-
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.
Add test case for issue 2132 Variables declared outside of a nested B…
…lockStmt are not resolved
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue2132Test.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,41 @@ | ||
package com.github.javaparser.symbolsolver; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
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.symbolsolver.model.resolution.TypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; | ||
|
||
|
||
public class Issue2132Test extends AbstractSymbolResolutionTest { | ||
|
||
@Test | ||
public void test() { | ||
|
||
TypeSolver typeSolver = new ReflectionTypeSolver(); | ||
ParserConfiguration config = new ParserConfiguration(); | ||
config.setSymbolResolver(new JavaSymbolSolver(typeSolver)); | ||
StaticJavaParser.setConfiguration(config); | ||
|
||
String s = | ||
"class A {\n" + | ||
" void method() {\n" + | ||
" String s = \"\";\n" + | ||
" {\n" + | ||
" s.length();\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
CompilationUnit cu = StaticJavaParser.parse(s); | ||
MethodCallExpr mce = cu.findFirst(MethodCallExpr.class).get(); | ||
assertEquals("int", mce.calculateResolvedType().describe()); | ||
assertEquals("java.lang.String.length", mce.resolve().getQualifiedName()); | ||
assertEquals("java.lang.String", mce.getScope().get().calculateResolvedType().describe()); | ||
} | ||
|
||
} |