1 8 package org.codehaus.aspectwerkz.reflect.impl.java; 9 10 import org.codehaus.aspectwerkz.annotation.Annotations; 11 import org.codehaus.aspectwerkz.reflect.ClassInfo; 12 import org.codehaus.aspectwerkz.reflect.FieldInfo; 13 import org.codehaus.aspectwerkz.reflect.ReflectHelper; 14 15 import java.lang.reflect.Field ; 16 import java.util.List ; 17 18 23 public class JavaFieldInfo extends JavaMemberInfo implements FieldInfo { 24 27 private ClassInfo m_type = null; 28 29 32 private String m_signature; 33 34 40 JavaFieldInfo(final Field field, final JavaClassInfo declaringType) { 41 super(field, declaringType); 42 m_signature = ReflectHelper.getFieldSignature(field); 43 } 44 45 51 public static FieldInfo getFieldInfo(final Field field) { 52 Class declaringClass = field.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.getField(ReflectHelper.calculateHash(field)); 59 } 60 61 66 public String getSignature() { 67 return m_signature; 68 } 69 70 75 public List getAnnotations() { 76 if (m_annotations == null) { 77 m_annotations = Annotations.getAnnotationInfos((Field ) m_member); 78 } 79 return m_annotations; 80 } 81 82 87 public ClassInfo getType() { 88 if (m_type == null) { 89 Class type = ((Field ) m_member).getType(); 90 if (m_classInfoRepository.hasClassInfo(type.getName())) { 91 m_type = m_classInfoRepository.getClassInfo(type.getName()); 92 } else { 93 m_type = JavaClassInfo.getClassInfo(type); 94 m_classInfoRepository.addClassInfo(m_type); 95 } 96 } 97 return m_type; 98 } 99 100 public boolean equals(Object o) { 101 if (this == o) { 102 return true; 103 } 104 if (!(o instanceof FieldInfo)) { 105 return false; 106 } 107 FieldInfo fieldInfo = (FieldInfo) o; 108 if (!m_declaringType.getName().equals(fieldInfo.getDeclaringType().getName())) { 109 return false; 110 } 111 if (!m_member.getName().equals(fieldInfo.getName())) { 112 return false; 113 } 114 ClassInfo fieldType = fieldInfo.getType(); 115 if (!m_type.getName().equals(fieldType.getName())) { 116 return false; 117 } 118 return true; 119 } 120 121 public int hashCode() { 122 int result = 29; 123 if (m_type == null) { 124 getType(); 125 } 126 result = (29 * result) + m_declaringType.getName().hashCode(); 127 result = (29 * result) + m_member.getName().hashCode(); 128 result = (29 * result) + getType().getName().hashCode(); 129 return result; 130 } 131 } | Popular Tags |