in src/main/java/org/apache/bcel/generic/ConstantPoolGen.java [275:330]
public int addConstant(final Constant constant, final ConstantPoolGen cpGen) {
final Constant[] constants = cpGen.getConstantPool().getConstantPool();
switch (constant.getTag()) {
case Const.CONSTANT_String: {
final ConstantString s = (ConstantString) constant;
final ConstantUtf8 u8 = (ConstantUtf8) constants[s.getStringIndex()];
return addString(u8.getBytes());
}
case Const.CONSTANT_Class: {
final ConstantClass s = (ConstantClass) constant;
final ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
return addClass(u8.getBytes());
}
case Const.CONSTANT_NameAndType: {
final ConstantNameAndType n = (ConstantNameAndType) constant;
final ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
final ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
return addNameAndType(u8.getBytes(), u8_2.getBytes());
}
case Const.CONSTANT_Utf8:
return addUtf8(((ConstantUtf8) constant).getBytes());
case Const.CONSTANT_Double:
return addDouble(((ConstantDouble) constant).getBytes());
case Const.CONSTANT_Float:
return addFloat(((ConstantFloat) constant).getBytes());
case Const.CONSTANT_Long:
return addLong(((ConstantLong) constant).getBytes());
case Const.CONSTANT_Integer:
return addInteger(((ConstantInteger) constant).getBytes());
case Const.CONSTANT_InterfaceMethodref:
case Const.CONSTANT_Methodref:
case Const.CONSTANT_Fieldref: {
final ConstantCP m = (ConstantCP) constant;
final ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
final ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
final String className = Utility.pathToPackage(u8.getBytes());
u8 = (ConstantUtf8) constants[n.getNameIndex()];
final String name = u8.getBytes();
u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
final String signature = u8.getBytes();
switch (constant.getTag()) {
case Const.CONSTANT_InterfaceMethodref:
return addInterfaceMethodref(className, name, signature);
case Const.CONSTANT_Methodref:
return addMethodref(className, name, signature);
case Const.CONSTANT_Fieldref:
return addFieldref(className, name, signature);
default: // Never reached
throw new IllegalArgumentException("Unknown constant type " + constant);
}
}
default: // Never reached
throw new IllegalArgumentException("Unknown constant type " + constant);
}
}