1 4 package com.tc.aspectwerkz.reflect.impl.java; 5 6 import com.tc.aspectwerkz.reflect.ClassInfo; 7 import com.tc.aspectwerkz.reflect.ConstructorInfo; 8 import com.tc.aspectwerkz.reflect.ReflectHelper; 9 import com.tc.backport175.bytecode.AnnotationElement; 10 11 import java.lang.reflect.Constructor ; 12 13 18 public class JavaConstructorInfo extends JavaMemberInfo implements ConstructorInfo { 19 22 private ClassInfo[] m_parameterTypes = null; 23 24 27 private ClassInfo[] m_exceptionTypes = null; 28 29 32 private String m_signature; 33 34 40 JavaConstructorInfo(final Constructor constructor, final JavaClassInfo declaringType) { 41 super(constructor, declaringType); 42 m_signature = ReflectHelper.getConstructorSignature(constructor); 43 } 44 45 51 public static ConstructorInfo getConstructorInfo(final Constructor constructor) { 52 Class declaringClass = constructor.getDeclaringClass(); 53 JavaClassInfoRepository repository = JavaClassInfoRepository.getRepository(declaringClass.getClassLoader()); 54 ClassInfo classInfo = repository.getClassInfo(declaringClass.getName()); 55 if (classInfo == null) { 56 classInfo = JavaClassInfo.getClassInfo(declaringClass); 57 } 58 return classInfo.getConstructor(ReflectHelper.calculateHash(constructor)); 59 } 60 61 66 public String getSignature() { 67 return m_signature; 68 } 69 70 public String getGenericsSignature() { 71 throw new RuntimeException (); 73 } 74 75 80 public AnnotationElement.Annotation[] getAnnotations() { 81 return getDeclaringType().getAnnotationReader().getConstructorAnnotationElements(m_signature); 82 } 83 84 89 public ClassInfo[] getParameterTypes() { 90 if (m_parameterTypes == null) { 91 Class [] parameterTypes = ((Constructor ) m_member).getParameterTypes(); 92 m_parameterTypes = new ClassInfo[parameterTypes.length]; 93 for (int i = 0; i < parameterTypes.length; i++) { 94 Class parameterType = parameterTypes[i]; 95 ClassInfo metaData; 96 if (m_classInfoRepository.hasClassInfo(parameterType.getName())) { 97 metaData = m_classInfoRepository.getClassInfo(parameterType.getName()); 98 } else { 99 metaData = JavaClassInfo.getClassInfo(parameterType); 100 m_classInfoRepository.addClassInfo(metaData); 101 } 102 m_parameterTypes[i] = metaData; 103 } 104 } 105 return m_parameterTypes; 106 } 107 108 113 public ClassInfo[] getExceptionTypes() { 114 if (m_exceptionTypes == null) { 115 Class [] exceptionTypes = ((Constructor ) m_member).getExceptionTypes(); 116 m_exceptionTypes = new ClassInfo[exceptionTypes.length]; 117 for (int i = 0; i < exceptionTypes.length; i++) { 118 Class exceptionType = exceptionTypes[i]; 119 ClassInfo metaData; 120 if (m_classInfoRepository.hasClassInfo(exceptionType.getName())) { 121 metaData = m_classInfoRepository.getClassInfo(exceptionType.getName()); 122 } else { 123 metaData = JavaClassInfo.getClassInfo(exceptionType); 124 m_classInfoRepository.addClassInfo(metaData); 125 } 126 m_exceptionTypes[i] = metaData; 127 } 128 } 129 return m_exceptionTypes; 130 } 131 132 public boolean equals(Object o) { 133 if (this == o) { 134 return true; 135 } 136 if (!(o instanceof ConstructorInfo)) { 137 return false; 138 } 139 ConstructorInfo constructorInfo = (ConstructorInfo) o; 140 if (!m_declaringType.getName().equals(constructorInfo.getDeclaringType().getName())) { 141 return false; 142 } 143 if (!m_member.getName().equals(constructorInfo.getName())) { 144 return false; 145 } 146 Class [] parameterTypes1 = ((Constructor ) m_member).getParameterTypes(); 147 ClassInfo[] parameterTypes2 = constructorInfo.getParameterTypes(); 148 if (parameterTypes1.length != parameterTypes2.length) { 149 return false; 150 } 151 for (int i = 0; i < parameterTypes1.length; i++) { 152 if (!parameterTypes1[i].getName().equals(parameterTypes2[i].getName())) { 153 return false; 154 } 155 } 156 return true; 157 } 158 159 public int hashCode() { 160 int result = 29; 161 result = (29 * result) + m_declaringType.getName().hashCode(); 162 result = (29 * result) + m_member.getName().hashCode(); 163 Class [] parameterTypes = ((Constructor ) m_member).getParameterTypes(); 164 for (int i = 0; i < parameterTypes.length; i++) { 165 result = (29 * result) + parameterTypes[i].getName().hashCode(); 166 } 167 return result; 168 } 169 } | Popular Tags |