@Test public void mustFindMethodsWithSpecificSetOfParameters() { List<MethodNode> methodNodes = findMethodsWithParameters(classNode.methods, Type.INT_TYPE, Type.getType(List.class), Type.DOUBLE_TYPE); assertEquals(1, methodNodes.size()); assertEquals("method1", methodNodes.get(0).name); }
public static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes) { Validate.notNull(methodNodes); Validate.notNull(paramTypes); Validate.noNullElements(methodNodes); Validate.noNullElements(paramTypes); for (Type paramType : paramTypes) { Validate.isTrue(paramType.getSort() != Type.METHOD && paramType.getSort() != Type.VOID); } List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNode : methodNodes) { Type methodDescType = Type.getType(methodNode.desc); Type[] methodParamTypes = methodDescType.getArgumentTypes(); if (methodParamTypes.length != paramTypes.length) { continue; } boolean found = true; for (int i = 0; i < methodParamTypes.length; i++) { if (!paramTypes[i].equals(methodParamTypes[i])) { found = false; } } if (found) { ret.add(methodNode); } } return ret; }
SearchUtils { public static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes) { Validate.notNull(methodNodes); Validate.notNull(paramTypes); Validate.noNullElements(methodNodes); Validate.noNullElements(paramTypes); for (Type paramType : paramTypes) { Validate.isTrue(paramType.getSort() != Type.METHOD && paramType.getSort() != Type.VOID); } List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNode : methodNodes) { Type methodDescType = Type.getType(methodNode.desc); Type[] methodParamTypes = methodDescType.getArgumentTypes(); if (methodParamTypes.length != paramTypes.length) { continue; } boolean found = true; for (int i = 0; i < methodParamTypes.length; i++) { if (!paramTypes[i].equals(methodParamTypes[i])) { found = false; } } if (found) { ret.add(methodNode); } } return ret; } }
SearchUtils { public static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes) { Validate.notNull(methodNodes); Validate.notNull(paramTypes); Validate.noNullElements(methodNodes); Validate.noNullElements(paramTypes); for (Type paramType : paramTypes) { Validate.isTrue(paramType.getSort() != Type.METHOD && paramType.getSort() != Type.VOID); } List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNode : methodNodes) { Type methodDescType = Type.getType(methodNode.desc); Type[] methodParamTypes = methodDescType.getArgumentTypes(); if (methodParamTypes.length != paramTypes.length) { continue; } boolean found = true; for (int i = 0; i < methodParamTypes.length; i++) { if (!paramTypes[i].equals(methodParamTypes[i])) { found = false; } } if (found) { ret.add(methodNode); } } return ret; } private  SearchUtils(); }
SearchUtils { public static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes) { Validate.notNull(methodNodes); Validate.notNull(paramTypes); Validate.noNullElements(methodNodes); Validate.noNullElements(paramTypes); for (Type paramType : paramTypes) { Validate.isTrue(paramType.getSort() != Type.METHOD && paramType.getSort() != Type.VOID); } List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNode : methodNodes) { Type methodDescType = Type.getType(methodNode.desc); Type[] methodParamTypes = methodDescType.getArgumentTypes(); if (methodParamTypes.length != paramTypes.length) { continue; } boolean found = true; for (int i = 0; i < methodParamTypes.length; i++) { if (!paramTypes[i].equals(methodParamTypes[i])) { found = false; } } if (found) { ret.add(methodNode); } } return ret; } private  SearchUtils(); static List<MethodNode> findMethodsWithName(Collection<MethodNode> methodNodes, String name); static List<MethodNode> findStaticMethods(Collection<MethodNode> methodNodes); static List<MethodNode> findMethodsWithParameter(Collection<MethodNode> methodNodes, Type expectedParamType); static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes); static MethodNode findMethod(Collection<MethodNode> methodNodes, boolean isStatic, Type returnType, String name,
            Type ... paramTypes); static List<AbstractInsnNode> findInvocationsOf(InsnList insnList, Method expectedMethod); static List<AbstractInsnNode> findInvocationsWithParameter(InsnList insnList,
            Type expectedParamType); static List<AbstractInsnNode> searchForOpcodes(InsnList insnList, int ... opcodes); static List<TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction(InsnList insnList,
            List<TryCatchBlockNode> tryCatchBlockNodes, AbstractInsnNode insnNode); static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode); static LocalVariableNode findLocalVariableNodeForInstruction(List<LocalVariableNode> lvnList, InsnList insnList,
            final AbstractInsnNode insnNode, int idx); static FieldNode findField(ClassNode classNode, String name); }
SearchUtils { public static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes) { Validate.notNull(methodNodes); Validate.notNull(paramTypes); Validate.noNullElements(methodNodes); Validate.noNullElements(paramTypes); for (Type paramType : paramTypes) { Validate.isTrue(paramType.getSort() != Type.METHOD && paramType.getSort() != Type.VOID); } List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNode : methodNodes) { Type methodDescType = Type.getType(methodNode.desc); Type[] methodParamTypes = methodDescType.getArgumentTypes(); if (methodParamTypes.length != paramTypes.length) { continue; } boolean found = true; for (int i = 0; i < methodParamTypes.length; i++) { if (!paramTypes[i].equals(methodParamTypes[i])) { found = false; } } if (found) { ret.add(methodNode); } } return ret; } private  SearchUtils(); static List<MethodNode> findMethodsWithName(Collection<MethodNode> methodNodes, String name); static List<MethodNode> findStaticMethods(Collection<MethodNode> methodNodes); static List<MethodNode> findMethodsWithParameter(Collection<MethodNode> methodNodes, Type expectedParamType); static List<MethodNode> findMethodsWithParameters(Collection<MethodNode> methodNodes, Type ... paramTypes); static MethodNode findMethod(Collection<MethodNode> methodNodes, boolean isStatic, Type returnType, String name,
            Type ... paramTypes); static List<AbstractInsnNode> findInvocationsOf(InsnList insnList, Method expectedMethod); static List<AbstractInsnNode> findInvocationsWithParameter(InsnList insnList,
            Type expectedParamType); static List<AbstractInsnNode> searchForOpcodes(InsnList insnList, int ... opcodes); static List<TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction(InsnList insnList,
            List<TryCatchBlockNode> tryCatchBlockNodes, AbstractInsnNode insnNode); static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode); static LocalVariableNode findLocalVariableNodeForInstruction(List<LocalVariableNode> lvnList, InsnList insnList,
            final AbstractInsnNode insnNode, int idx); static FieldNode findField(ClassNode classNode, String name);  }