Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I try to call a generic method, an exception is thrown directly in MethodCall#getMethod(). #497

Open
p-moon opened this issue Dec 11, 2024 · 1 comment

Comments

@p-moon
Copy link

p-moon commented Dec 11, 2024

What should I do? When I try to call a generic method, an exception is thrown directly in MethodCall#getMethod().

    private void analyzeMethodCalls(String className, CtMethod method) throws NotFoundException, CannotCompileException {
        method.instrument(new ExprEditor() {
            @Override
            public void edit(MethodCall m) throws CannotCompileException {
                String runMethodName = method.getName();
                String runClassName = method.getDeclaringClass().getName();
                String callClassName = m.getClassName();
                String callMethodName = m.getMethodName();
                String fileName = m.getFileName();
                Integer lineNumber = m.getLineNumber();
                try {
// TODO: Let's compare here. The generic function calls m.getMethod() and directly throws an exception.   
                    CtMethod calledMethod = m.getMethod();
                    CtClass callCtClass = calledMethod.getDeclaringClass();
                    if (!scanPackagePrefix.stream().allMatch(runClassName::startsWith)) {
                        return;
                    }
                    if (callCtClass.isInterface()) { // 打印每个接口的执行结果
                        if (interfaceImplMap.containsKey(callCtClass)) {
                            for (CtClass callImplClass : interfaceImplMap.get(callCtClass)) {
                                CtMethod overrideMethod = callImplClass.getDeclaredMethod(calledMethod.getName(), calledMethod.getParameterTypes());
                                analyzeMethodCalls(callImplClass.getName(), seekImplInterfaceMethod(overrideMethod));
                            }
                        }
                    }
@p-moon
Copy link
Author

p-moon commented Dec 11, 2024

For example, the save method in mybatis-plus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant