public void visitConstantDouble(ConstantDouble constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
/** * Initialize from another object. */ public ConstantDouble(ConstantDouble c) { this(c.getBytes()); }
public void visitConstantDouble(ConstantDouble obj){ if (obj.getTag() != Constants.CONSTANT_Double){ throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } //no indices to check } public void visitConstantNameAndType(ConstantNameAndType obj){
/** * Add a new double constant to the ConstantPool, if it is not already in there. * * @param n Double number to add * @return index of entry */ public int addDouble(double n) { int ret; if((ret = lookupDouble(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index] = new ConstantDouble(n); index += 2; // Wastes one entry according to spec return ret; }
/** * Add a new double constant to the ConstantPool, if it is not already in there. * * @param n Double number to add * @return index of entry */ public int addDouble(double n) { int ret; if((ret = lookupDouble(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index] = new ConstantDouble(n); index += 2; // Wastes one entry according to spec return ret; }
/** * Initialize from another object. */ public ConstantDouble(ConstantDouble c) { this(c.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); } } }
public void visitConstantDouble(ConstantDouble constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
public void visitConstantDouble(ConstantDouble obj){ if (obj.getTag() != Constants.CONSTANT_Double){ throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } //no indices to check } public void visitConstantNameAndType(ConstantNameAndType obj){
/** * Look for ConstantDouble in ConstantPool. * * @param n Double number to look for * @return index on success, -1 otherwise */ public int lookupDouble(double n) { long bits = Double.doubleToLongBits(n); for(int i=1; i < index; i++) { if(constants[i] instanceof ConstantDouble) { ConstantDouble c = (ConstantDouble)constants[i]; if(Double.doubleToLongBits(c.getBytes()) == bits) return i; } } return -1; }
/** * 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); } } }
/** * Look for ConstantDouble in ConstantPool. * * @param n Double number to look for * @return index on success, -1 otherwise */ public int lookupDouble(double n) { long bits = Double.doubleToLongBits(n); for(int i=1; i < index; i++) { if(constants[i] instanceof ConstantDouble) { ConstantDouble c = (ConstantDouble)constants[i]; if(Double.doubleToLongBits(c.getBytes()) == bits) return i; } } return -1; }
public Number getValue(ConstantPoolGen cpg) { com.sun.org.apache.bcel.internal.classfile.Constant c = cpg.getConstantPool().getConstant(index); switch(c.getTag()) { case com.sun.org.apache.bcel.internal.Constants.CONSTANT_Long: return new Long(((com.sun.org.apache.bcel.internal.classfile.ConstantLong)c).getBytes()); case com.sun.org.apache.bcel.internal.Constants.CONSTANT_Double: return new Double(((com.sun.org.apache.bcel.internal.classfile.ConstantDouble)c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + index); } }
public Number getValue(ConstantPoolGen cpg) { com.sun.org.apache.bcel.internal.classfile.Constant c = cpg.getConstantPool().getConstant(index); switch(c.getTag()) { case com.sun.org.apache.bcel.internal.Constants.CONSTANT_Long: return new Long(((com.sun.org.apache.bcel.internal.classfile.ConstantLong)c).getBytes()); case com.sun.org.apache.bcel.internal.Constants.CONSTANT_Double: return new Double(((com.sun.org.apache.bcel.internal.classfile.ConstantDouble)c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + index); } }
/** * @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; }
/** * @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; }
case Constants.CONSTANT_Double: str = "" + ((ConstantDouble)c).getBytes(); break; case Constants.CONSTANT_Float: str = "" + ((ConstantFloat)c).getBytes(); break; case Constants.CONSTANT_Long: str = "" + ((ConstantLong)c).getBytes(); break;
case Constants.CONSTANT_Double: str = "" + ((ConstantDouble)c).getBytes(); break; case Constants.CONSTANT_Float: str = "" + ((ConstantFloat)c).getBytes(); break; case Constants.CONSTANT_Long: str = "" + ((ConstantLong)c).getBytes(); break;
return addDouble(((ConstantDouble)c).getBytes());
return addDouble(((ConstantDouble)c).getBytes());