-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issue 4358 prevent infinite cycles with static imports
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4358Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.javaparser.symbolsolver; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.github.javaparser.ParserConfiguration; | ||
import com.github.javaparser.StaticJavaParser; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.expr.MethodCallExpr; | ||
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class Issue4358Test extends AbstractSymbolResolutionTest { | ||
@Test | ||
public void testIssue4358() throws IOException { | ||
Path issueResourcesPath = adaptPath("src/test/resources/issue4358"); | ||
ReflectionTypeSolver rts = new ReflectionTypeSolver(); | ||
JavaParserTypeSolver jpts = new JavaParserTypeSolver(issueResourcesPath); | ||
CombinedTypeSolver cts = new CombinedTypeSolver(); | ||
cts.add(rts); | ||
cts.add(jpts); | ||
ParserConfiguration pc = new ParserConfiguration() | ||
.setSymbolResolver(new JavaSymbolSolver(cts)); | ||
StaticJavaParser.setConfiguration(pc); | ||
CompilationUnit cu = StaticJavaParser.parse(issueResourcesPath.resolve("foo/A.java")); | ||
|
||
// There's only one method call in this compilation unit | ||
ResolvedMethodDeclaration actual = cu.findAll(MethodCallExpr.class).stream() | ||
.map(MethodCallExpr::resolve) | ||
.findAny().get(); | ||
|
||
assertEquals("foo.B.d()", actual.getQualifiedSignature()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/A.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package foo; | ||
|
||
import static foo.B.d; | ||
|
||
class A { | ||
void c() { | ||
d(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
javaparser-symbol-solver-testing/src/test/resources/issue4358/foo/B.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package foo; | ||
|
||
class B extends A { | ||
static void d() { | ||
} | ||
} |