@Test public void testGetAllAncestorsWithoutTypeParameters() { JavaParserClassDeclaration cu = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); assertEquals(ImmutableSet.of("java.lang.Cloneable", "com.github.javaparser.ast.Node", "java.lang.Object"), cu.getAllAncestors().stream().map(i -> i.getQualifiedName()).collect(Collectors.toSet())); }
@Test public void testGetAllAncestorsWithTypeParameters() { JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); assertEquals(12, constructorDeclaration.getAllAncestors().size()); ancestor = constructorDeclaration.getAllAncestors().get(0); assertEquals("com.github.javaparser.ast.body.BodyDeclaration", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.body.BodyDeclaration.T").get().asReferenceType().getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(1); assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(2); assertEquals("java.lang.Cloneable", ancestor.getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(3); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(4); assertEquals("java.lang.Object", ancestor.getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(5); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", ancestor.getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(6); assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithDeclaration", ancestor.getQualifiedName()); ancestor = constructorDeclaration.getAllAncestors().get(7);