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"); } }
intConstant = ((ConstantInteger) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantLong) { longConstant = ((ConstantLong) constantRefOperand).getBytes();
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;
/** * Initialize from another object. */ public ConstantInteger(final ConstantInteger c) { this(c.getBytes()); }
/** * Initialize from another object. */ public ConstantInteger(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(); }
public char getValueChar() { if (super.getType() != PRIMITIVE_CHAR) { throw new RuntimeException( "Dont call getValueChar() on a non CHAR ElementValue"); } final ConstantInteger c = (ConstantInteger) super.getConstantPool().getConstant(getIndex(), Const.CONSTANT_Integer); return (char) c.getBytes(); }
public boolean getValueBoolean() { if (super.getType() != PRIMITIVE_BOOLEAN) { throw new RuntimeException( "Dont call getValueBoolean() on a non BOOLEAN ElementValue"); } final ConstantInteger bo = (ConstantInteger) super.getConstantPool().getConstant(getIndex()); return bo.getBytes() != 0; }
public Object getValue(ConstantPoolGen cpg) { org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index); switch(c.getTag()) { case org.apache.bcel.Constants.CONSTANT_String: int i = ((org.apache.bcel.classfile.ConstantString)c).getStringIndex(); c = cpg.getConstantPool().getConstant(i); return ((org.apache.bcel.classfile.ConstantUtf8)c).getBytes(); case org.apache.bcel.Constants.CONSTANT_Float: return new Float(((org.apache.bcel.classfile.ConstantFloat)c).getBytes()); case org.apache.bcel.Constants.CONSTANT_Integer: return new Integer(((org.apache.bcel.classfile.ConstantInteger)c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + index); } }
return Integer.toString(c.getBytes()); case PRIMITIVE_LONG: final ConstantLong j = (ConstantLong) getConstantPool().getConstant(idx); case PRIMITIVE_SHORT: final ConstantInteger s = (ConstantInteger) getConstantPool().getConstant(idx); return Integer.toString(s.getBytes()); case PRIMITIVE_BYTE: final ConstantInteger b = (ConstantInteger) getConstantPool().getConstant(idx); return Integer.toString(b.getBytes()); case PRIMITIVE_CHAR: final ConstantInteger ch = (ConstantInteger) getConstantPool().getConstant(idx); return Integer.toString(ch.getBytes()); case PRIMITIVE_BOOLEAN: final ConstantInteger bo = (ConstantInteger) getConstantPool().getConstant(idx); if (bo.getBytes() == 0) { return "false";
break; case Const.CONSTANT_Integer: buf = String.valueOf(((ConstantInteger) c).getBytes()); break; case Const.CONSTANT_String:
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"); } }
public Object getValue( final ConstantPoolGen cpg ) { org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(super.getIndex()); switch (c.getTag()) { case org.apache.bcel.Const.CONSTANT_String: final int i = ((org.apache.bcel.classfile.ConstantString) c).getStringIndex(); c = cpg.getConstantPool().getConstant(i); return ((org.apache.bcel.classfile.ConstantUtf8) c).getBytes(); case org.apache.bcel.Const.CONSTANT_Float: return new Float(((org.apache.bcel.classfile.ConstantFloat) c).getBytes()); case org.apache.bcel.Const.CONSTANT_Integer: return Integer.valueOf(((org.apache.bcel.classfile.ConstantInteger) c).getBytes()); case org.apache.bcel.Const.CONSTANT_Class: final int nameIndex = ((org.apache.bcel.classfile.ConstantClass) c).getNameIndex(); c = cpg.getConstantPool().getConstant(nameIndex); return new ObjectType(((org.apache.bcel.classfile.ConstantUtf8) c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + super.getIndex()); } }
/** * @return String representation of constant value. */ public final String toString() { Constant c = constant_pool.getConstant(constantvalue_index); String buf; int i; // Print constant to string depending on its type switch(c.getTag()) { case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break; case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break; case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break; case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break; case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8); buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\""; break; default: throw new IllegalStateException("Type of ConstValue invalid: " + c); } return buf; }
break; case Constants.CONSTANT_Integer: str= "" + ((ConstantInteger) c).getBytes(); break;