1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 27 import java.io.File ; 28 import java.util.StringTokenizer ; 29 import org.aspectj.tools.ide.Declaration; 30 31 public class AJDecParser { 32 33 public final static int BAD = -1; 34 35 public static int getMethodLineNumber(String fileName, 36 String methodName) { 37 if (fileName == null) { 38 return BAD; 39 } 40 Util.debug("Looking for methodName=" + methodName + " in " + fileName); 41 String fullName = new File (fileName).getAbsolutePath(); 42 Declaration[] decs = 43 AJLineMapper.symbolManager. 44 getDeclarations(fullName); 45 if (decs == null) { 46 return BAD; 47 } 48 MethodComparator c = new MethodComparator(); 49 for (int i = 0; i < decs.length; i++) { 50 int result = getBeginLine(decs[i], methodName, c); 51 if (result != BAD) { 52 return result; 53 } 54 } 55 return BAD; 56 } 57 58 public static int getBeginLine(Declaration dec, 59 String s, 60 DeclarationComparator c) { 61 if (c.compare(dec, s)) { 62 return dec.getBeginLine(); 63 } 64 Declaration[] decs = dec.getDeclarations(); 65 int result = BAD; 66 for (int i = 0; i < decs.length; i++) { 67 if ((result = getBeginLine(decs[i], s, c)) != BAD) { 68 return result; 69 } 70 } 71 return BAD; 72 } 73 } 74 75 interface DeclarationComparator { 76 boolean compare(Declaration d, String s); 77 } 78 79 class MethodComparator implements DeclarationComparator { 80 public boolean compare(Declaration d1, String s) { 81 String method1 = getMethodPrototype(d1); 82 String method2 = s; 83 return (!method1.equals("") && 84 !method2.equals("") && 85 method1.equals(method2)); 86 } 87 88 public static String getMethodPrototype(Declaration dec) { 89 if (dec == null ||!(dec.getKind().equals("method") || 90 dec.getKind().equals("constructor"))) { 91 return ""; 92 } 93 String fullSig = dec.getFullSignature(); 94 String sig = dec.getSignature(); 95 String methodName = sig.substring(0, sig.indexOf("(")); 96 if (methodName.equals("new")) { 97 methodName = dec.getDeclaringType(); 98 } 99 String name = dec.getDeclaringType() + "." + methodName; 100 String args = fullSig.substring(fullSig.indexOf("(")+1, 101 fullSig.indexOf(")")); 102 String str = name + "("; 103 StringTokenizer tok = new StringTokenizer (args, ","); 104 if (!tok.hasMoreTokens()) { 105 str += ")"; 106 } 107 while (tok.hasMoreTokens()) { 108 String arg = tok.nextToken().trim(); 109 String type = arg.substring(0, arg.indexOf(" ")); 110 str += arg.substring(0, arg.indexOf(" ")) + 111 (tok.hasMoreTokens() ? "," : ")"); 112 } 113 return str; 114 } 115 } 116 | Popular Tags |