/** * Set the return type of the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethodReturn(String type) { return setMethod(getMethodDeclarerName(), getMethodName(), type, getMethodParamNames()); }
/** * Return the method this instruction operates on, or null if not set. */ public BCMethod getMethod() { String dec = getMethodDeclarerName(); if (dec == null) return null; BCClass bc = getProject().loadClass(dec, getClassLoader()); BCMethod[] meths = bc.getMethods(getMethodName(),getMethodParamNames()); if (meths.length == 0) return null; return meths[0]; }
/** * Set the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethod(Constructor method) { if (method == null) return setMethodIndex(0); setOpcode(Constants.INVOKESPECIAL); return setMethod(method.getDeclaringClass(), "<init>", void.class, method.getParameterTypes()); }
/** * Return the return type of the method this instruction operates on, * or null if not set. */ public BCClass getMethodReturnBC() { String type = getMethodReturnName(); if (type == null) return null; return getProject().loadClass(type, getClassLoader()); }
/** * Set the method this instruction operates on. * * @param dec the full class name of the method's declaring class * @param name the method name * @param returnType the full class name of the method return type * @param param the full class names of the method param types * @return this instruction, for method chaining */ public MethodInstruction setMethod(String dec, String name, String returnType, String[] params) { return setMethod(dec, name, returnType, params, true); }
/** * Set the method this instruction operates on, for methods that are * declared by the current class. * * @param name the method name * @param returnType the full class name of the method return type * @param param the full class names of the method param types * @return this instruction, for method chaining */ public MethodInstruction setMethod(String name, String returnType, String[] params) { BCClass owner = getCode().getMethod().getDeclarer(); return setMethod(owner.getName(), name, returnType, params); }
/** * Set the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethod(Method method) { if (method == null) return setMethodIndex(0); return setMethod(method.getDeclaringClass(), method.getName(), method.getReturnType(), method.getParameterTypes()); }
public int getLogicalStackChange() { String ret = getMethodReturnName(); if (ret == null) return 0; // subtract a stack pos for the this ptr int stack = 0; if (getOpcode() != Constants.INVOKESTATIC) stack--; // and for each arg String[] params = getMethodParamNames(); for (int i = 0; i < params.length; i++) stack--; // add for the return value, if any if (!void.class.getName().equals(ret)) stack++; return stack; }
/** * Return the declaring type of the method this instruction operates on, * or null if not set. */ public BCClass getMethodDeclarerBC() { String type = getMethodDeclarerName(); if (type == null) return null; return getProject().loadClass(type, getClassLoader()); }
/** * Return the param types of the method this instruction operates on, * or empty array if none. */ public BCClass[] getMethodParamBCs() { String[] paramNames = getMethodParamNames(); BCClass[] params = new BCClass[paramNames.length]; for (int i = 0; i < paramNames.length; i++) params[i] = getProject().loadClass(paramNames[i], getClassLoader()); return params; }
/** * Return the declaring type of the method this instruction operates on, * or null if not set. */ public Class getMethodDeclarerType() { String type = getMethodDeclarerName(); if (type == null) return null; return Strings.toClass(type, getClassLoader()); }
/** * Return the param types of the method this instruction operates on, * or empty array if none. */ public Class[] getMethodParamTypes() { String[] paramNames = getMethodParamNames(); Class[] params = new Class[paramNames.length]; for (int i = 0; i < paramNames.length; i++) params[i] = Strings.toClass(paramNames[i], getClassLoader()); return params; }
/** * Return the return type of the method this instruction operates on, * or null if not set. */ public Class getMethodReturnType() { String type = getMethodReturnName(); if (type == null) return null; return Strings.toClass(type, getClassLoader()); }
void write(DataOutput out) throws IOException { super.write(out); out.writeShort(_index); if (getOpcode() == Constants.INVOKEINTERFACE) { String[] args = getMethodParamNames(); int count = 1; for (int i = 0; i < args.length; i++, count++) if (long.class.getName().equals(args[i]) || double.class.getName().equals(args[i])) count++; out.writeByte(count); out.writeByte(0); } else if (getOpcode() == Constants.INVOKEDYNAMIC) { out.writeByte(0); out.writeByte(0); } } }
case Constants.INVOKEINTERFACE: case Constants.INVOKEDYNAMIC: return new MethodInstruction(this, opcode); case Constants.NEW: case Constants.ANEWARRAY:
/** * Set the method this instruction operates on. * * @param dec the full class name of the method's declaring class * @param name the method name * @param returnType the full class name of the method return type * @param param the full class names of the method param types * @return this instruction, for method chaining */ public MethodInstruction setMethod(String dec, String name, String returnType, String[] params) { return setMethod(dec, name, returnType, params, true); }
/** * Set the method this instruction operates on, for methods that are * declared by the current class. * * @param name the method name * @param returnType the full class name of the method return type * @param param the full class names of the method param types * @return this instruction, for method chaining */ public MethodInstruction setMethod(String name, String returnType, String[] params) { BCClass owner = getCode().getMethod().getDeclarer(); return setMethod(owner.getName(), name, returnType, params); }
/** * Set the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethod(Method method) { if (method == null) return setMethodIndex(0); return setMethod(method.getDeclaringClass(), method.getName(), method.getReturnType(), method.getParameterTypes()); }
/** * Set the method this instruction operates on. * * @return this instruction, for method chaining */ public MethodInstruction setMethod(Constructor method) { if (method == null) return setMethodIndex(0); setOpcode(Constants.INVOKESPECIAL); return setMethod(method.getDeclaringClass(), "<init>", void.class, method.getParameterTypes()); }
public int getLogicalStackChange() { String ret = getMethodReturnName(); if (ret == null) return 0; // subtract a stack pos for the this ptr int stack = 0; if (getOpcode() != Constants.INVOKESTATIC) stack--; // and for each arg String[] params = getMethodParamNames(); for (int i = 0; i < params.length; i++) stack--; // add for the return value, if any if (!void.class.getName().equals(ret)) stack++; return stack; }