Skip to content

[BUG] Inner interface cannot be correctly parsed #220

@shuaiwang516

Description

@shuaiwang516

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()]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions