1 6 7 package fr.emn.info.eaop.instrumentation; 8 9 import fr.emn.info.eaop.*; 10 11 import recoder.abstraction.*; 12 import recoder.java.*; 13 import recoder.java.declaration.*; 14 import recoder.list.*; 15 16 41 public class SelectiveInstrumentation { 42 protected TypeDeclaration td = null; 43 protected MethodDeclaration md = null; 44 public String [] files; 45 46 50 public SelectiveInstrumentation() {} 51 52 55 protected boolean checkClass(TypeDeclaration td) { 56 this.td = td; 57 58 return true; 59 } 60 61 64 protected boolean checkMethodOrConstructor(MethodDeclaration md) { 65 this.md = md; 66 67 return true; 68 } 69 70 73 protected boolean checkAspect(TypeDeclaration td) { 74 this.td = td; 75 76 return matchClassName("Billing"); 77 } 78 79 80 84 protected boolean matchClassName(String regexp) { 85 return td.getName().matches(regexp); 86 } 87 88 protected boolean matchFieldNames(String regexp) { 89 FieldList fs = td.getFields(); 90 String fsStr = ""; 91 String fStr; 92 93 for (int i=0; i<fs.size(); i++) { 94 if (fsStr != "") fsStr += ","; 95 fsStr += fs.getField(i).getName(); 96 } 97 98 return fsStr.matches(regexp); 99 } 100 101 protected boolean matchMethodNames(String regexp) { 102 MethodList ms = td.getMethods(); 103 String msStr = ""; 104 String mStr; 105 106 for (int i=0; i<ms.size(); i++) { 107 if (msStr != "") msStr += ","; 108 msStr += ms.getMethod(i).getName(); 109 } 110 111 return msStr.matches(regexp); 112 } 113 114 protected boolean matchSupertypeNames(String regexp) { 115 ClassTypeList ss = td.getAllSupertypes(); 116 String ssStr = ""; 117 String sStr; 118 119 if (ss == null) return false; 120 121 for (int i=0; i<ss.size(); i++) { 122 if (ssStr != "") ssStr += ","; 123 ssStr += ss.getClassType(i).getName(); 124 } 125 126 return ssStr.matches(regexp); 127 } 128 129 protected boolean matchSupertypeNames(ClassTypeList cts, String regexp) { 130 ClassTypeList ss = cts; 131 String ssStr = ""; 132 String sStr; 133 134 if (ss == null) return false; 135 136 for (int i=0; i<ss.size(); i++) { 137 if (ssStr != "") ssStr += ","; 138 ssStr += ss.getClassType(i).getName(); 139 } 140 141 return ssStr.matches(regexp); 142 } 143 144 protected boolean matchPackage(String regexp) { 145 return td.getPackage().getName().matches(regexp); 146 } 147 148 149 153 protected boolean isAspectInstance() { 154 return matchSupertypeNames(".*,Aspect,.*"); 155 } 156 157 158 162 protected boolean matchMethodClassName(String regexp) { 163 return 164 Main.getSourceInfo() 165 .getContainingClassType((ProgramElement) md).getName() 166 .matches(regexp); 167 } 168 169 protected boolean matchMethodName(String regexp) { 170 return md.getName().matches(regexp); 171 } 172 173 protected boolean matchMethodPackage(String regexp) { 174 return md.getPackage().getName().matches(regexp); 175 } 176 177 protected boolean matchParameterTypes(String regexp) { 178 ParameterDeclarationMutableList ps = md.getParameters(); 179 String psStr = ""; 180 String tStr; 181 182 if (ps.size() == 0) psStr = "void"; 183 else 184 for (int i=0; i<ps.size(); i++) { 185 if (psStr != "") psStr += ","; 186 tStr = ps.getParameterDeclaration(i) 187 .getVariableSpecification().getType().getName(); 188 if (tStr == "") psStr += "void"; 189 else psStr += tStr; 190 } 191 192 return psStr.matches(regexp); 193 } 194 195 protected boolean matchReturnType(String regexp) { 196 Type t = md.getReturnType(); 197 if (t == null) return "".matches(regexp) || "void".matches(regexp); 198 return t.getName().matches(regexp); 199 } 200 201 protected boolean isSystemMethodOrConstructor() { 202 return matchParameterTypes( 203 ".*" + Instrumentation.constructorDummyTypeStr + ".*") 204 || matchMethodName("definition") 205 || matchMethodName("next.*"); 206 } 207 208 212 public String [] getFiles() { 213 return files; 214 } 215 } 216 217 | Popular Tags |