1 4 package com.tc.object.bytecode.aspectwerkz; 5 6 import org.apache.commons.lang.builder.ToStringBuilder; 7 8 import com.tc.asm.Type; 9 import com.tc.aspectwerkz.reflect.ClassInfo; 10 import com.tc.aspectwerkz.reflect.MethodInfo; 11 import com.tc.backport175.bytecode.AnnotationElement; 12 import com.tc.exception.ImplementMe; 13 14 import java.lang.reflect.Method ; 15 16 19 public class AsmMethodInfo implements MethodInfo { 20 private int modifiers; 21 private ClassInfo declaringType; 22 private String name; 23 private ClassInfo returnTypeInfo; 24 private ClassInfo[] parameterTypeInfos; 25 private ClassInfo[] exceptionTypeInfos; 26 private ClassInfoFactory classInfoFactory; 27 28 public AsmMethodInfo(ClassInfoFactory classInfoFactory, int modifiers, String className, String methodName, 29 String desc, String [] exceptions) { 30 this.classInfoFactory = classInfoFactory; 31 this.modifiers = modifiers; 33 this.declaringType = classInfoFactory.getClassInfo(className); this.name = methodName.equals("<init>") ? "__INIT__" : methodName; 37 this.returnTypeInfo = type2ClassInfo(Type.getReturnType(desc)); 39 Type[] parameterTypes = Type.getArgumentTypes(desc); 41 this.parameterTypeInfos = types2ClassInfos(parameterTypes); 42 this.exceptionTypeInfos = classNames2ClassInfos(exceptions); 44 } 45 46 public String toString() { 47 return ToStringBuilder.reflectionToString(this); 48 } 49 50 private ClassInfo[] classNames2ClassInfos(String [] classNames) { 51 if (classNames == null) return null; 52 ClassInfo[] rv = new ClassInfo[classNames.length]; 53 for (int i = 0; i < classNames.length; i++) { 54 rv[i] = className2ClassInfo(classNames[i]); 55 } 56 return rv; 57 } 58 59 private ClassInfo[] types2ClassInfos(Type[] types) { 60 if (types == null) return null; 61 ClassInfo[] rv = new ClassInfo[types.length]; 62 for (int i = 0; i < types.length; i++) { 63 rv[i] = type2ClassInfo(types[i]); 64 } 65 return rv; 66 } 67 68 private ClassInfo className2ClassInfo(String className) { 69 return classInfoFactory.getClassInfo(className); } 71 72 private ClassInfo type2ClassInfo(Type type) { 73 return className2ClassInfo(type.getClassName()); 74 } 75 76 public ClassInfo getReturnType() { 77 return this.returnTypeInfo; 78 } 79 80 public ClassInfo[] getParameterTypes() { 81 return this.parameterTypeInfos; 82 } 83 84 public String [] getParameterNames() { 85 return new String [0]; } 87 88 public ClassInfo[] getExceptionTypes() { 89 return this.exceptionTypeInfos; 90 } 91 92 public ClassInfo getDeclaringType() { 93 return this.declaringType; 94 } 95 96 public String getName() { 97 return this.name; 98 } 99 100 public String getSignature() { 101 return null; 102 } 103 104 public String getGenericsSignature() { 105 return null; 106 } 107 108 public int getModifiers() { 109 return modifiers; 110 } 111 112 public AnnotationElement.Annotation[] getAnnotations() { 113 throw new ImplementMe(); 114 } 115 116 119 public static AsmMethodInfo createNewAsmMethodInfo(Method method) { 120 int modifiers = method.getModifiers(); 121 String className = method.getDeclaringClass().getName(); 122 String methodName = method.getName(); 123 String desc = Type.getMethodDescriptor(method); 124 Class [] exceptionTypes = method.getExceptionTypes(); 125 String [] exceptionTypeNames = new String [exceptionTypes.length]; 126 for (int i = 0; i < exceptionTypes.length; i++) { 127 exceptionTypeNames[i] = exceptionTypes[i].getName(); 128 } 129 return new AsmMethodInfo(new ClassInfoFactory(), modifiers, className, methodName, desc, exceptionTypeNames); 130 } 131 132 } | Popular Tags |