use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method getParent.
@Test
public void getParent() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
Context context = new CompilationUnitContext(cu, typeSolver);
assertTrue(null == context.getParent());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveSymbolAsValueReferringToStaticField.
@Test
public void solveSymbolAsValueReferringToStaticField() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitSymbols");
Context context = new CompilationUnitContext(cu, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("java.lang.System.out", new ReflectionTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("java.io.PrintStream", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveUnexistingGenericType.
@Test
public void solveUnexistingGenericType() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
Context context = new CompilationUnitContext(cu, typeSolver);
Optional<ResolvedType> d = context.solveGenericType("D", new MemoryTypeSolver());
assertEquals(false, d.isPresent());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredInstanceField.
@Test
public void solveSymbolAsValueReferringToDeclaredInstanceField() {
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("i", new MemoryTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("int", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.core.resolution.Context in project javaparser by javaparser.
the class LambdaExprContextResolutionTest method solveParameterOfLambdaInFieldDecl.
@Test
public void solveParameterOfLambdaInFieldDecl() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
VariableDeclarator field = Navigator.demandField(clazz, "functional");
LambdaExpr lambdaExpr = (LambdaExpr) field.getInitializer().get();
File src = new File("src/test/resources");
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(src)));
Context context = new LambdaExprContext(lambdaExpr, combinedTypeSolver);
Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
assertTrue(ref.isPresent());
assertEquals("java.lang.String", ref.get().getType().describe());
}
Aggregations