/** * Equivalent to <code>setLocal (0).setType (Object.class)</code>; the * <code>this</code> ptr is always passed in local variable 0. * * @return this instruction, for method chaining */ public LoadInstruction setThis() { return (LoadInstruction) setLocal(0).setType(Object.class); }
/** * Equivalent to <code>setLocal (0).setType (Object.class)</code>; the * <code>this</code> ptr is always passed in local variable 0. * * @return this instruction, for method chaining */ public LoadInstruction setThis() { return (LoadInstruction) setLocal(0).setType(Object.class); }
/** * Set the local variable object this instruction * operates on. This method will set both the type and local index * of this instruction from the given local variable. * * @return this instruction, for method chaining */ public LocalVariableInstruction setLocalVariable(LocalVariable local) { if (local == null) return setLocal(-1); String type = local.getTypeName(); if (type != null) setType(type); return setLocal(local.getLocal()); }
/** * Set the local variable object this instruction * operates on. This method will set both the type and local index * of this instruction from the given local variable. * * @return this instruction, for method chaining */ public LocalVariableInstruction setLocalVariable(LocalVariable local) { if (local == null) return setLocal(-1); String type = local.getTypeName(); if (type != null) setType(type); return setLocal(local.getLocal()); }
/** * Set the method parameter that this instruction operates on. This * will set both the local index and the type of the instruction based * on the current method parameters. */ public LocalVariableInstruction setParam(int param) { int local = getCode().getLocalsIndex(param); if (local != -1) { BCMethod method = getCode().getMethod(); setType(method.getParamNames()[param]); } return setLocal(local); }
/** * 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(); }
/** * Set the method parameter that this instruction operates on. This * will set both the local index and the type of the instruction based * on the current method parameters. */ public LocalVariableInstruction setParam(int param) { int local = getCode().getLocalsIndex(param); if (local != -1) { BCMethod method = getCode().getMethod(); setType(method.getParamNames()[param]); } return setLocal(local); }
/** * 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(); }
/** * 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(); }