1 32 package net.sf.retrotranslator.runtime.impl; 33 34 import java.lang.reflect.*; 35 import net.sf.retrotranslator.runtime.asm.signature.SignatureReader; 36 import net.sf.retrotranslator.runtime.java.lang.annotation.Annotation_; 37 38 41 public class FieldDescriptor extends AnnotatedElementDescriptor { 42 43 private String name; 44 private String desc; 45 private ClassDescriptor classDescriptor; 46 private TypeDescriptor typeDescriptor; 47 48 public FieldDescriptor(ClassDescriptor classDescriptor, int access, String name, String desc, String signature) { 49 this.classDescriptor = classDescriptor; 50 this.access = access; 51 this.name = name; 52 this.desc = desc; 53 if (signature != null) { 54 typeDescriptor = new TypeDescriptor(); 55 new SignatureReader(signature).accept(typeDescriptor); 56 } 57 } 58 59 public FieldDescriptor(ClassDescriptor classDescriptor, Field field) { 60 this(classDescriptor, field.getModifiers(), field.getName(), 61 net.sf.retrotranslator.runtime.asm.Type.getDescriptor(field.getType()), null); 62 } 63 64 public static FieldDescriptor getInstance(Field field) { 65 ClassDescriptor classDescriptor = ClassDescriptor.getInstance(field.getDeclaringClass()); 66 FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor(field.getName()); 67 return fieldDescriptor != null ? fieldDescriptor : new FieldDescriptor(classDescriptor, field); 68 } 69 70 public String getName() { 71 return name; 72 } 73 74 public String getDesc() { 75 return desc; 76 } 77 78 public Type getGenericType() { 79 return createType(typeDescriptor); 80 } 81 82 public ClassDescriptor getClassDescriptor() { 83 return classDescriptor; 84 } 85 86 protected TypeVariable findTypeVariable(String name) { 87 return classDescriptor.findTypeVariable(name); 88 } 89 90 protected Annotation_[] createAnnotations(Annotation_[] declaredAnnotations) { 91 return declaredAnnotations; 92 } 93 94 } 95 | Popular Tags |