/** * Proxy the given method with one that overrides it by calling into the * given helper. */ private void proxyOverrideMethod(BCClass bc, Method meth, Method helper, Class[] params) { BCMethod m = bc.declareMethod(meth.getName(), meth.getReturnType(), meth.getParameterTypes()); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); for (int i = 1; i < params.length; i++) code.xload().setParam(i - 1).setType(params[i]); code.invokestatic().setMethod(helper); code.xreturn().setType(meth.getReturnType()); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given method with one that overrides it by calling into the * given helper. */ private void proxyOverrideMethod(BCClass bc, Method meth, Method helper, Class[] params) { BCMethod m = bc.declareMethod(meth.getName(), meth.getReturnType(), meth.getParameterTypes()); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); for (int i = 1; i < params.length; i++) code.xload().setParam(i - 1).setType(params[i]); code.invokestatic().setMethod(helper); code.xreturn().setType(meth.getReturnType()); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given method with one that overrides it by calling into the * given helper. */ private void proxyOverrideMethod(BCClass bc, Method meth, Method helper, Class[] params) { BCMethod m = bc.declareMethod(meth.getName(), meth.getReturnType(), meth.getParameterTypes()); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); for (int i = 1; i < params.length; i++) code.xload().setParam(i - 1).setType(params[i]); code.invokestatic().setMethod(helper); code.xreturn().setType(meth.getReturnType()); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given method with one that overrides it by calling into the * given helper. */ private void proxyOverrideMethod(BCClass bc, Method meth, Method helper, Class[] params) { BCMethod m = bc.declareMethod(meth.getName(), meth.getReturnType(), meth.getParameterTypes()); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); for (int i = 1; i < params.length; i++) code.xload().setParam(i - 1).setType(params[i]); code.invokestatic().setMethod(helper); code.xreturn().setType(meth.getReturnType()); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given method with one that overrides it by calling into the * given helper. */ private void proxyOverrideMethod(BCClass bc, Method meth, Method helper, Class[] params) { BCMethod m = bc.declareMethod(meth.getName(), meth.getReturnType(), meth.getParameterTypes()); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); for (int i = 1; i < params.length; i++) code.xload().setParam(i - 1).setType(params[i]); code.invokestatic().setMethod(helper); code.xreturn().setType(meth.getReturnType()); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Create pass-through constructors to base type. */ private void delegateConstructors(BCClass bc, Class type) { Constructor[] cons = type.getConstructors(); Class[] params; BCMethod m; Code code; for (int i = 0; i < cons.length; i++) { params = cons[i].getParameterTypes(); m = bc.declareMethod("<init>", void.class, params); m.makePublic(); code = m.getCode(true); code.aload().setThis(); for (int j = 0; j < params.length; j++) code.xload().setParam(j).setType(params[j]); code.invokespecial().setMethod(cons[i]); code.vreturn(); code.calculateMaxStack(); code.calculateMaxLocals(); } }
/** * Create pass-through constructors to base type. */ private void delegateConstructors(BCClass bc, Class type) { Constructor[] cons = type.getConstructors(); Class[] params; BCMethod m; Code code; for (int i = 0; i < cons.length; i++) { params = cons[i].getParameterTypes(); m = bc.declareMethod("<init>", void.class, params); m.makePublic(); code = m.getCode(true); code.aload().setThis(); for (int j = 0; j < params.length; j++) code.xload().setParam(j).setType(params[j]); code.invokespecial().setMethod(cons[i]); code.vreturn(); code.calculateMaxStack(); code.calculateMaxLocals(); } }
/** * Create pass-through constructors to base type. */ private void delegateConstructors(BCClass bc, Class type) { Constructor[] cons = type.getConstructors(); Class[] params; BCMethod m; Code code; for (int i = 0; i < cons.length; i++) { params = cons[i].getParameterTypes(); m = bc.declareMethod("<init>", void.class, params); m.makePublic(); code = m.getCode(true); code.aload().setThis(); for (int j = 0; j < params.length; j++) code.xload().setParam(j).setType(params[j]); code.invokespecial().setMethod(cons[i]); code.vreturn(); code.calculateMaxStack(); code.calculateMaxLocals(); } }
/** * Proxy the given setter method to dirty the proxy owner. */ private void proxySetter(BCClass bc, Class type, Method meth) { Class[] params = meth.getParameterTypes(); Class ret = meth.getReturnType(); BCMethod m = bc.declareMethod(meth.getName(), ret, params); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); code.constant().setValue(true); code.invokestatic().setMethod(Proxies.class, "dirty", void.class, new Class[] { Proxy.class, boolean.class }); code.aload().setThis(); for (int i = 0; i < params.length; i++) code.xload().setParam(i).setType(params[i]); code.invokespecial().setMethod(type, meth.getName(), ret, params); code.xreturn().setType(ret); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given setter method to dirty the proxy owner. */ private void proxySetter(BCClass bc, Class type, Method meth) { Class[] params = meth.getParameterTypes(); Class ret = meth.getReturnType(); BCMethod m = bc.declareMethod(meth.getName(), ret, params); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); code.constant().setValue(true); code.invokestatic().setMethod(Proxies.class, "dirty", void.class, new Class[] { Proxy.class, boolean.class }); code.aload().setThis(); for (int i = 0; i < params.length; i++) code.xload().setParam(i).setType(params[i]); code.invokespecial().setMethod(type, meth.getName(), ret, params); code.xreturn().setType(ret); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given setter method to dirty the proxy owner. */ private void proxySetter(BCClass bc, Class type, Method meth) { Class[] params = meth.getParameterTypes(); Class ret = meth.getReturnType(); BCMethod m = bc.declareMethod(meth.getName(), ret, params); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); code.constant().setValue(true); code.invokestatic().setMethod(Proxies.class, "dirty", void.class, new Class[] { Proxy.class, boolean.class }); code.aload().setThis(); for (int i = 0; i < params.length; i++) code.xload().setParam(i).setType(params[i]); code.invokespecial().setMethod(type, meth.getName(), ret, params); code.xreturn().setType(ret); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given setter method to dirty the proxy owner. */ private void proxySetter(BCClass bc, Class type, Method meth) { Class[] params = meth.getParameterTypes(); Class ret = meth.getReturnType(); BCMethod m = bc.declareMethod(meth.getName(), ret, params); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); code.constant().setValue(true); code.invokestatic().setMethod(Proxies.class, "dirty", void.class, new Class[] { Proxy.class, boolean.class }); code.aload().setThis(); for (int i = 0; i < params.length; i++) code.xload().setParam(i).setType(params[i]); code.invokespecial().setMethod(type, meth.getName(), ret, params); code.xreturn().setType(ret); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Proxy the given setter method to dirty the proxy owner. */ private void proxySetter(BCClass bc, Class type, Method meth) { Class[] params = meth.getParameterTypes(); Class ret = meth.getReturnType(); BCMethod m = bc.declareMethod(meth.getName(), ret, params); m.makePublic(); Code code = m.getCode(true); code.aload().setThis(); code.constant().setValue(true); code.invokestatic().setMethod(Proxies.class, "dirty", void.class, new Class[] { Proxy.class, boolean.class }); code.aload().setThis(); for (int i = 0; i < params.length; i++) code.xload().setParam(i).setType(params[i]); code.invokespecial().setMethod(type, meth.getName(), ret, params); code.xreturn().setType(ret); code.calculateMaxStack(); code.calculateMaxLocals(); }
/** * Add method which defers to AbstractPCData. */ protected void callAbstractPCData(BCClass bc, String name, Class retType, Class[] args) { BCMethod meth = bc.declareMethod(name, retType, args); Code code = meth.getCode(true); code.aload().setThis(); for (int i = 0; i < args.length; i++) code.xload().setParam(i).setType(args[i]); code.invokevirtual().setMethod(AbstractPCData.class, name, retType, args); if (!void.class.equals(retType)) code.xreturn().setType(retType); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Add method which defers to AbstractPCData. */ protected void callAbstractPCData(BCClass bc, String name, Class<?> retType, Class<?>[] args) { BCMethod meth = bc.declareMethod(name, retType, args); Code code = meth.getCode(true); code.aload().setThis(); for (int i = 0; i < args.length; i++) code.xload().setParam(i).setType(args[i]); code.invokevirtual().setMethod(AbstractPCData.class, name, retType, args); if (!void.class.equals(retType)) code.xreturn().setType(retType); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Add method which defers to AbstractPCData. */ protected void callAbstractPCData(BCClass bc, String name, Class<?> retType, Class<?>[] args) { BCMethod meth = bc.declareMethod(name, retType, args); Code code = meth.getCode(true); code.aload().setThis(); for (int i = 0; i < args.length; i++) code.xload().setParam(i).setType(args[i]); code.invokevirtual().setMethod(AbstractPCData.class, name, retType, args); if (!void.class.equals(retType)) code.xreturn().setType(retType); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Add method which defers to AbstractPCData. */ protected void callAbstractPCData(BCClass bc, String name, Class<?> retType, Class<?>[] args) { BCMethod meth = bc.declareMethod(name, retType, args); Code code = meth.getCode(true); code.aload().setThis(); for (int i = 0; i < args.length; i++) code.xload().setParam(i).setType(args[i]); code.invokevirtual().setMethod(AbstractPCData.class, name, retType, args); if (!void.class.equals(retType)) code.xreturn().setType(retType); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Add method which defers to AbstractPCData. */ protected void callAbstractPCData(BCClass bc, String name, Class<?> retType, Class<?>[] args) { BCMethod meth = bc.declareMethod(name, retType, args); Code code = meth.getCode(true); code.aload().setThis(); for (int i = 0; i < args.length; i++) code.xload().setParam(i).setType(args[i]); code.invokevirtual().setMethod(AbstractPCData.class, name, retType, args); if (!void.class.equals(retType)) code.xreturn().setType(retType); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Convenience method to add a default constructor to this class. * If a default constructor already exists, this method will return it * without modification. * This method can only be called if the superclass has been set. * * @return the default constructor */ public BCMethod addDefaultConstructor() { BCMethod method = getDeclaredMethod("<init>", (String[]) null); if (method != null) return method; method = declareMethod("<init>", void.class, null); Code code = method.getCode(true); code.setMaxStack(1); code.setMaxLocals(1); code.xload().setThis(); code.invokespecial() .setMethod(getSuperclassName(), "<init>", "void", null); code.vreturn(); return method; }
/** * Convenience method to add a default constructor to this class. * If a default constructor already exists, this method will return it * without modification. * This method can only be called if the superclass has been set. * * @return the default constructor */ public BCMethod addDefaultConstructor() { BCMethod method = getDeclaredMethod("<init>", (String[]) null); if (method != null) return method; method = declareMethod("<init>", void.class, null); Code code = method.getCode(true); code.setMaxStack(1); code.setMaxLocals(1); code.xload().setThis(); code.invokespecial() .setMethod(getSuperclassName(), "<init>", "void", null); code.vreturn(); return method; }