1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 27 import com.sun.jdi.*; 28 import java.util.*; 29 import org.aspectj.tools.ide.*; 30 31 public class AJTranslator { 32 33 final static String AJC = "$ajc"; 34 final static String BEFORE_AJC = "before" + AJC; 35 final static String AFTER_AJC = "after" + AJC; 36 final static String AROUND_AJC = "around" + AJC; 37 38 final static String EXECUTION = "$execution"; 39 final static String RECEPTION = "$reception"; 40 final static String CALL = "$call"; 41 final static String ASPECT_OF = "aspectOf"; 42 final static String HAS_ASPECT = "hasAspect"; 43 44 final static String AROUND = "$around"; 45 final static String AROUND_EXECUTION = AROUND + EXECUTION; 46 final static String AROUND_RECEPTION = AROUND + RECEPTION; 47 final static String AROUND_CALL = AROUND + CALL; 48 49 final static String [] SPECIAL_STRINGS = { 50 EXECUTION, 51 RECEPTION, 52 CALL, 53 ASPECT_OF, 54 HAS_ASPECT, 55 }; 56 57 final static String [] ADVICE_STRINGS = { 58 BEFORE_AJC, 59 AFTER_AJC, 60 AROUND_AJC 61 }; 62 63 67 public static String getMappingMethodName(String method) { 68 String clazz = AJUtil.getTypeFromMethod(method); 69 70 String file = AJLineMapper.getSourceFilePathFromAJCClass(clazz); 72 if (file == null) { 73 return method; 74 } 75 76 int line = AJDecParser.getMethodLineNumber(file, method); 78 if (line == -1) { 79 return method; 80 } 81 82 Declaration dec = AJLineMapper.symbolManager.getDeclarationAtLine(file, line); 84 if (dec == null || 85 dec.getPointedToBy() == null || 86 dec.getPointedToBy().length == 0) { 87 return method; 88 } 89 90 String baseName = AJUtil.stripParens(method); 94 ReferenceType refType = null; 96 try { 97 refType = ComponentRepository.getAJDebugger().getReferenceTypeFromToken(clazz); 98 } catch (DebuggerException de) { 99 } 100 if (refType == null) { 101 return method; 102 } 103 Iterator iter = refType.methods().iterator(); 104 String uScoreClass = clazz.replace('.', '_'); 105 String comp = AJUtil.stripTypeFromMethod(baseName) + "$" + uScoreClass; 106 while (iter.hasNext()) { 107 Method meth = (Method) iter.next(); 108 if (!meth.name().startsWith(comp) || isNonMappingMethod(meth)) { 109 continue; 110 } 111 return meth + ""; 112 } 113 return method; 114 } 115 116 public static String translateFullWorkingDirMethodName(String meth) { 117 String type = AJUtil.getTypeFromMethod(meth); 118 String name = translateWorkingDirMethodName( 119 AJUtil.getNameFromMethod(meth)); 120 String params = AJUtil.getParamsFromMethod(meth); 121 return type + "." + name + "(" + params + ")"; 122 } 123 124 127 public static boolean isNonMappingMethod(Method method) { 128 Location loc = method.location(); 129 if (loc == null) { 130 return false; 131 } 132 int line = AJLineMapper.getCorrespondingLine(loc).line; 133 if (line == AJLineMapper.NON_MAPPING_SOURCE_LINE) { 134 return true; 135 } 136 return false; 137 } 138 139 public static boolean isNonMappingMethod(String clazz, int oldLine) { 140 String ajFile = AJLineMapper.getSourceFilePathFromAJCClass(clazz); 141 if (ajFile == null) { 142 return false; 143 } 144 int line = AJLineMapper.getCorrespondingLine(clazz, oldLine).line; 145 if (line == AJLineMapper.NON_MAPPING_SOURCE_LINE) { 146 return true; 147 } 148 return false; 149 } 150 151 public static String getBaseName(String method) { 152 int end = method.indexOf("("); 153 if (end == -1) { 154 end = method.length(); 155 } 156 int i = end - 1; 157 int idollar = -1; 158 while (i >= 0) { 159 char c = method.charAt(i); 160 if (c == '.') { 161 break; 162 } else if (c == '$') { 163 idollar = i; 164 } 165 i--; 166 } 167 return (idollar != -1) ? method.substring(0, idollar) : method; 168 } 169 170 public static String getBaseNameWithParams(String method) { 171 int ip = method.indexOf("("); 172 String params = ""; 173 String nameAndMaybeType = method; 174 if (ip != -1) { 175 params = method.substring(ip); 176 nameAndMaybeType = method.substring(0, ip); 177 } 178 return getBaseName(nameAndMaybeType) + params; 179 } 180 181 public static String translateWorkingDirMethodName_(String methodName) { 182 int firstDollar = methodName.indexOf('$'); 183 184 if (firstDollar == -1) return methodName; 185 186 String baseName = methodName.substring(0, firstDollar); 187 188 int iajc; 189 int iaroundExecution; 190 int iaroundReception; 191 int iaroundCall; 192 int iexecution; 193 int ireception; 194 int icall; 195 196 if ((iajc = methodName.indexOf(AJC)) != -1) { 197 String numStr = methodName.substring(iajc + AJC.length()); 198 return baseName + "<" + "advice-#" + numStr + ">"; 199 } else if ((iaroundExecution = methodName.indexOf(AROUND_EXECUTION)) != -1) { 200 return baseName + "<" + "around-execution>"; 201 } else if ((iaroundReception = methodName.indexOf(AROUND_RECEPTION)) != -1) { 202 return baseName + "<" + "around-reception>"; 203 } else if ((iaroundCall = methodName.indexOf(AROUND_CALL)) != -1) { 204 String numStr = methodName.substring(iaroundCall + AROUND_CALL.length()); 205 return baseName + "<" + "around-call-#" + numStr + ">"; 206 } else if ((iexecution = methodName.indexOf(EXECUTION)) != -1) { 207 return baseName + "<" + "execution>"; 208 } else if ((ireception = methodName.indexOf(RECEPTION)) != -1) { 209 return baseName + "<" + "reception>"; 210 } else if ((icall = methodName.indexOf(CALL))!= -1) { 211 String numStr = methodName.substring(icall + CALL.length()); 212 return baseName + "<" + "call-#" + numStr + ">"; 213 } 214 return methodName; 216 } 217 218 public static String translateWorkingDirMethod(String clazz, String methodName) { 219 if (isAdvice(methodName)) { 220 return translateWorkingDirMethodName(methodName); 221 } 222 return getMappingMethodName(clazz + "." + methodName); 223 } 224 225 public static String translateWorkingDirMethodName(String methodName) { 226 int firstDollar = methodName.indexOf('$'); 227 if (firstDollar == -1) { 228 return methodName; 229 } 230 231 String baseName = methodName.substring(0, firstDollar); 232 String noDollars = methodName.substring(firstDollar + 1).replace('$', '-'); 233 return baseName + "<" + noDollars + ">"; 234 } 235 236 public static boolean isAdvice(String methodName) { 237 if (methodName.indexOf(AJC) != -1) { 238 return true; 239 } 240 return false; 241 } 242 243 public static boolean isReception(String methodName) { 244 if (methodName.indexOf(RECEPTION) != -1) { 245 return true; 246 } 247 return false; 248 } 249 250 public static boolean isSpecialMethod(String methodName) { 251 for (int i = 0; i < SPECIAL_STRINGS.length; i++) { 252 if (methodName.indexOf(SPECIAL_STRINGS[i]) != -1) { 253 return true; 254 } 255 } 256 return false; 257 } 258 259 public static String translateSourceMethodNameWithParams(String methodName) { 260 String params = AJUtil.getParamsFromMethod(methodName); 261 String rest = AJUtil.stripParens(methodName); 262 String result = translateSourceMethodName(rest); 263 return result + "(" + params + ")"; 265 268 } 269 270 273 public static String translateSourceMethodName(String methodName) { 274 275 int firstLT = methodName.indexOf("<"); 277 if (firstLT < 1) { 278 return methodName; 279 } 280 281 String baseName = methodName.substring(0, firstLT); 282 String dollars = methodName.substring(firstLT + 1, methodName.length() - 1).replace('-', '$'); 283 return baseName + "$" + dollars; 284 } 285 286 public static String translateSourceMethodName_(String methodName) { 287 if (methodName.equals("<init>") || 288 methodName.equals("<clinit>")) { 289 return methodName; 290 } else if (methodName.startsWith("<") && methodName.endsWith(">")) { 291 int iAdvice = methodName.indexOf("-advice-#"); 295 if (iAdvice == -1) { 296 return methodName; 297 } 298 String adviceType = methodName.substring(1, iAdvice); 299 int iNum = iAdvice + 9; 300 String numStr = methodName.substring(iNum, methodName.length()-1); 301 return adviceType + "$ajc" + numStr; 302 303 } else { 304 308 } 309 return methodName; 310 } 311 312 public static String translateWorkingDirMethodNameWithParams(String methodName) { 313 String params = AJUtil.getParamsFromMethod(methodName); 314 String rest = AJUtil.stripParens(methodName); 315 String result = translateWorkingDirMethodName(rest); 316 return result + "(" + params + ")"; 318 } 321 322 327 public static String getTranslatedMethodName(String classID, String meth) { 328 return ""; 329 } 361 } 362 | Popular Tags |