use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolReferringToDeclaredInstanceField.
@Test
public void solveSymbolReferringToDeclaredInstanceField() {
CompilationUnit cu = parseSample("AnEnum");
com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("i", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
assertEquals("int", ref.getCorrespondingDeclaration().getType().describe());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolReferringToDeclaredStaticField.
@Test
public void solveSymbolReferringToDeclaredStaticField() {
CompilationUnit cu = parseSample("AnEnum");
com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("j", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
assertEquals("long", ref.getCorrespondingDeclaration().getType().describe());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredStaticField.
@Test
public void solveSymbolAsValueReferringToDeclaredStaticField() {
CompilationUnit cu = parseSample("AnEnum");
com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("j", new MemoryTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("long", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolReferringToValue.
@Test
public void solveSymbolReferringToValue() {
CompilationUnit cu = parseSample("AnEnum");
com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("E1", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
assertEquals("MyEnum", ref.getCorrespondingDeclaration().getType().describe());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class LambdaExprContextResolutionTest method solveParameterOfLambdaInMethodCallExpr.
@Test
public void solveParameterOfLambdaInMethodCallExpr() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaMap");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
MethodCallExpr methodCallExpr = (MethodCallExpr) returnStmt.getExpression().get();
LambdaExpr lambdaExpr = (LambdaExpr) methodCallExpr.getArguments().get(0);
Context context = new LambdaExprContext(lambdaExpr, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
assertTrue(ref.isPresent());
assertEquals("? super java.lang.String", ref.get().getType().describe());
}
Aggregations