1 6 7 package fr.emn.info.eaop.instrumentation; 8 9 import fr.emn.info.eaop.*; 10 import fr.emn.info.eaop.recoderaux.AuxListKit; 11 12 import recoder.*; 13 import recoder.abstraction.*; 14 import recoder.list.*; 15 import recoder.kit.*; 16 import recoder.java.*; 17 import recoder.java.declaration.*; 18 import recoder.java.reference.*; 19 20 21 31 public class WrapMethods extends Instrumentation { 32 33 public WrapMethods(CrossReferenceServiceConfiguration sc, 34 TypeDeclaration td) { 35 super(sc, null, td); 36 } 37 38 43 public ProblemReport execute() { 44 SelectiveInstrumentation instrument = IO.getInstrumentationContext(); 45 Method m; 46 47 if (instrument.checkClass(td)) { 48 MethodList ml = Main.getSourceInfo().getMethods(td); 49 50 for (int i = 0, s = ml.size(); i < s; i += 1) { 51 m = ml.getMethod(i); 52 if (!(m instanceof MethodDeclaration) || 53 (m instanceof Constructor)) continue; 54 MethodDeclaration md = (MethodDeclaration) m; 55 56 if (!instrument.checkMethodOrConstructor(md)) continue; 57 attach(buildDelegatee(md), td, td.getMembers().size()); 58 59 if (!td.replaceChild(md, buildDelegator(md))) { 60 IO.fail("[execute] Method replacement"); 61 }; 62 } 63 } 64 65 return Transformation.NO_PROBLEM; 66 } 67 68 74 MethodDeclaration buildDelegator(MethodDeclaration md) { 75 MethodDeclaration newMd = (MethodDeclaration) md.deepClone(); 76 77 Identifier id = new Identifier(md.getName() + origStr); 78 ExpressionMutableList el = MethodKit.createArguments(md); 79 80 StatementArrayList sl = 81 new StatementArrayList(new MethodReference(id, el)); 82 StatementBlock sb = new StatementBlock(sl); 83 84 if (!newMd.replaceChild(newMd.getBody(), sb)) { 85 IO.fail("[buildDelegator] Body replacement"); 86 }; 87 88 return newMd; 89 } 90 91 97 MethodDeclaration buildDelegatee(MethodDeclaration m) { 98 MethodDeclaration res = null; 99 100 Identifier id = 101 new Identifier(m.getIdentifier().getText() + origStr); 102 res = (MethodDeclaration) m.deepClone(); 103 res.setIdentifier(id); 104 105 return res; 106 } 107 } 108 109 | Popular Tags |