use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveMethodStaticallyImportedWithAsterisk.
@Test
public void solveMethodStaticallyImportedWithAsterisk() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitWithImports");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
typeSolver.add(new ReflectionTypeSolver());
SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("assertFalse", ImmutableList.of(ResolvedPrimitiveType.BOOLEAN), false, typeSolver);
assertEquals(true, ref.isSolved());
assertEquals("assertFalse", ref.getCorrespondingDeclaration().getName());
assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams());
assertEquals("boolean", ref.getCorrespondingDeclaration().getParam(0).getType().describe());
assertEquals(true, ref.getCorrespondingDeclaration().getParam(0).getType().isPrimitive());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveExistingGenericType.
@Test
public void solveExistingGenericType() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
Context context = new CompilationUnitContext(cu, typeSolver);
Optional<ResolvedType> a = context.solveGenericType("A", new MemoryTypeSolver());
Optional<ResolvedType> b = context.solveGenericType("B", new MemoryTypeSolver());
Optional<ResolvedType> c = context.solveGenericType("C", new MemoryTypeSolver());
assertEquals(false, a.isPresent());
assertEquals(false, b.isPresent());
assertEquals(false, c.isPresent());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveMethodStaticallyImportedWithoutAsterisk.
@Test
public void solveMethodStaticallyImportedWithoutAsterisk() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitSymbols");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
typeSolver.add(new ReflectionTypeSolver());
SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("assertEquals", ImmutableList.of(NullType.INSTANCE, NullType.INSTANCE), false, typeSolver);
assertEquals(true, ref.isSolved());
assertEquals("assertEquals", ref.getCorrespondingDeclaration().getName());
assertEquals(2, ref.getCorrespondingDeclaration().getNumberOfParams());
assertEquals("java.lang.Object", ref.getCorrespondingDeclaration().getParam(0).getType().asReferenceType().getQualifiedName());
assertEquals("java.lang.Object", ref.getCorrespondingDeclaration().getParam(1).getType().asReferenceType().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveSymbolReferringToStaticallyImportedUsingAsteriskValue.
@Test
public void solveSymbolReferringToStaticallyImportedUsingAsteriskValue() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitSymbols");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("err", typeSolver);
assertEquals(true, ref.isSolved());
assertEquals("java.io.PrintStream", ref.getCorrespondingDeclaration().getType().asReferenceType().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveSymbolAsValueReferringToStaticallyImportedValue.
@Test
public void solveSymbolAsValueReferringToStaticallyImportedValue() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitSymbols");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
Optional<Value> ref = context.solveSymbolAsValue("out", typeSolver);
assertEquals(true, ref.isPresent());
assertEquals("java.io.PrintStream", ref.get().getType().describe());
}
Aggregations