1 22 23 package org.aspectj.debugger.request; 24 25 import org.aspectj.debugger.base.*; 26 import org.aspectj.tools.ide.*; 27 28 import com.sun.jdi.*; 29 import com.sun.jdi.request.*; 30 import java.util.*; 31 32 40 41 public abstract class ClassMethodBreakpointRequestAction extends ClassBreakpointRequestAction { 42 43 private String methodProto; 44 45 ClassMethodBreakpointRequestAction(Debugger debugger, 46 String className, 47 String methodProto) { 48 super(debugger, className); 49 this.methodProto = methodProto; 50 } 51 52 public String getMethodProto() { 53 return methodProto; 54 } 55 56 public String getErrorMessage() { 57 return "No method " + getMethodName() + " in " + getClassName(); 58 } 59 60 public String getProto() { 61 return getClassName() + "." + getMethodProto(); 62 } 63 64 65 66 public boolean equals(Object o) { 67 if (!(o instanceof ClassMethodBreakpointRequestAction)) { 68 return super.equals(o); 69 } 70 ClassMethodBreakpointRequestAction ra = (ClassMethodBreakpointRequestAction)o; 71 return (ra.getClassName().equals(getClassName()) && 72 ra.getMethodName().equals(getMethodName()) && 73 ra.argumentTypeNames().equals(argumentTypeNames())); 74 } 75 76 Location findLocation() 77 throws NoVMException, 78 MultipleLocationsException, 79 UnableToSetRequestException { 80 Location location = null; 81 Iterator iter = vm().classesByName(className).iterator(); 82 while (iter.hasNext()) { 83 ReferenceType refType = (ReferenceType) iter.next(); 84 if (refType.name().equals(className)) { 85 List methods = refType.methodsByName(getMethodName()); 86 Iterator methodsIter = methods.iterator(); 87 List argumentTypeNames = argumentTypeNames(); 88 boolean justName = true; 89 for (int i = 0; i < methodProto.length(); i++) { 90 if (!Character.isJavaIdentifierPart(methodProto.charAt(i))) { 91 justName = false; 92 break; 93 } 94 } 95 if (justName) { 96 if (methods.size() == 1) { 97 location = ((Method) methods.get(0)).location(); 98 return location; 99 } else if (methods.size() == 0) { 100 throw new UnableToSetRequestException(this); 101 } else { 102 throw new MultipleLocationsException(className + "." + methodProto, methods); 103 } 104 } 105 while (methodsIter.hasNext()) { 106 Method method = (Method) methodsIter.next(); 107 if (argumentTypeNames().equals(method.argumentTypeNames())) { 108 location = method.location(); 109 return location; 110 } 111 } 112 throw new UnableToSetRequestException(this); 113 } 114 } 115 return location; 116 } 117 118 String getMethodName() { 119 int iparen = methodProto.indexOf("("); 120 if (iparen != -1) { 121 return methodProto.substring(0, iparen); 122 } 123 return methodProto; 124 } 125 126 public List getArgumentTypeNames() { 127 return argumentTypeNames(); 128 } 129 130 List argumentTypeNames() { 131 List argNames = new ArrayList(); 132 int iparen = methodProto.indexOf("("); 133 if (iparen == -1) { 134 return argNames; 135 } 136 StringTokenizer tok = new StringTokenizer(methodProto, "(,;:)"); 137 try { 138 String meth = tok.nextToken(); 139 while (tok.hasMoreTokens()) { 140 String token = tok.nextToken(); 141 argNames.add(token); 142 } 143 } catch (NoSuchElementException e) { 144 } 145 return argNames; 146 } 147 148 public int getLine() { 150 SourceLine sl = sourceLine(); 151 if (sl == null || sl.line < 0) { 152 return super.getLine(); 153 } 154 return sl.line; 155 } 156 157 public String getSourceName() { 159 SourceLine sl = sourceLine(); 160 if (sl == null) { 161 return super.getSourceName(); 162 } 163 return sl.filename; 164 } 165 166 167 public SourceLine sourceLine() { 168 String fullSrcPath = ajdbg().getFullSourcePathFromAJCClass(className); 169 Location loc = getLocation(); 170 if (loc == null) { 171 return ajdbg().sourceLineOfMethodThatShouldMap(getClassName(), 172 getMethodName(), 173 fullSrcPath); 174 } else { 175 return ajdbg().sourceLineOfMethodThatShouldMap(loc, fullSrcPath); 176 } 177 } 178 } 179 | Popular Tags |