InstructionHandle ctor_ih_9 = ctor.append(fac.createReturn(Type.VOID)); cg.addMethod(ctorMethod.getMethod()); ctor.dispose(); InstructionHandle getter_ih_4 = getter.append(fac.createReturn(Type.OBJECT)); cg.addMethod(getterMethod.getMethod()); getter.dispose(); InstructionHandle setter_ih_0_ih_5 = setter.append(fac.createReturn(Type.VOID)); cg.addMethod(setterMethod.getMethod()); setter.dispose();
public void setMethods( final Method[] methods ) { method_vec.clear(); for (final Method method : methods) { addMethod(method); } }
public void setMethods(Method[] methods) { method_vec.clear(); for(int m=0; m<methods.length; m++) addMethod(methods[m]); }
public void addMethod(MethodGenerator methodGen) { Method[] methodsToAdd = methodGen.getGeneratedMethods(this); for (int i = 0; i < methodsToAdd.length; i++) { addMethod(methodsToAdd[i]); } } }
public void addMethod(MethodGenerator methodGen) { Method[] methodsToAdd = methodGen.getGeneratedMethods(this); for (int i = 0; i < methodsToAdd.length; i++) { addMethod(methodsToAdd[i]); } } }
import java.io.FileOutputStream; import org.apache.bcel.Const; import org.apache.bcel.generic.*; public class CreateB { public static void main(String[] args) throws Exception { ClassGen cg = new ClassGen("B", "A", "B.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {}); ConstantPoolGen cp = cg.getConstantPool(); InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "<init>", "B", il, cp); il.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); cg.getJavaClass().dump(new FileOutputStream("B.class")); } }
/** * Convenience method. * * Add an empty constructor to this class that does nothing but calling super(). * @param access_flags rights for constructor */ public void addEmptyConstructor( final int access_flags ) { final InstructionList il = new InstructionList(); il.append(InstructionConst.THIS); // Push `this' il.append(new INVOKESPECIAL(cp.addMethodref(super_class_name, "<init>", "()V"))); il.append(InstructionConst.RETURN); final MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, "<init>", class_name, il, cp); mg.setMaxStack(1); addMethod(mg.getMethod()); }
/** * Convenience method. * * Add an empty constructor to this class that does nothing but calling super(). * @param access rights for constructor */ public void addEmptyConstructor(int access_flags) { InstructionList il = new InstructionList(); il.append(InstructionConstants.THIS); // Push `this' il.append(new INVOKESPECIAL(cp.addMethodref(super_class_name, "<init>", "()V"))); il.append(InstructionConstants.RETURN); MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, "<init>", class_name, il, cp); mg.setMaxStack(1); addMethod(mg.getMethod()); }
private void createMethod_getARGV() { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, getObjectType(Object.class), new Type[] {}, new String[] {}, "getARGV", classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(factory.createFieldAccess(classname, argv_field, getObjectType(Object.class), Constants.GETFIELD)); tmpIl.append(InstructionFactory.createReturn(getObjectType(Object.class))); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createSetMethod(String method_name, String field_name, Class field_type) { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, Type.VOID, buildArgs(new Class[] {field_type}), new String[] {"arg"}, method_name, classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(InstructionConstants.ALOAD_1); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.PUTFIELD)); tmpIl.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createResetMethod(String method_name, String field_name) { InstructionList tmpIl = new InstructionList(); // no-arg method MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, Type.VOID, buildArgs(new Class[] {}), new String[] {}, method_name, classname, tmpIl, cp); // implement: setXX(ZERO) tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(factory.createFieldAccess(classname, "ZERO", getObjectType(Integer.class), Constants.GETSTATIC)); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.PUTFIELD)); tmpIl.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] { }, "test3", TEST_PACKAGE+".TestReturn03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(InstructionFactory.createReturn(Type.OBJECT)); method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); } }
private void generateEqualsMethod(String generatedClassName) { /* public boolean equals(Object o) { * return stubHelper.isEquals(this,o); * } */ InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD)); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE)); il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
private void createGetMethod(int method_access, String method_name, String field_name) { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(method_access | ACC_FINAL, getObjectType(Object.class), new Type[] {}, new String[] {}, method_name, classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.GETFIELD)); tmpIl.append(InstructionConstants.DUP); BranchHandle bh = tmpIl.append(new IFNONNULL(null)); // NULL! tmpIl.append(InstructionConstants.POP); // pop the null tmpIl.append(new PUSH(cp, "")); InstructionHandle ih = tmpIl.append(InstructionFactory.createReturn(getObjectType(Object.class))); bh.setTarget(ih); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestReturn03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestArrayAccess03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestReturn01", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestArrayAccess04", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestArrayAccess02", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, Type.NO_ARGS, new String[] { }, "foo", TEST_PACKAGE+".TestReturn01", il, _cp); final InstructionHandle ih_0 = il.append(_factory.createNew("java.lang.Object")); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(InstructionConst.DUP); il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); il.append(InstructionConst.NOP); final InstructionHandle ih_8 = il.append(InstructionFactory.createReturn(Type.OBJECT)); Assert.assertNotNull(ih_8); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); } }