-
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 #2133 from jjbr/inter-blockStmt-resolution
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...g/src/test/java/com/github/javaparser/symbolsolver/resolution/VariableResolutionTest.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,44 @@ | ||
package com.github.javaparser.symbolsolver.resolution; | ||
|
||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; | ||
import com.github.javaparser.ast.body.MethodDeclaration; | ||
import com.github.javaparser.ast.expr.MethodCallExpr; | ||
import com.github.javaparser.resolution.MethodUsage; | ||
import com.github.javaparser.symbolsolver.javaparser.Navigator; | ||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class VariableResolutionTest extends AbstractResolutionTest { | ||
|
||
@Test | ||
void variableResolutionNoBlockStmt() { | ||
// Test without nested block statement | ||
|
||
CompilationUnit cu = parseSample("VariableResolutionInVariousScopes"); | ||
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "VariableResolutionInVariousScopes"); | ||
|
||
MethodDeclaration method = Navigator.demandMethod(clazz, "noBlock"); | ||
MethodCallExpr callExpr = method.findFirst(MethodCallExpr.class).get(); | ||
MethodUsage methodUsage = JavaParserFacade.get(new ReflectionTypeSolver()).solveMethodAsUsage(callExpr); | ||
|
||
assertTrue(methodUsage.declaringType().getQualifiedName().equals("java.lang.String")); | ||
} | ||
|
||
@Test | ||
void variableResolutionWithBlockStmt() { | ||
// Test without nested block statement | ||
|
||
CompilationUnit cu = parseSample("VariableResolutionInVariousScopes"); | ||
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "VariableResolutionInVariousScopes"); | ||
|
||
MethodDeclaration method = Navigator.demandMethod(clazz, "withBlock"); | ||
MethodCallExpr callExpr = method.findFirst(MethodCallExpr.class).get(); | ||
MethodUsage methodUsage = JavaParserFacade.get(new ReflectionTypeSolver()).solveMethodAsUsage(callExpr); | ||
|
||
assertTrue(methodUsage.declaringType().getQualifiedName().equals("java.lang.String")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...arser-symbol-solver-testing/src/test/resources/VariableResolutionInVariousScopes.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,15 @@ | ||
package testcase; | ||
|
||
public class VariableResolutionInVariousScopes { | ||
public void withBlock() { | ||
String s = ""; | ||
{ | ||
s.length(); | ||
} | ||
} | ||
|
||
public void noBlock() { | ||
String s = ""; | ||
s.length(); | ||
} | ||
} |