1 4 package com.tc.aspectwerkz.reflect.impl.asm; 5 6 import com.tc.backport175.bytecode.AnnotationElement; 7 import com.tc.asm.Type; 8 9 import com.tc.aspectwerkz.transform.inlining.AsmHelper; 10 import com.tc.aspectwerkz.reflect.ClassInfo; 11 import com.tc.aspectwerkz.reflect.ConstructorInfo; 12 13 18 public class AsmConstructorInfo extends AsmMemberInfo implements ConstructorInfo { 19 20 23 private String [] m_parameterTypeNames = null; 24 25 28 private String [] m_exceptionTypeNames = null; 29 30 33 private ClassInfo[] m_parameterTypes = null; 34 35 38 private ClassInfo[] m_exceptionTypes = null; 39 40 47 AsmConstructorInfo(final MethodStruct method, final String declaringType, final ClassLoader loader) { 48 super(method, declaringType, loader); 49 Type[] argTypes = Type.getArgumentTypes(method.desc); 50 m_parameterTypeNames = new String [argTypes.length]; 51 for (int i = 0; i < argTypes.length; i++) { 52 m_parameterTypeNames[i] = argTypes[i].getClassName(); 53 } 54 m_exceptionTypeNames = new String []{}; 56 } 57 58 66 public static ConstructorInfo getConstructorInfo(final String constructorDesc, 67 final byte[] bytecode, 68 final ClassLoader loader) { 69 String className = AsmClassInfo.retrieveClassNameFromBytecode(bytecode); 70 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 71 ClassInfo classInfo = repository.getClassInfo(className); 72 if (classInfo == null) { 73 classInfo = AsmClassInfo.getClassInfo(bytecode, loader); 74 } 75 return classInfo.getConstructor(AsmHelper.calculateConstructorHash(constructorDesc)); 76 } 77 78 83 public String getSignature() { 84 return AsmHelper.getConstructorDescriptor(this); 85 } 86 87 public String getGenericsSignature() { 88 return m_member.signature; 89 } 90 91 96 public synchronized ClassInfo[] getParameterTypes() { 97 if (m_parameterTypes == null) { 98 m_parameterTypes = new ClassInfo[m_parameterTypeNames.length]; 99 for (int i = 0; i < m_parameterTypeNames.length; i++) { 100 m_parameterTypes[i] = AsmClassInfo.getClassInfo( 101 m_parameterTypeNames[i], 102 (ClassLoader ) m_loaderRef.get() 103 ); 104 } 105 } 106 return m_parameterTypes; 107 } 108 109 114 public synchronized ClassInfo[] getExceptionTypes() { 115 if (m_exceptionTypes == null) { 116 m_exceptionTypes = new ClassInfo[m_exceptionTypeNames.length]; 117 for (int i = 0; i < m_exceptionTypeNames.length; i++) { 118 m_exceptionTypes[i] = AsmClassInfo.getClassInfo( 119 m_exceptionTypeNames[i], 120 (ClassLoader ) m_loaderRef.get() 121 ); 122 } 123 } 124 return m_exceptionTypes; 125 } 126 127 132 public AnnotationElement.Annotation[] getAnnotations() { 133 return getDeclaringType().getAnnotationReader().getConstructorAnnotationElements(m_member.desc); 134 } 135 136 public boolean equals(Object o) { 137 if (this == o) { 138 return true; 139 } 140 if (!(o instanceof ConstructorInfo)) { 141 return false; 142 } 143 ConstructorInfo constructorInfo = (ConstructorInfo) o; 144 if (!m_declaringTypeName.equals(constructorInfo.getDeclaringType().getName())) { 145 return false; 146 } 147 if (!m_member.name.equals(constructorInfo.getName())) { 148 return false; 149 } 150 ClassInfo[] parameterTypes = constructorInfo.getParameterTypes(); 151 if (m_parameterTypeNames.length != parameterTypes.length) { return false; 153 } 154 for (int i = 0; i < m_parameterTypeNames.length; i++) { 155 if (!m_parameterTypeNames[i].equals(parameterTypes[i].getName())) { 156 return false; 157 } 158 } 159 return true; 160 } 161 162 public int hashCode() { 163 int result = 29; 164 result = (29 * result) + m_declaringTypeName.hashCode(); 165 result = (29 * result) + m_member.name.hashCode(); 166 for (int i = 0; i < m_parameterTypeNames.length; i++) { 167 result = (29 * result) + m_parameterTypeNames[i].hashCode(); 168 } 169 return result; 170 } 171 172 public String toString() { 173 StringBuffer sb = new StringBuffer (m_declaringTypeName); 174 sb.append('.').append(m_member.name); 175 sb.append(m_member.desc); 176 return sb.toString(); 177 } 178 } 179 | Popular Tags |