]
George Gastaldi updated FORGE-471:
----------------------------------
Fix Version/s: 2.x Future
(was: 1.x Future)
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
Security Level: Public(Everyone can see)
Components: Parsers / File Manipulation, Resources
Affects Versions: 1.0.6.Final
Reporter: Rudy De Busscher
Fix For: 2.x Future
In the case you have following java source file
{code:java}
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");
}
}
}
{code}
And running following statements
{code:java}
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());
}
{code}
You get the following output
{code}
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
{code}
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.