Skip to content

Commit

Permalink
Fixes forge#223 - tries to resolve classes in current package before …
Browse files Browse the repository at this point in the history
…looking into wildcard import , uses a new mechanism - ParsingContext , resolving java.lang according to actual order
  • Loading branch information
asaf-wizzdi committed Dec 25, 2021
1 parent d5632f6 commit 1b93944
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,7 @@ public String resolveType(final String type)
return result;
}

// java lang types are implicitly imported and we don't allow a duplicate simple name in another package
if (Types.isJavaLang(result))
{
return "java.lang." + result;
}


List<Import> imports = getImports(); // fetch imports only once

Expand All @@ -447,6 +443,11 @@ public String resolveType(final String type)
return className;
}
}
// java lang types are implicitly imported after package and explicit imports
if (Types.isJavaLang(result))
{
return "java.lang." + result;
}

// if we have no imports and no fqn name the following doesn't need to be executed
if (!imports.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ClassLoaderWildcardImportResolverTest
{
private static JavaClassSource javaClass;
private static JavaClassSource second;
private static JavaClassSource third;


@BeforeAll
Expand All @@ -41,6 +42,11 @@ public static void reset() throws IOException
{
second = parsingContext.parse(JavaClassSource.class, stream);
}
fileName = "/org/jboss/forge/grammar/java/Object.java";
try (InputStream stream = ClassLoaderWildcardImportResolverTest.class.getResourceAsStream(fileName))
{
third = parsingContext.parse(JavaClassSource.class, stream);
}


}
Expand All @@ -50,6 +56,8 @@ public void testType()
{
Assertions.assertEquals(List.class.getCanonicalName(),javaClass.getMethod("getList").getReturnType().getQualifiedName());
Assertions.assertEquals("org.jboss.forge.grammar.java.HttpRequest",javaClass.getMethod("getHttpRequest").getReturnType().getQualifiedName());
Assertions.assertEquals("org.jboss.forge.grammar.java.Object",javaClass.getMethod("getObject").getReturnType().getQualifiedName());


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public List<String> getList(){
public HttpRequest getHttpRequest(){
return new HttpRequest();
}
public Object getObject(){
return new Object();
}
}
17 changes: 17 additions & 0 deletions tests/src/test/resources/org/jboss/forge/grammar/java/Object.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jboss.forge.grammar.java;


public class Object {

private String fakeField;


public String getFakeField() {
return fakeField;
}

public <T extends Object> T setFakeField(String fakeField) {
this.fakeField = fakeField;
return (T) this;
}
}

0 comments on commit 1b93944

Please sign in to comment.