use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method getParentForTopClass.
@Test
public void getParentForTopClass() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
assertFalse(null == context.getParent());
assertEquals(new CompilationUnitContext(cu, typeSolver), context.getParent());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveSymbolReferringToStaticallyImportedValue.
@Test
public void solveSymbolReferringToStaticallyImportedValue() 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("out", 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 solveSymbolAsValueReferringToStaticallyImportedUsingAsteriskValue.
@Test
public void solveSymbolAsValueReferringToStaticallyImportedUsingAsteriskValue() 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("err", typeSolver);
assertEquals(true, ref.isPresent());
assertEquals("java.io.PrintStream", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveTypeInSamePackage.
@Test
public void solveTypeInSamePackage() {
CompilationUnit cu = parseSample("CompilationUnitWithImports");
Context context = new CompilationUnitContext(cu, typeSolver);
ResolvedReferenceTypeDeclaration otherClass = mock(ResolvedReferenceTypeDeclaration.class);
when(otherClass.getQualifiedName()).thenReturn("com.foo.OtherClassInSamePackage");
MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
memoryTypeSolver.addDeclaration("com.foo.OtherClassInSamePackage", otherClass);
SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("OtherClassInSamePackage", memoryTypeSolver);
assertEquals(true, ref.isSolved());
assertEquals("com.foo.OtherClassInSamePackage", ref.getCorrespondingDeclaration().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveTypeNotImported.
@Test
public void solveTypeNotImported() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitWithImports");
Context context = new CompilationUnitContext(cu, typeSolver);
SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("org.junit.Assume", new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
assertEquals(true, ref.isSolved());
assertEquals("org.junit.Assume", ref.getCorrespondingDeclaration().getQualifiedName());
}
Aggregations