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

[BUG] Inner interface cannot be correctly parsed #220

Open
shuaiwang516 opened this issue Nov 6, 2024 · 1 comment
Open

[BUG] Inner interface cannot be correctly parsed #220

shuaiwang516 opened this issue Nov 6, 2024 · 1 comment

Comments

@shuaiwang516
Copy link

shuaiwang516 commented Nov 6, 2024

Consider the following interface file demoInterface.java, there is a inner interface called AnotherInterface.

package org.example;

public interface demoInterface {
    interface AnotherInterface {
        void anotherMethod();
        void anotherMethod2();
        void anotherMethod3();
    }
}

Now a class implements the above interface as below:

package org.example;

public class demoTest implements demoInterface {
    public AnotherInterface fakeMethod() {
        return null;
    }
}

When QDox parses the fakeMethod(), it cannot correctly get the method infomration.
The parsing code is:

JavaProjectBuilder builder = new JavaProjectBuilder();
builder.addSourceTree(${path_to_org_example_package});
JavaClass javaClass = builder.getClassByName("org.example.demoTest");
// iterate all the methods
for (JavaMethod method : javaClass.getMethods()) {
    JavaClass returnClass = method.getReturns();
    if (returnClass != null) {
        System.out.println("Class: " + returnClass.getFullyQualifiedName());
        System.out.println("Method: " + method.getName() + " returns: " + returnClass.getFullyQualifiedName());
        System.out.println(returnClass.getMethods());
    }
}

You will see the output:

Class: AnotherInterface
Method: fakeMethod returns: AnotherInterface
[]

The expected output should be:

Class: org.example.demoInterface.AnotherInterface
Method: fakeMethod returns: org.example.demoInterface.AnotherInterface
[public void anotherMethod(), public void anotherMethod2(), public void anotherMethod3()]
@shuaiwang516
Copy link
Author

I found that the issue only happens if the target class implements the interface.

So the below code works:

package org.example;

public class demoTest {
    public demoInterface.AnotherInterface fakeMethod() {
        return null;
    }
}

But this code does not work:

package org.example;

public class demoTest implements demoInterface {
    public AnotherInterface fakeMethod() {
        return null;
    }
}

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