[forge-issues] [JBoss JIRA] (FORGE-471) JavaResource handling of files with nested classes is incorrect

Rudy De Busscher (JIRA) jira-events at lists.jboss.org
Wed Feb 1 07:01:48 EST 2012


Rudy De Busscher created FORGE-471:
--------------------------------------

             Summary: JavaResource handling of files with nested classes is incorrect
                 Key: FORGE-471
                 URL: https://issues.jboss.org/browse/FORGE-471
             Project: Forge
          Issue Type: Bug
          Components: Parsers / File Manipulation, Resources API
    Affects Versions: 1.0.0.Beta5
            Reporter: Rudy De Busscher


In the case you have following java source file

public class Test {
    
    private String mainProperty;

    public void mainMethod() {
        System.out.println("Hi");
    }

    public static final class Nested {

        private String innerProperty;

        public void innerMethod() {
            System.out.println("I'm inner");
        }
    }
}

And running following statements
        JavaResource javaResource = factory.getResourceFrom(new File"/path/to/file/Test.java")).reify(JavaResource.class);
        System.out.println(javaResource.toString());
        List<Resource<?>> resources = javaResource.listResources();
        for (Resource res : resources) {
            System.out.println(res.getFullyQualifiedName());
        }

You get following output
     be.rubus.forge.deltaspike.test.projectstage.Nested
     /path/to/file/Test.java/innerProperty::String
     /path/to/file/Test.java/mainMethod()::void
     /path/to/file/Test.java/innerMethod()::void


The wrong name is due to the fact that TypeDeclarationFinderVisitor records every class type the parser finds.  In our case the 2 class names but only the last one is kept (first name is overwritten)

The MethodFinderVisitor has a similar problem, it gets called twice and adds up the found methods.

So there need to be a general review of the visitors to be able to handle nested or multiple classes in one java source file.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the forge-issues mailing list