-
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.
Merge pull request #2956 from jlerbsc/master
Fix issue 2781 resolve Stack overflow occurs when the name of the interface implemented by the class is the same as the name of the internal class
- Loading branch information
Showing
3 changed files
with
60 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
52 changes: 52 additions & 0 deletions
52
...symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2781Test.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,52 @@ | ||
package com.github.javaparser.symbolsolver; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.github.javaparser.StaticJavaParser; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.body.ConstructorDeclaration; | ||
import com.github.javaparser.ast.expr.MethodCallExpr; | ||
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; | ||
import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; | ||
|
||
public class Issue2781Test extends AbstractResolutionTest { | ||
|
||
@Test() | ||
void test() throws FileNotFoundException { | ||
|
||
String code = | ||
"public class A implements AnInterface {\n" + | ||
" private AnInterface field;\n" + | ||
"\n" + | ||
" protected AnInterface getContainer() {\n" + | ||
" return this.field;\n" + | ||
" }\n" + | ||
" protected static class AnInterface {\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver(); | ||
combinedTypeSolver.add(new ReflectionTypeSolver()); | ||
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath("src/test/resources"))); | ||
StaticJavaParser.getConfiguration().setSymbolResolver(new JavaSymbolSolver(combinedTypeSolver)); | ||
|
||
CompilationUnit cu = StaticJavaParser.parse(code); | ||
List<ConstructorDeclaration> constructorDeclarations = cu.findAll(ConstructorDeclaration.class); | ||
constructorDeclarations.forEach(constructorDeclaration -> { | ||
constructorDeclaration.findAll(MethodCallExpr.class).forEach(methodCallExpr -> { | ||
//Exception in thread "main" java.lang.StackOverflowError | ||
ResolvedMethodDeclaration rmd = methodCallExpr.resolve(); | ||
System.out.println(rmd.getQualifiedName()); | ||
}); | ||
}); | ||
|
||
|
||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
javaparser-symbol-solver-testing/src/test/resources/AnInterface.java.txt
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,2 @@ | ||
public interface AnInterface { | ||
} |