public int addConstant( Constant c, ConstantPoolGen cp ) {
Constant[] constants = cp.getConstantPool().getConstantPool();
switch (c.getTag()) {
case Constants.CONSTANT_String: {
ConstantString s = (ConstantString) c;
ConstantUtf8 u8 = (ConstantUtf8) constants[s.getStringIndex()];
return addString(u8.getBytes());
}
case Constants.CONSTANT_Class: {
ConstantClass s = (ConstantClass) c;
ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
return addClass(u8.getBytes());
}
case Constants.CONSTANT_NameAndType: {
ConstantNameAndType n = (ConstantNameAndType) c;
ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
return addNameAndType(u8.getBytes(), u8_2.getBytes());
}
case Constants.CONSTANT_Utf8:
return addUtf8(((ConstantUtf8) c).getBytes());
case Constants.CONSTANT_Double:
return addDouble(((ConstantDouble) c).getBytes());
case Constants.CONSTANT_Float:
return addFloat(((ConstantFloat) c).getBytes());
case Constants.CONSTANT_Long:
return addLong(((ConstantLong) c).getBytes());
case Constants.CONSTANT_Integer:
return addInteger(((ConstantInteger) c).getBytes());
case Constants.CONSTANT_InterfaceMethodref:
case Constants.CONSTANT_Methodref:
case Constants.CONSTANT_Fieldref: {
ConstantCP m = (ConstantCP) c;
ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
String class_name = u8.getBytes().replace('/', '.');
u8 = (ConstantUtf8) constants[n.getNameIndex()];
String name = u8.getBytes();
u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
String signature = u8.getBytes();
switch (c.getTag()) {
case Constants.CONSTANT_InterfaceMethodref:
return addInterfaceMethodref(class_name, name, signature);
case Constants.CONSTANT_Methodref:
return addMethodref(class_name, name, signature);