1 4 package com.tc.aspectwerkz.reflect.impl.asm; 5 6 import com.tc.backport175.bytecode.AnnotationElement.Annotation; 7 8 import com.tc.asm.Type; 9 10 import com.tc.aspectwerkz.transform.inlining.AsmHelper; 11 import com.tc.aspectwerkz.reflect.ClassInfo; 12 import com.tc.aspectwerkz.reflect.FieldInfo; 13 14 19 public class AsmFieldInfo extends AsmMemberInfo implements FieldInfo { 20 21 24 private String m_typeName; 25 26 29 private ClassInfo m_type = null; 30 31 38 AsmFieldInfo(final FieldStruct field, final String declaringType, final ClassLoader loader) { 39 super(field, declaringType, loader); 40 m_typeName = Type.getType(field.desc).getClassName(); 41 } 42 43 52 public static FieldInfo getFieldInfo(final String fieldName, 53 final String fieldDesc, 54 final byte[] bytecode, 55 final ClassLoader loader) { 56 String className = AsmClassInfo.retrieveClassNameFromBytecode(bytecode); 57 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 58 ClassInfo classInfo = repository.getClassInfo(className); 59 if (classInfo == null) { 60 classInfo = AsmClassInfo.getClassInfo(bytecode, loader); 61 } 62 return classInfo.getField(AsmHelper.calculateFieldHash(fieldName, fieldDesc)); 63 } 64 65 70 public String getSignature() { 71 return AsmHelper.getFieldDescriptor(this); 72 } 73 74 public String getGenericsSignature() { 75 return m_member.signature; 76 } 77 78 83 public ClassInfo getType() { 84 if (m_type == null) { 85 m_type = AsmClassInfo.getClassInfo(m_typeName, (ClassLoader ) m_loaderRef.get()); 86 } 87 return m_type; 88 } 89 90 95 public Annotation[] getAnnotations() { 96 return getDeclaringType().getAnnotationReader().getFieldAnnotationElements(m_member.name, m_member.desc); 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_declaringTypeName.equals(fieldInfo.getDeclaringType().getName())) { 108 return false; 109 } 110 if (!m_member.name.equals(fieldInfo.getName())) { 111 return false; 112 } 113 if (!m_typeName.equals(fieldInfo.getType().getName())) { 114 return false; 115 } 116 return true; 117 } 118 119 public int hashCode() { 120 int result = 29; 121 result = (29 * result) + m_declaringTypeName.hashCode(); 122 result = (29 * result) + m_member.name.hashCode(); 123 result = (29 * result) + m_typeName.hashCode(); 124 return result; 125 } 126 127 public String toString() { 128 StringBuffer sb = new StringBuffer (m_declaringTypeName); 129 sb.append('.').append(m_member.name).append(' '); 130 sb.append(m_member.desc); 131 return sb.toString(); 132 } 133 } | Popular Tags |