1 25 26 package org.netbeans.modules.classfile; 27 28 import java.io.DataInputStream ; 29 import java.io.IOException ; 30 31 37 public abstract class ElementValue { 38 static ElementValue load(DataInputStream in, ConstantPool pool, 39 boolean runtimeVisible) 40 throws IOException { 41 char tag = (char)in.readByte(); 42 switch (tag) { 43 case 'e': return loadEnumValue(in, pool); 44 case 'c': { 45 int classType = in.readUnsignedShort(); 46 return new ClassElementValue(pool, classType); 47 } 48 case '@': { 49 Annotation value = 50 Annotation.loadAnnotation(in, pool, runtimeVisible); 51 return new NestedElementValue(pool, value); 52 } 53 case '[': { 54 ElementValue[] values = new ElementValue[in.readUnsignedShort()]; 55 for (int i = 0; i < values.length; i++) 56 values[i] = load(in, pool, runtimeVisible); 57 return new ArrayElementValue(pool, values); 58 } 59 default: 60 assert "BCDFIJSZs".indexOf(tag) >= 0 : "invalid annotation tag"; 61 return new PrimitiveElementValue(pool, in.readUnsignedShort()); 62 } 63 } 64 65 private static ElementValue loadEnumValue(DataInputStream in, 66 ConstantPool pool) 67 throws IOException { 68 int type = in.readUnsignedShort(); 69 CPEntry cpe = pool.get(type); 70 if (cpe.getTag() == ConstantPool.CONSTANT_FieldRef) { 71 CPFieldInfo fe = (CPFieldInfo)cpe; 73 String enumType = fe.getClassName().getInternalName(); 74 String enumName = fe.getFieldName(); 75 return new EnumElementValue(enumType, enumName); 76 } else { 77 int name = in.readUnsignedShort(); 78 return new EnumElementValue(pool, type, name); 79 } 80 } 81 82 85 ElementValue() { 86 } 87 } 88 | Popular Tags |