private void pushByConstant(DismantleBytecode dbc, Constant c) { if (c instanceof ConstantClass) { push(new Item("Ljava/lang/Class;", ((ConstantClass) c).getConstantValue(dbc.getConstantPool()))); } else if (c instanceof ConstantInteger) { push(new Item("I", Integer.valueOf(((ConstantInteger) c).getBytes()))); } else if (c instanceof ConstantString) { int s = ((ConstantString) c).getStringIndex(); push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s))); } else if (c instanceof ConstantFloat) { push(new Item("F", Float.valueOf(((ConstantFloat) c).getBytes()))); } else if (c instanceof ConstantDouble) { push(new Item("D", Double.valueOf(((ConstantDouble) c).getBytes()))); } else if (c instanceof ConstantLong) { push(new Item("J", Long.valueOf(((ConstantLong) c).getBytes()))); } else { throw new UnsupportedOperationException("StaticConstant type not expected"); } }
break; case org.apache.bcel.Const.CONSTANT_Integer: str = ((ConstantInteger) c).toString(); break;
/** * Add a new Integer constant to the ConstantPool, if it is not already in there. * * @param n integer number to add * @return index of entry */ public int addInteger( final int n ) { int ret; if ((ret = lookupInteger(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index++] = new ConstantInteger(n); return ret; }
@Override public void visitConstantInteger(final ConstantInteger obj) { if (obj.getTag() != Const.CONSTANT_Integer) { throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } // no indices to check } @Override
public void visitConstantInteger(ConstantInteger constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
/** * Add a new Integer constant to the ConstantPool, if it is not already in there. * * @param n integer number to add * @return index of entry */ public int addInteger(int n) { int ret; if((ret = lookupInteger(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index++] = new ConstantInteger(n); return ret; }
public void visitConstantInteger(ConstantInteger obj){ if (obj.getTag() != Constants.CONSTANT_Integer){ throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } // no indices to check } public void visitConstantFloat(ConstantFloat obj){
@Override public void visitConstantInteger(final ConstantInteger constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
intConstant = ((ConstantInteger) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantLong) { longConstant = ((ConstantLong) constantRefOperand).getBytes();
/** * 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); } } }
if (testingEnabled && (c instanceof ConstantInteger && ((ConstantInteger) c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT || c instanceof ConstantLong && ((ConstantLong) c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT)) { BugInstance bug = new BugInstance(this, "TESTING", HIGH_PRIORITY).addClassAndMethod(this) accumulator.accumulateBug(bug, this); if ((c instanceof ConstantInteger && ((ConstantInteger) c).getBytes() == Integer.MIN_VALUE || c instanceof ConstantLong && ((ConstantLong) c).getBytes() == Long.MIN_VALUE)) { sawLoadOfMinValue = true;
return new ConstantString(dataInput); case Const.CONSTANT_Integer: return new ConstantInteger(dataInput); case Const.CONSTANT_Float: return new ConstantFloat(dataInput);
/** * Initialize from another object. */ public ConstantInteger(ConstantInteger c) { this(c.getBytes()); }
/** * Initialize from another object. */ public ConstantInteger(final ConstantInteger c) { this(c.getBytes()); }
/** * Look for ConstantInteger in ConstantPool. * * @param n integer number to look for * @return index on success, -1 otherwise */ public int lookupInteger( final int n ) { for (int i = 1; i < index; i++) { if (constants[i] instanceof ConstantInteger) { final ConstantInteger c = (ConstantInteger) constants[i]; if (c.getBytes() == n) { return i; } } } return -1; }
/** * Look for ConstantInteger in ConstantPool. * * @param n integer number to look for * @return index on success, -1 otherwise */ public int lookupInteger(int n) { for(int i=1; i < index; i++) { if(constants[i] instanceof ConstantInteger) { ConstantInteger c = (ConstantInteger)constants[i]; if(c.getBytes() == n) return i; } } return -1; }
public int getValueInt() { if (super.getElementValueType() != PRIMITIVE_INT) { throw new RuntimeException( "Dont call getValueString() on a non STRING ElementValue"); } final ConstantInteger c = (ConstantInteger) getConstantPool().getConstant(idx); return c.getBytes(); }
public int getValueInt() { if (super.getType() != PRIMITIVE_INT) { throw new RuntimeException( "Dont call getValueString() on a non STRING ElementValue"); } final ConstantInteger c = (ConstantInteger) super.getConstantPool().getConstant(getIndex(), Const.CONSTANT_Integer); return c.getBytes(); }
public short getValueShort() { if (super.getType() != PRIMITIVE_SHORT) { throw new RuntimeException( "Dont call getValueShort() on a non SHORT ElementValue"); } final ConstantInteger s = (ConstantInteger) super.getConstantPool().getConstant(getIndex()); return (short) s.getBytes(); }
public byte getValueByte() { if (super.getType() != PRIMITIVE_BYTE) { throw new RuntimeException( "Dont call getValueByte() on a non BYTE ElementValue"); } final ConstantInteger c = (ConstantInteger) super.getConstantPool().getConstant(getIndex(), Const.CONSTANT_Integer); return (byte) c.getBytes(); }