Source:
static Optional<MethodUsage> getMethodUsage(CtClass ctClass, String name, List<Type> argumentsTypes, TypeSolver typeSolver, Context invokationContext) { for (CtMethod method : ctClass.getDeclaredMethods()) { if (method.getName().equals(name)) { MethodUsage methodUsage = new MethodUsage(new JavassistMethodDeclaration(method, typeSolver)); if (argumentsTypes.size() < methodUsage.getNoParams()) { continue; } try { if (method.getGenericSignature() != null) { SignatureAttribute.MethodSignature classSignature = SignatureAttribute.toMethodSignature(method.getGenericSignature()); List<Type> parametersOfReturnType = parseTypeParameters(classSignature.getReturnType().toString(), typeSolver, invokationContext); Type newReturnType = methodUsage.returnType(); if (newReturnType instanceof ReferenceType && parametersOfReturnType.size() > 0) { newReturnType = newReturnType.asReferenceType().transformTypeParameters(tp -> parametersOfReturnType.remove(0)); } methodUsage = methodUsage.replaceReturnType(newReturnType); } return Optional.of(methodUsage); } catch (BadBytecode e) { throw new RuntimeException(e); } } } try { CtClass superClass = ctClass.getSuperclass(); if (superClass != null) { Optional<MethodUsage> ref = new JavassistClassDeclaration(superClass, typeSolver).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, null); if (ref.isPresent()) { return ref; } } } catch (NotFoundException e) { throw new RuntimeException(e); } try { for (CtClass interfaze : ctClass.getInterfaces()) { Optional<MethodUsage> ref = new JavassistInterfaceDeclaration(interfaze, typeSolver).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, null); if (ref.isPresent()) { return ref; } } } catch (NotFoundException e) { throw new RuntimeException(e); } return Optional.empty(); }

Target:
static Optional<MethodUsage> getMethodUsage(CtClass ctClass, String name, List<Type> argumentsTypes, TypeSolver typeSolver, Context invokationContext) { for (CtMethod method : ctClass.getDeclaredMethods()) { if (method.getName().equals(name)) { MethodUsage methodUsage = new MethodUsage(new JavassistMethodDeclaration(method, typeSolver)); if (argumentsTypes.size() < methodUsage.getNoParams()) { continue; } try { if (method.getGenericSignature() != null) { SignatureAttribute.MethodSignature classSignature = SignatureAttribute.toMethodSignature(method.getGenericSignature()); List<Type> parametersOfReturnType = parseTypeParameters(classSignature.getReturnType().toString(), typeSolver, invokationContext); Type newReturnType = methodUsage.returnType(); if (newReturnType.isReferenceType() && parametersOfReturnType.size() > 0) { newReturnType = newReturnType.asReferenceType().transformTypeParameters(tp -> parametersOfReturnType.remove(0)); } methodUsage = methodUsage.replaceReturnType(newReturnType); } return Optional.of(methodUsage); } catch (BadBytecode e) { throw new RuntimeException(e); } } } try { CtClass superClass = ctClass.getSuperclass(); if (superClass != null) { Optional<MethodUsage> ref = new JavassistClassDeclaration(superClass, typeSolver).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, null); if (ref.isPresent()) { return ref; } } } catch (NotFoundException e) { throw new RuntimeException(e); } try { for (CtClass interfaze : ctClass.getInterfaces()) { Optional<MethodUsage> ref = new JavassistInterfaceDeclaration(interfaze, typeSolver).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, null); if (ref.isPresent()) { return ref; } } } catch (NotFoundException e) { throw new RuntimeException(e); } return Optional.empty(); }