Search in sources :

Example 1 with ConstantFloat

use of org.apache.bcel.classfile.ConstantFloat in project jop by jop-devel.

the class ConstantPoolRebuilder method copyConstant.

public static Constant copyConstant(Map<Integer, Integer> idMap, Constant c) {
    if (c instanceof ConstantClass) {
        int index = ((ConstantClass) c).getNameIndex();
        return new ConstantClass(idMap.get(index));
    } else if (c instanceof ConstantFieldref) {
        int clsIdx = ((ConstantFieldref) c).getClassIndex();
        int nameIdx = ((ConstantFieldref) c).getNameAndTypeIndex();
        return new ConstantFieldref(idMap.get(clsIdx), idMap.get(nameIdx));
    } else if (c instanceof ConstantMethodref) {
        int clsIdx = ((ConstantMethodref) c).getClassIndex();
        int nameIdx = ((ConstantMethodref) c).getNameAndTypeIndex();
        return new ConstantMethodref(idMap.get(clsIdx), idMap.get(nameIdx));
    } else if (c instanceof ConstantInterfaceMethodref) {
        int clsIdx = ((ConstantInterfaceMethodref) c).getClassIndex();
        int nameIdx = ((ConstantInterfaceMethodref) c).getNameAndTypeIndex();
        return new ConstantInterfaceMethodref(idMap.get(clsIdx), idMap.get(nameIdx));
    } else if (c instanceof ConstantString) {
        int index = ((ConstantString) c).getStringIndex();
        return new ConstantString(idMap.get(index));
    } else if (c instanceof ConstantInteger) {
        return new ConstantInteger((ConstantInteger) c);
    } else if (c instanceof ConstantFloat) {
        return new ConstantFloat((ConstantFloat) c);
    } else if (c instanceof ConstantLong) {
        return new ConstantLong((ConstantLong) c);
    } else if (c instanceof ConstantDouble) {
        return new ConstantDouble((ConstantDouble) c);
    } else if (c instanceof ConstantNameAndType) {
        int nameIdx = ((ConstantNameAndType) c).getNameIndex();
        int sigIdx = ((ConstantNameAndType) c).getSignatureIndex();
        return new ConstantNameAndType(idMap.get(nameIdx), idMap.get(sigIdx));
    } else if (c instanceof ConstantUtf8) {
        return new ConstantUtf8((ConstantUtf8) c);
    }
    throw new JavaClassFormatError("Unknown constant type " + c);
}
Also used : ConstantString(org.apache.bcel.classfile.ConstantString) ConstantDouble(org.apache.bcel.classfile.ConstantDouble) ConstantUtf8(org.apache.bcel.classfile.ConstantUtf8) ConstantFloat(org.apache.bcel.classfile.ConstantFloat) ConstantNameAndType(org.apache.bcel.classfile.ConstantNameAndType) ConstantMethodref(org.apache.bcel.classfile.ConstantMethodref) ConstantLong(org.apache.bcel.classfile.ConstantLong) ConstantFieldref(org.apache.bcel.classfile.ConstantFieldref) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) ConstantInterfaceMethodref(org.apache.bcel.classfile.ConstantInterfaceMethodref) ConstantClass(org.apache.bcel.classfile.ConstantClass) ConstantInteger(org.apache.bcel.classfile.ConstantInteger)

Aggregations

JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)1 ConstantClass (org.apache.bcel.classfile.ConstantClass)1 ConstantDouble (org.apache.bcel.classfile.ConstantDouble)1 ConstantFieldref (org.apache.bcel.classfile.ConstantFieldref)1 ConstantFloat (org.apache.bcel.classfile.ConstantFloat)1 ConstantInteger (org.apache.bcel.classfile.ConstantInteger)1 ConstantInterfaceMethodref (org.apache.bcel.classfile.ConstantInterfaceMethodref)1 ConstantLong (org.apache.bcel.classfile.ConstantLong)1 ConstantMethodref (org.apache.bcel.classfile.ConstantMethodref)1 ConstantNameAndType (org.apache.bcel.classfile.ConstantNameAndType)1 ConstantString (org.apache.bcel.classfile.ConstantString)1 ConstantUtf8 (org.apache.bcel.classfile.ConstantUtf8)1