1 6 7 package fr.emn.info.eaop.instrumentation; 8 9 import fr.emn.info.eaop.IO; 10 11 import recoder.*; 12 import recoder.abstraction.*; 13 import recoder.kit.*; 14 import recoder.list.*; 15 import recoder.java.*; 16 import recoder.java.declaration.*; 17 18 19 25 public class HandleTermination extends Instrumentation { 26 27 public HandleTermination(CrossReferenceServiceConfiguration sc, 28 CompilationUnit cu) { 29 super(sc, cu, null); 30 } 31 32 34 42 public ProblemReport execute() { 43 for (int i=0; i<cu.getTypeDeclarationCount(); i++) { 44 TypeDeclaration td = cu.getTypeDeclarationAt(i); 45 MethodList ml = td.getMethods(); 46 for (int j=0; j<ml.size(); j++) { 47 Method m = ml.getMethod(j); 48 if (m.getName().equals("main")) { 49 if (!(m instanceof MethodDeclaration)) 50 IO.fail("[execute] No valid main method"); 51 MethodDeclaration md = (MethodDeclaration) m; 52 StatementBlock sb = md.getBody(); 53 StatementMutableList sl = sb.getBody(); 54 try { 55 sl.add(pf.parseStatements("System.exit(0);")); 56 } catch (ParserException e) { 57 IO.fail("[execute] Parsing for termination handling"); 58 } 59 if (!md.replaceChild(sb, new StatementBlock(sl))) 60 IO.fail("[execute] Termination handling for main"); 61 } 62 } 63 } 64 65 return Transformation.NO_PROBLEM; 66 } 67 } 68 69 | Popular Tags |