public String getSignature() { return Type.getMethodSignature(type, arg_types); }
@Override public String getSignature() { return Type.getMethodSignature(super.getType(), arg_types); }
/** * Return string representation close to declaration format, * `public static void main(String[]) throws IOException', e.g. * * @return String representation of the method. */ public final String toString() { String access = Utility.accessToString(access_flags); String signature = Type.getMethodSignature(type, arg_types); signature = Utility.methodSignatureToString(signature, name, access, true, getLocalVariableTable(cp)); StringBuffer buf = new StringBuffer(signature); if(throws_vec.size() > 0) { for(Iterator e = throws_vec.iterator(); e.hasNext(); ) buf.append("\n\t\tthrows " + e.next()); } return buf.toString(); }
/** * Return string representation close to declaration format, * `public static void main(String[]) throws IOException', e.g. * * @return String representation of the method. */ @Override public final String toString() { final String access = Utility.accessToString(super.getAccessFlags()); String signature = Type.getMethodSignature(super.getType(), arg_types); signature = Utility.methodSignatureToString(signature, super.getName(), access, true, getLocalVariableTable(super.getConstantPool())); final StringBuilder buf = new StringBuilder(signature); for (final Attribute a : getAttributes()) { if (!((a instanceof Code) || (a instanceof ExceptionTable))) { buf.append(" [").append(a).append("]"); } } if (throws_vec.size() > 0) { for (final String throwsDescriptor : throws_vec) { buf.append("\n\t\tthrows ").append(throwsDescriptor); } } return buf.toString(); }
protected static String getField(Type target, String name, Type ret, Type[] args) throws ClassNotFoundException { final JavaClass clazz = Repository.lookupClass(target.toString()); for (Method method : clazz.getMethods()) { if (method.getName().equals(name) && method.getSignature().equals(Type.getMethodSignature(ret, args))) { final Code code = method.getCode(); final Instruction[] instructions = new InstructionList(code.getCode()).getInstructions(); if (instructions.length != 3) throw new Error("Method " + method + " does not have exactly three instruction!"); if (!(instructions[0] instanceof ALOAD) || (((ALOAD) instructions[0]).getIndex() != 0)) throw new Error(); if (!(instructions[instructions.length - 1] instanceof ReturnInstruction)) throw new Error(); final ConstantPoolGen constantPoolGen = new ConstantPoolGen(method.getConstantPool()); final GETFIELD get = ((GETFIELD) instructions[1]); return get.getFieldName(constantPoolGen); } } throw new Error(); }
/** Create an invoke instruction. * * @param class_name name of the called class * @param name name of the called method * @param ret_type return type of method * @param arg_types argument types of method * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, * or INVOKESPECIAL * @see Constants */ public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind) { int index; int nargs = 0; String signature = Type.getMethodSignature(ret_type, arg_types); for(int i=0; i < arg_types.length; i++) // Count size of arguments nargs += arg_types[i].getSize(); if(kind == Constants.INVOKEINTERFACE) index = cp.addInterfaceMethodref(class_name, name, signature); else index = cp.addMethodref(class_name, name, signature); switch(kind) { case Constants.INVOKESPECIAL: return new INVOKESPECIAL(index); case Constants.INVOKEVIRTUAL: return new INVOKEVIRTUAL(index); case Constants.INVOKESTATIC: return new INVOKESTATIC(index); case Constants.INVOKEINTERFACE: return new INVOKEINTERFACE(index, nargs + 1); default: throw new RuntimeException("Oops: Unknown invoke kind:" + kind); } }
int index; int nargs = 0; final String signature = Type.getMethodSignature(ret_type, arg_types); for (final Type arg_type : arg_types) { nargs += arg_type.getSize();
String sig = Type.getMethodSignature(Type.STRINGBUFFER, new Type[]{ Type.STRING }); il.append( new INVOKEVIRTUAL(