34 /**
35 * This is a utility class for parsing the log entries for a method. It supplies
36 * a few select methods for reflecting the class and method from that information.
37 *
38 * Example log entries:
39 * "java.util.TreeMap.successor(Ljava/util/TreeMap$Entry;)Ljava/util/TreeMap$Entry;"
40 */
41
42 public MethodIdentifierParser(String logString) {
43 this.logString = logString;
44
45 int i = logString.lastIndexOf("."); // find start of method name
46 className = logString.substring(0, i); // classname is everything before
47 int i2 = logString.indexOf("("); // Signature starts with an '('
48 methodName = logString.substring(i+1, i2);
49 methodDescriptor = logString.substring(i2, logString.length());
50
51 // Add sanity check for extracted fields
52 }
53
54 public Method getMethod() throws NoSuchMethodException, SecurityException, ClassNotFoundException, Exception {
55 try {
56 return Class.forName(className).getDeclaredMethod(methodName, getParamenterDescriptorArray());
57 } catch (UnexpectedTokenException e) {
58 throw new Exception("Parse failed");
59 }
60 }
61
62 public Class<?>[] getParamenterDescriptorArray() throws ClassNotFoundException, UnexpectedTokenException {
63 ParameterDecriptorIterator s = new ParameterDecriptorIterator(methodDescriptor);
64 Class<?> paramType;
65 ArrayList<Class<?>> list = new ArrayList<Class<?>>();
66 while ((paramType = s.nextParamType()) != null) {
67 list.add(paramType);
68 }
69 if (list.size() > 0) {
70 return list.toArray(new Class<?>[list.size()]);
71 } else {
72 return null;
73 }
74 }
75
76 class ParameterDecriptorIterator {
77
78 // This class uses charAt() indexing for startMark and i
|
34 /**
35 * This is a utility class for parsing the log entries for a method. It supplies
36 * a few select methods for reflecting the class and method from that information.
37 *
38 * Example log entries:
39 * "java.util.TreeMap.successor(Ljava/util/TreeMap$Entry;)Ljava/util/TreeMap$Entry;"
40 */
41
42 public MethodIdentifierParser(String logString) {
43 this.logString = logString;
44
45 int i = logString.lastIndexOf("."); // find start of method name
46 className = logString.substring(0, i); // classname is everything before
47 int i2 = logString.indexOf("("); // Signature starts with an '('
48 methodName = logString.substring(i+1, i2);
49 methodDescriptor = logString.substring(i2, logString.length());
50
51 // Add sanity check for extracted fields
52 }
53
54 public Method getMethod() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
55 try {
56 return Class.forName(className).getDeclaredMethod(methodName, getParamenterDescriptorArray());
57 } catch (UnexpectedTokenException e) {
58 throw new RuntimeException("Parse failed");
59 }
60 }
61
62 public Class<?>[] getParamenterDescriptorArray() throws ClassNotFoundException, UnexpectedTokenException {
63 ParameterDecriptorIterator s = new ParameterDecriptorIterator(methodDescriptor);
64 Class<?> paramType;
65 ArrayList<Class<?>> list = new ArrayList<Class<?>>();
66 while ((paramType = s.nextParamType()) != null) {
67 list.add(paramType);
68 }
69 if (list.size() > 0) {
70 return list.toArray(new Class<?>[list.size()]);
71 } else {
72 return null;
73 }
74 }
75
76 class ParameterDecriptorIterator {
77
78 // This class uses charAt() indexing for startMark and i
|