1 18 19 package alt.jiapi.reflect; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import alt.jiapi.file.ClassFile; 26 import alt.jiapi.file.ConstantPool; 27 import alt.jiapi.file.Field; 28 import alt.jiapi.file.Attribute; 29 30 37 public class JiapiField { 38 private JiapiClass declaringClass; 39 private Field field; 40 41 JiapiField(Field f) { 42 this.field = f; 43 } 44 45 46 51 public String getName() { 52 return field.getName(); 53 } 54 55 64 public JiapiClass getType() throws ClassNotFoundException { 65 Loader loader = getDeclaringClass().getLoader(); 66 JiapiClass clazz = null; 67 try { 68 clazz = loader.loadClass(getTypeName()); 69 } 70 catch(java.io.IOException ioe) { 71 throw new ClassNotFoundException (getTypeName()); 72 } 73 74 return clazz; 75 } 76 77 82 public String getTypeName() { 83 String descriptor = getDescriptor(); 84 String type = TypeHelper.descriptorToType(descriptor); 85 86 return type; 87 } 88 89 92 String getDescriptor() { 93 return field.getDescriptor(); 94 } 95 96 100 public int getModifiers() { 101 return field.getAccessFlags(); 102 } 103 104 110 void setModifiers(int modifiers) { 111 throw new RuntimeException ("Operation not supported"); 114 } 115 116 117 Field getField() { 118 return field; 119 } 120 121 122 128 public JiapiClass getDeclaringClass() { 129 return declaringClass; 130 } 131 132 133 135 public String toString() { 136 StringBuffer sb = 137 new StringBuffer (Modifier.toString(getModifiers())); 138 sb.append(' '); 139 sb.append(getTypeName()); 140 sb.append(' '); 141 sb.append(getName()); 142 143 return sb.toString(); 144 } 145 146 147 152 void setDeclaringClass(JiapiClass declaringClass) { 153 this.declaringClass = declaringClass; 154 } 155 156 157 158 161 private List getAttributes() { 162 return field.getAttributes(); 163 } 164 165 166 169 private Attribute getAttribute(String name) { 170 List l = getAttributes(); 171 Iterator i = l.iterator(); 172 174 while(i.hasNext()) { 175 Attribute a = (Attribute)i.next(); 176 177 if (a.getName().equals(name)) { 178 return a; 179 } 180 } 181 182 return null; 183 } 184 } 185 | Popular Tags |