1 4 package com.tc.aspectwerkz.reflect.impl.java; 5 6 import com.tc.backport175.bytecode.AnnotationElement; 7 8 9 import java.lang.reflect.Field ; 10 11 import com.tc.aspectwerkz.reflect.ClassInfo; 12 import com.tc.aspectwerkz.reflect.ReflectHelper; 13 import com.tc.aspectwerkz.reflect.FieldInfo; 14 15 20 public class JavaFieldInfo extends JavaMemberInfo implements FieldInfo { 21 24 private ClassInfo m_type = null; 25 26 29 private String m_signature; 30 31 37 JavaFieldInfo(final Field field, final JavaClassInfo declaringType) { 38 super(field, declaringType); 39 m_signature = ReflectHelper.getFieldSignature(field); 40 } 41 42 48 public static FieldInfo getFieldInfo(final Field field) { 49 Class declaringClass = field.getDeclaringClass(); 50 JavaClassInfoRepository repository = JavaClassInfoRepository.getRepository(declaringClass.getClassLoader()); 51 ClassInfo classInfo = repository.getClassInfo(declaringClass.getName()); 52 if (classInfo == null) { 53 classInfo = JavaClassInfo.getClassInfo(declaringClass); 54 } 55 return classInfo.getField(ReflectHelper.calculateHash(field)); 56 } 57 58 63 public String getSignature() { 64 return m_signature; 65 } 66 67 public String getGenericsSignature() { 68 throw new RuntimeException (); 70 } 71 72 77 public AnnotationElement.Annotation[] getAnnotations() { 78 return getDeclaringType().getAnnotationReader().getFieldAnnotationElements(getName(), m_signature); 79 } 80 81 86 public ClassInfo getType() { 87 if (m_type == null) { 88 Class type = ((Field ) m_member).getType(); 89 if (m_classInfoRepository.hasClassInfo(type.getName())) { 90 m_type = m_classInfoRepository.getClassInfo(type.getName()); 91 } else { 92 m_type = JavaClassInfo.getClassInfo(type); 93 m_classInfoRepository.addClassInfo(m_type); 94 } 95 } 96 return m_type; 97 } 98 99 public boolean equals(Object o) { 100 if (this == o) { 101 return true; 102 } 103 if (!(o instanceof FieldInfo)) { 104 return false; 105 } 106 FieldInfo fieldInfo = (FieldInfo) o; 107 if (!m_declaringType.getName().equals(fieldInfo.getDeclaringType().getName())) { 108 return false; 109 } 110 if (!m_member.getName().equals(fieldInfo.getName())) { 111 return false; 112 } 113 ClassInfo fieldType = fieldInfo.getType(); 114 if (!m_type.getName().equals(fieldType.getName())) { 115 return false; 116 } 117 return true; 118 } 119 120 public int hashCode() { 121 int result = 29; 122 if (m_type == null) { 123 getType(); 124 } 125 result = (29 * result) + m_declaringType.getName().hashCode(); 126 result = (29 * result) + m_member.getName().hashCode(); 127 result = (29 * result) + getType().getName().hashCode(); 128 return result; 129 } 130 } | Popular Tags |