constValue = ((ConstantFloat) c).getBytes(); } else if (c instanceof ConstantLong) { constValue = ((ConstantLong) c).getBytes(); } else { state = SEEN_NOTHING;
break; case org.apache.bcel.Const.CONSTANT_Long: str = ((ConstantLong) c).toString(); break; case org.apache.bcel.Const.CONSTANT_Integer:
/** * Add a new long constant to the ConstantPool, if it is not already in there. * * @param n Long number to add * @return index of entry */ public int addLong(long n) { int ret; if((ret = lookupLong(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index] = new ConstantLong(n); index += 2; // Wastes one entry according to spec return ret; }
public void visitConstantLong(ConstantLong constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
@Override public void visitConstantLong(final ConstantLong obj) { if (obj.getTag() != Const.CONSTANT_Long) { throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } //no indices to check } @Override
/** * Add a new long constant to the ConstantPool, if it is not already in there. * * @param n Long number to add * @return index of entry */ public int addLong( final long n ) { int ret; if ((ret = lookupLong(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index] = new ConstantLong(n); index += 2; // Wastes one entry according to spec return ret; }
@Override public void visitConstantLong(final ConstantLong constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
public void visitConstantLong(ConstantLong obj){ if (obj.getTag() != Constants.CONSTANT_Long){ throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } //no indices to check } public void visitConstantDouble(ConstantDouble obj){
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"); } }
/** * 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); } } }
@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
return new ConstantFloat(dataInput); case Const.CONSTANT_Long: return new ConstantLong(dataInput); case Const.CONSTANT_Double: return new ConstantDouble(dataInput);
intConstant = ((ConstantInteger) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantLong) { longConstant = ((ConstantLong) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantFloat) { floatConstant = ((ConstantFloat) constantRefOperand).getBytes();
Constant c = getConstantRefOperand(); 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) .addString("Did you mean MICROS_PER_DAY").addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) || c instanceof ConstantLong && ((ConstantLong) c).getBytes() == Long.MIN_VALUE)) { sawLoadOfMinValue = true; pendingAbsoluteValueBug = null;
/** * Initialize from another object. */ public ConstantLong(ConstantLong c) { this(c.getBytes()); } /**
/** * Initialize from another object. */ public ConstantLong(final ConstantLong c) { this(c.getBytes()); }
/** * Look for ConstantLong in ConstantPool. * * @param n Long number to look for * @return index on success, -1 otherwise */ public int lookupLong(long n) { for(int i=1; i < index; i++) { if(constants[i] instanceof ConstantLong) { ConstantLong c = (ConstantLong)constants[i]; if(c.getBytes() == n) return i; } } return -1; }
/** * Look for ConstantLong in ConstantPool. * * @param n Long number to look for * @return index on success, -1 otherwise */ public int lookupLong( final long n ) { for (int i = 1; i < index; i++) { if (constants[i] instanceof ConstantLong) { final ConstantLong c = (ConstantLong) constants[i]; if (c.getBytes() == n) { return i; } } } return -1; }
public Number getValue(ConstantPoolGen cpg) { org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index); switch(c.getTag()) { case org.apache.bcel.Constants.CONSTANT_Long: return new Long(((org.apache.bcel.classfile.ConstantLong)c).getBytes()); case org.apache.bcel.Constants.CONSTANT_Double: return new Double(((org.apache.bcel.classfile.ConstantDouble)c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + index); } }
public long getValueLong() { if (super.getType() != PRIMITIVE_LONG) { throw new RuntimeException( "Dont call getValueLong() on a non LONG ElementValue"); } final ConstantLong j = (ConstantLong) super.getConstantPool().getConstant(getIndex()); return j.getBytes(); }