/** * Set the value of this constant; note that this type is converted to int. * * @return this instruction, for method chaining */ public ConstantInstruction setValue(short value) { return setValue((int) value); }
/** * Set the value of this constant. * * @return this instruction, for method chaining */ public ConstantInstruction setValue(Class value) { if (value == null) return setNull(); calculateOpcode(value.getName(), true, false); return this; }
/** * Load some constant onto the stack. The {@link ConstantInstruction} * type takes any constant and correctly translates it into the proper * opcode, depending on the constant type and value. For example, * if the constant value is set to 0L, the opcode will be set to * <code>lconst0</code>. */ public ConstantInstruction constant() { return (ConstantInstruction) addInstruction(new ConstantInstruction (this)); }
void read(Instruction orig) { super.read(orig); ConstantInstruction ci = (ConstantInstruction) orig; calculateOpcode(ci.getValue(), Class.class.getName().equals(ci.getTypeName()), ci.getOpcode() == Constants.LDCW); }
private void calculateOpcode(Object value, boolean clsName, boolean wide) { int len = getLength(); _arg = -1; if (value == null) setOpcode(Constants.ACONSTNULL); else if (clsName) { String name = getProject().getNameCache().getInternalForm((String) value, false); _arg = getPool().findClassEntry(name, true); setOpcode(Constants.LDCW); ensureBytecodeVersion(); } else if (value instanceof Float) { float floatVal = ((Float) value).floatValue(); if ((floatVal == 0) || (floatVal == 1) || (floatVal == 2)) setOpcode(Constants.FCONST0 + (int) floatVal); else { _arg = getPool().findFloatEntry((float) floatVal, true); setOpcode((_arg > 255 || wide) ? Constants.LDCW : Constants.LDC); long longVal = ((Long) value).longValue(); if (longVal == 0 || longVal == 1) setOpcode(Constants.LCONST0 + (int) longVal); else { _arg = getPool().findLongEntry(longVal, true); setOpcode(Constants.LDC2W); setOpcode(Constants.DCONST0 + (int) doubleVal); else { _arg = getPool().findDoubleEntry(doubleVal, true);
name); } else code.constant().setNull(); code.areturn(); code.calculateMaxLocals();
int opcode = getOpcode(); switch (opcode) { case Constants.NOP: return Numbers.valueOf(_arg); default: Entry entry = getPool().getEntry(_arg); Object val = ((ConstantEntry) entry).getConstant(); if (entry.getType() == Entry.CLASS) return getProject().getNameCache().getExternalForm((String) val, false); return val;
/** * Set this constant to null. * * @return this instruction, for method chaining */ public ConstantInstruction setNull() { calculateOpcode(null, false, false); return this; }
void read(DataInput in) throws IOException { super.read(in); switch (getOpcode()) { case Constants.BIPUSH: case Constants.LDC: _arg = in.readUnsignedByte(); break; case Constants.SIPUSH: case Constants.LDCW: case Constants.LDC2W: _arg = in.readUnsignedShort(); } }
/** * When adding class entries, make sure the bytecode spec supports them. */ private void ensureBytecodeVersion() { BCClass bc = getCode().getMethod().getDeclarer(); if (bc.getMajorVersion() < Constants.MAJOR_VERSION_JAVA5) { bc.setMajorVersion(Constants.MAJOR_VERSION_JAVA5); bc.setMinorVersion(Constants.MINOR_VERSION_JAVA5); } } }
name); } else code.constant().setNull(); code.areturn(); code.calculateMaxLocals();
private void calculateOpcode(Object value, boolean clsName, boolean wide) { int len = getLength(); _arg = -1; if (value == null) setOpcode(Constants.ACONSTNULL); else if (clsName) { String name = getProject().getNameCache().getInternalForm((String) value, false); _arg = getPool().findClassEntry(name, true); setOpcode(Constants.LDCW); ensureBytecodeVersion(); } else if (value instanceof Float) { float floatVal = ((Float) value).floatValue(); if ((floatVal == 0) || (floatVal == 1) || (floatVal == 2)) setOpcode(Constants.FCONST0 + (int) floatVal); else { _arg = getPool().findFloatEntry((float) floatVal, true); setOpcode((_arg > 255 || wide) ? Constants.LDCW : Constants.LDC); long longVal = ((Long) value).longValue(); if (longVal == 0 || longVal == 1) setOpcode(Constants.LCONST0 + (int) longVal); else { _arg = getPool().findLongEntry(longVal, true); setOpcode(Constants.LDC2W); setOpcode(Constants.DCONST0 + (int) doubleVal); else { _arg = getPool().findDoubleEntry(doubleVal, true);
void read(Instruction orig) { super.read(orig); ConstantInstruction ci = (ConstantInstruction) orig; calculateOpcode(ci.getValue(), Class.class.getName().equals(ci.getTypeName()), ci.getOpcode() == Constants.LDCW); }
int opcode = getOpcode(); switch (opcode) { case Constants.NOP: return Numbers.valueOf(_arg); default: Entry entry = getPool().getEntry(_arg); Object val = ((ConstantEntry) entry).getConstant(); if (entry.getType() == Entry.CLASS) return getProject().getNameCache().getExternalForm((String) val, false); return val;
public ConstantInstruction setValue(String value, boolean clsName) { calculateOpcode(value, clsName, false); return this; }
void read(DataInput in) throws IOException { super.read(in); switch (getOpcode()) { case Constants.BIPUSH: case Constants.LDC: _arg = in.readUnsignedByte(); break; case Constants.SIPUSH: case Constants.LDCW: case Constants.LDC2W: _arg = in.readUnsignedShort(); } }