/** * 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; }
/** * 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; }
/** * Create primitive element values */ public void testCreateIntegerElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_INT, cp, 555); // Creation of an element like that should leave a new entry in the // cpool assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + cp.lookupInteger(555), evg.getIndex() == cp.lookupInteger(555)); checkSerialize(evg, cp); }
public void testCreateByteElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_CHAR, cp, (byte) 'z'); // Creation of an element like that should leave a new entry in the // cpool final int idx = cp.lookupInteger((byte) 'z'); assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + idx, evg.getIndex() == idx); checkSerialize(evg, cp); }
public void testCreateShortElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_SHORT, cp, (short) 42); // Creation of an element like that should leave a new entry in the // cpool final int idx = cp.lookupInteger(42); assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + idx, evg.getIndex() == idx); checkSerialize(evg, cp); }
public void testCreateCharElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_CHAR, cp, 't'); // Creation of an element like that should leave a new entry in the // cpool final int idx = cp.lookupInteger('t'); assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + idx, evg.getIndex() == idx); checkSerialize(evg, cp); }
public void testCreateBooleanElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_BOOLEAN, cp, true); // Creation of an element like that should leave a new entry in the // cpool final int idx = cp.lookupInteger(1); // 1 == true assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + idx, evg.getIndex() == idx); checkSerialize(evg, cp); }