Uploaded image for project: 'Forge'
  1. Forge
  2. FORGE-471

JavaResource handling of files with nested classes is incorrect

    Details

      Description

      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 the 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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                rdul064 Rudy De Busscher
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated: