1 4 package com.tc.aspectwerkz.reflect.impl.java; 5 6 import com.tc.aspectwerkz.reflect.ClassInfo; 7 import com.tc.aspectwerkz.reflect.MethodInfo; 8 import com.tc.aspectwerkz.reflect.ReflectHelper; 9 import com.tc.backport175.bytecode.AnnotationElement; 10 11 import java.lang.reflect.Method ; 12 13 18 public class JavaMethodInfo extends JavaMemberInfo implements MethodInfo { 19 20 23 private ClassInfo m_returnType = null; 24 25 28 private ClassInfo[] m_parameterTypes = null; 29 30 33 private ClassInfo[] m_exceptionTypes = null; 34 35 38 private String m_signature; 39 40 46 JavaMethodInfo(final Method method, final JavaClassInfo declaringType) { 47 super(method, declaringType); 48 m_signature = ReflectHelper.getMethodSignature(method); 49 } 50 51 57 public static MethodInfo getMethodInfo(final Method method) { 58 Class declaringClass = method.getDeclaringClass(); 59 JavaClassInfoRepository repository = JavaClassInfoRepository.getRepository(declaringClass.getClassLoader()); 60 ClassInfo classInfo = repository.getClassInfo(declaringClass.getName()); 61 if (classInfo == null) { 62 classInfo = JavaClassInfo.getClassInfo(declaringClass); 63 } 64 return classInfo.getMethod(ReflectHelper.calculateHash(method)); 65 } 66 67 72 public String getSignature() { 73 return m_signature; 74 } 75 76 public String getGenericsSignature() { 77 throw new RuntimeException (); 79 } 80 81 86 public AnnotationElement.Annotation[] getAnnotations() { 87 return getDeclaringType().getAnnotationReader().getMethodAnnotationElements(m_member.getName(), m_signature); 88 } 89 90 95 public ClassInfo getReturnType() { 96 if (m_returnType == null) { 97 Class returnTypeClass = ((Method ) m_member).getReturnType(); 98 if (m_classInfoRepository.hasClassInfo(returnTypeClass.getName())) { 99 m_returnType = m_classInfoRepository.getClassInfo(returnTypeClass.getName()); 100 } else { 101 m_returnType = JavaClassInfo.getClassInfo(returnTypeClass); 102 m_classInfoRepository.addClassInfo(m_returnType); 103 } 104 } 105 return m_returnType; 106 } 107 108 113 public ClassInfo[] getParameterTypes() { 114 if (m_parameterTypes == null) { 115 Class [] parameterTypes = ((Method ) m_member).getParameterTypes(); 116 m_parameterTypes = new ClassInfo[parameterTypes.length]; 117 for (int i = 0; i < parameterTypes.length; i++) { 118 Class parameterType = parameterTypes[i]; 119 ClassInfo metaData; 120 if (m_classInfoRepository.hasClassInfo(parameterType.getName())) { 121 metaData = m_classInfoRepository.getClassInfo(parameterType.getName()); 122 } else { 123 metaData = JavaClassInfo.getClassInfo(parameterType); 124 m_classInfoRepository.addClassInfo(metaData); 125 } 126 m_parameterTypes[i] = metaData; 127 } 128 } 129 return m_parameterTypes; 130 } 131 132 140 public String [] getParameterNames() { 141 return null; 142 } 143 144 149 public ClassInfo[] getExceptionTypes() { 150 if (m_exceptionTypes == null) { 151 Class [] exceptionTypes = ((Method ) m_member).getExceptionTypes(); 152 m_exceptionTypes = new ClassInfo[exceptionTypes.length]; 153 for (int i = 0; i < exceptionTypes.length; i++) { 154 Class exceptionType = exceptionTypes[i]; 155 ClassInfo metaData; 156 if (m_classInfoRepository.hasClassInfo(exceptionType.getName())) { 157 metaData = m_classInfoRepository.getClassInfo(exceptionType.getName()); 158 } else { 159 metaData = JavaClassInfo.getClassInfo(exceptionType); 160 m_classInfoRepository.addClassInfo(metaData); 161 } 162 m_exceptionTypes[i] = metaData; 163 } 164 } 165 return m_exceptionTypes; 166 } 167 168 public boolean equals(Object o) { 169 if (this == o) { 170 return true; 171 } 172 if (!(o instanceof MethodInfo)) { 173 return false; 174 } 175 MethodInfo methodInfo = (MethodInfo) o; 176 if (!m_declaringType.getName().equals(methodInfo.getDeclaringType().getName())) { 177 return false; 178 } 179 if (!m_member.getName().equals(methodInfo.getName())) { 180 return false; 181 } 182 Class [] parameterTypes1 = ((Method ) m_member).getParameterTypes(); 183 ClassInfo[] parameterTypes2 = methodInfo.getParameterTypes(); 184 if (parameterTypes1.length != parameterTypes2.length) { 185 return false; 186 } 187 for (int i = 0; i < parameterTypes1.length; i++) { 188 if (!parameterTypes1[i].getName().equals(parameterTypes2[i].getName())) { 189 return false; 190 } 191 } 192 return true; 193 } 194 195 public int hashCode() { 196 int result = 29; 197 result = (29 * result) + m_declaringType.getName().hashCode(); 198 result = (29 * result) + m_member.getName().hashCode(); 199 Class [] parameterTypes = ((Method ) m_member).getParameterTypes(); 200 for (int i = 0; i < parameterTypes.length; i++) { 201 result = (29 * result) + parameterTypes[i].getName().hashCode(); 202 } 203 return result; 204 } 205 206 public String toString() { 207 return m_member.toString(); 208 } 209 } | Popular Tags |