1 7 8 package org.gjt.jclasslib.structures; 9 10 import org.gjt.jclasslib.structures.constants.*; 11 12 import java.io.DataInput ; 13 import java.io.IOException ; 14 15 21 public abstract class CPInfo extends AbstractStructure { 22 23 public static final byte CONSTANT_CLASS = 7; 24 public static final byte CONSTANT_FIELDREF = 9; 25 public static final byte CONSTANT_METHODREF = 10; 26 public static final byte CONSTANT_INTERFACE_METHODREF = 11; 27 public static final byte CONSTANT_STRING = 8; 28 public static final byte CONSTANT_INTEGER = 3; 29 public static final byte CONSTANT_FLOAT = 4; 30 public static final byte CONSTANT_LONG = 5; 31 public static final byte CONSTANT_DOUBLE = 6; 32 public static final byte CONSTANT_NAME_AND_TYPE = 12; 33 public static final byte CONSTANT_UTF8 = 1; 34 35 public static final String CONSTANT_CLASS_VERBOSE = "CONSTANT_Class_info"; 36 public static final String CONSTANT_FIELDREF_VERBOSE = "CONSTANT_Fieldref_info"; 37 public static final String CONSTANT_METHODREF_VERBOSE = "CONSTANT_Methodref_info"; 38 public static final String CONSTANT_INTERFACE_METHODREF_VERBOSE = "CONSTANT_InterfaceMethodref_info"; 39 public static final String CONSTANT_STRING_VERBOSE = "CONSTANT_String_info"; 40 public static final String CONSTANT_INTEGER_VERBOSE = "CONSTANT_Integer_info"; 41 public static final String CONSTANT_FLOAT_VERBOSE = "CONSTANT_Float_info"; 42 public static final String CONSTANT_LONG_VERBOSE = "CONSTANT_Long_info"; 43 public static final String CONSTANT_DOUBLE_VERBOSE = "CONSTANT_Double_info"; 44 public static final String CONSTANT_NAME_AND_TYPE_VERBOSE = "CONSTANT_NameAndType_info"; 45 public static final String CONSTANT_UTF8_VERBOSE = "CONSTANT_Utf8_info"; 46 47 58 public static CPInfo create(DataInput in, ClassFile classFile) 59 throws InvalidByteCodeException, IOException { 60 61 CPInfo cpInfo; 62 63 byte tag = in.readByte(); 64 65 switch (tag) { 66 case CONSTANT_CLASS: 67 cpInfo = new ConstantClassInfo(); 68 break; 69 case CONSTANT_FIELDREF: 70 cpInfo = new ConstantFieldrefInfo(); 71 break; 72 case CONSTANT_METHODREF: 73 cpInfo = new ConstantMethodrefInfo(); 74 break; 75 case CONSTANT_INTERFACE_METHODREF: 76 cpInfo = new ConstantInterfaceMethodrefInfo(); 77 break; 78 case CONSTANT_STRING: 79 cpInfo = new ConstantStringInfo(); 80 break; 81 case CONSTANT_INTEGER: 82 cpInfo = new ConstantIntegerInfo(); 83 break; 84 case CONSTANT_FLOAT: 85 cpInfo = new ConstantFloatInfo(); 86 break; 87 case CONSTANT_LONG: 88 cpInfo = new ConstantLongInfo(); 89 break; 90 case CONSTANT_DOUBLE: 91 cpInfo = new ConstantDoubleInfo(); 92 break; 93 case CONSTANT_NAME_AND_TYPE: 94 cpInfo = new ConstantNameAndTypeInfo(); 95 break; 96 case CONSTANT_UTF8: 97 cpInfo = new ConstantUtf8Info(); 98 break; 99 default: 100 throw new InvalidByteCodeException("invalid constant pool entry with unknown tag " + tag); 101 } 102 cpInfo.setClassFile(classFile); 103 cpInfo.read(in); 104 105 return cpInfo; 106 } 107 108 109 114 public abstract byte getTag(); 115 116 122 public abstract String getTagVerbose(); 123 124 130 public String getVerbose() throws InvalidByteCodeException { 131 return ""; 132 } 133 134 142 public static int skip(DataInput in) 143 throws InvalidByteCodeException, IOException { 144 145 int offset = 0; 146 147 byte tag = in.readByte(); 148 149 switch (tag) { 150 case CONSTANT_CLASS: 151 in.skipBytes(ConstantClassInfo.SIZE); 152 break; 153 case CONSTANT_FIELDREF: 154 case CONSTANT_METHODREF: 155 case CONSTANT_INTERFACE_METHODREF: 156 in.skipBytes(ConstantReference.SIZE); 157 break; 158 case CONSTANT_STRING: 159 in.skipBytes(ConstantStringInfo.SIZE); 160 break; 161 case CONSTANT_INTEGER: 162 case CONSTANT_FLOAT: 163 in.skipBytes(ConstantNumeric.SIZE); 164 break; 165 case CONSTANT_LONG: 166 case CONSTANT_DOUBLE: 167 in.skipBytes(ConstantLargeNumeric.SIZE); 168 offset = 1; 169 break; 170 case CONSTANT_NAME_AND_TYPE: 171 in.skipBytes(ConstantNameAndTypeInfo.SIZE); 172 break; 173 case CONSTANT_UTF8: 174 in.skipBytes(in.readUnsignedShort()); 176 break; 177 default: 178 throw new InvalidByteCodeException("invalid constant pool entry with unknown tag " + tag); 179 } 180 181 return offset; 182 } 183 184 public boolean equals(Object object) { 185 return object instanceof CPInfo; 186 } 187 188 public int hashCode() { 189 return 0; 190 } 191 192 protected String printAccessFlagsVerbose(int accessFlags) { 193 if (accessFlags != 0) 194 throw new RuntimeException ("Access flags should be zero: " + Integer.toHexString(accessFlags)); 195 return ""; 196 } 197 } 198 | Popular Tags |