use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration 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.resolution.declarations.ResolvedTypeDeclaration 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());
}
use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration in project javaparser by javaparser.
the class MethodContextResolutionTest method solveTypeRefToLocalClass.
@Test
public void solveTypeRefToLocalClass() {
CompilationUnit cu = parseSample("MethodWithTypes");
ClassOrInterfaceDeclaration cd = Navigator.demandClass(cu, "Main");
MethodDeclaration md = Navigator.demandMethod(cd, "methodWithLocalTypes");
Context context = new MethodContext(md, typeSolver);
SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("LocalClass", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
}
Aggregations