/** * Add a new NameAndType constant to the ConstantPool if it is not already * in there. * * @param name Name string to add * @param signature signature string to add * @return index of entry */ public int addNameAndType( final String name, final String signature ) { int ret; int name_index; int signature_index; if ((ret = lookupNameAndType(name, signature)) != -1) { return ret; // Already in CP } adjustSize(); name_index = addUtf8(name); signature_index = addUtf8(signature); ret = index; constants[index++] = new ConstantNameAndType(name_index, signature_index); final String key = name + NAT_DELIM + signature; if (!n_a_t_table.containsKey(key)) { n_a_t_table.put(key, new Index(ret)); } return ret; }
/** * Add a new NameAndType constant to the ConstantPool if it is not already * in there. * * @param n NameAndType string to add * @return index of entry */ public int addNameAndType(String name, String signature) { int ret; int name_index, signature_index; if((ret = lookupNameAndType(name, signature)) != -1) return ret; // Already in CP adjustSize(); name_index = addUtf8(name); signature_index = addUtf8(signature); ret = index; constants[index++] = new ConstantNameAndType(name_index, signature_index); n_a_t_table.put(name + NAT_DELIM + signature, new Index(ret)); return ret; }
/** * Read one constant from the given file, the type depends on a tag byte. * * @param file Input stream * @return Constant object */ static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatException { byte b = file.readByte(); // Read tag byte switch(b) { case Constants.CONSTANT_Class: return new ConstantClass(file); case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); case Constants.CONSTANT_InterfaceMethodref: return new ConstantInterfaceMethodref(file); case Constants.CONSTANT_String: return new ConstantString(file); case Constants.CONSTANT_Integer: return new ConstantInteger(file); case Constants.CONSTANT_Float: return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file); case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); default: throw new ClassFormatException("Invalid byte tag in constant pool: " + b); } } }
return new ConstantDouble(dataInput); case Const.CONSTANT_NameAndType: return new ConstantNameAndType(dataInput); case Const.CONSTANT_Utf8: return ConstantUtf8.getInstance(dataInput);