Skip to content

Commit

Permalink
Add test case for issue 2132 Variables declared outside of a nested B…
Browse files Browse the repository at this point in the history
…lockStmt are not resolved
  • Loading branch information
jlerbsc committed Nov 3, 2020
1 parent a69b1b2 commit 82e8d9f
Showing 1 changed file with 41 additions and 0 deletions.
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());
}

}

0 comments on commit 82e8d9f

Please sign in to comment.