use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class FieldsResolutionTest method accessClassFieldThroughThisWithCompetingSymbolInParentContext.
@Test
public void accessClassFieldThroughThisWithCompetingSymbolInParentContext() {
CompilationUnit cu = parseSample("AccessClassMemberThroughThis");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessClassMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(clazz, "setLabel");
ExpressionStmt expressionStmt = (ExpressionStmt) method.getBody().get().getStatements().get(0);
AssignExpr assignExpr = (AssignExpr) expressionStmt.getExpression();
FieldAccessExpr fieldAccessExpr = (FieldAccessExpr) assignExpr.getTarget();
File src = adaptPath(new File("src/test/resources"));
CombinedTypeSolver typeSolver = new CombinedTypeSolver(new JavaParserTypeSolver(src), new ReflectionTypeSolver());
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> ref = symbolSolver.solveSymbol(fieldAccessExpr.getName().getId(), fieldAccessExpr);
assertTrue(ref.isSolved());
assertTrue(ref.getCorrespondingDeclaration().isField());
}
use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class GenericsResolutionTest method resolveUsageOfGenericFieldSimpleCase.
@Test
public void resolveUsageOfGenericFieldSimpleCase() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo1");
ExpressionStmt stmt = (ExpressionStmt) method.getBody().get().getStatements().get(0);
Expression expression = stmt.getExpression();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals(false, type.isTypeVariable());
assertEquals("java.lang.String", type.describe());
}
Aggregations