public List<ResolvedReferenceType> getAllAncestors() { // We need to go through the inheritance line and propagate the type parametes List<ResolvedReferenceType> ancestors = typeDeclaration.getAllAncestors(); ancestors = ancestors.stream() .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); // Avoid repetitions of Object ancestors.removeIf(a -> a.getQualifiedName().equals(Object.class.getCanonicalName())); ResolvedReferenceTypeDeclaration objectType = typeSolver.solveType(Object.class.getCanonicalName()); ResolvedReferenceType objectRef = create(objectType); ancestors.add(objectRef); return ancestors; }
public List<ResolvedReferenceType> getAllAncestors() { // We need to go through the inheritance line and propagate the type parametes List<ResolvedReferenceType> ancestors = typeDeclaration.getAllAncestors(); ancestors = ancestors.stream() .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); // Avoid repetitions of Object ancestors.removeIf(a -> a.getQualifiedName().equals(Object.class.getCanonicalName())); ResolvedReferenceTypeDeclaration objectType = typeSolver.solveType(Object.class.getCanonicalName()); ResolvedReferenceType objectRef = create(objectType); ancestors.add(objectRef); return ancestors; }
public List<ResolvedReferenceType> getAllAncestors() { // We need to go through the inheritance line and propagate the type parametes List<ResolvedReferenceType> ancestors = typeDeclaration.getAllAncestors(); ancestors = ancestors.stream() .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); // Avoid repetitions of Object ancestors.removeIf(a -> a.getQualifiedName().equals(Object.class.getCanonicalName())); ResolvedReferenceTypeDeclaration objectType = typeSolver.solveType(Object.class.getCanonicalName()); ResolvedReferenceType objectRef = create(objectType); ancestors.add(objectRef); return ancestors; }
public List<ResolvedReferenceType> getDirectAncestors() { // We need to go through the inheritance line and propagate the type parametes List<ResolvedReferenceType> ancestors = typeDeclaration.getAncestors(); ancestors = ancestors.stream() .map(a -> typeParametersMap().replaceAll(a).asReferenceType()) .collect(Collectors.toList()); // Avoid repetitions of Object ancestors.removeIf(a -> a.getQualifiedName().equals(Object.class.getCanonicalName())); boolean isClassWithSuperClassOrObject = this.getTypeDeclaration().isClass() && (this.getTypeDeclaration().asClass().getSuperClass() == null || !this.getTypeDeclaration().asClass().getSuperClass().getQualifiedName().equals(Object.class.getCanonicalName())); if (!isClassWithSuperClassOrObject) { ResolvedReferenceTypeDeclaration objectType = typeSolver.solveType(Object.class.getCanonicalName()); ResolvedReferenceType objectRef = create(objectType); ancestors.add(objectRef); } return ancestors; }
@Test public void testGetSuperclassWithTypeParameters() { ReflectionClassDeclaration compilationUnit = (ReflectionClassDeclaration) typeResolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); assertEquals("com.github.javaparser.ast.body.CallableDeclaration", compilationUnit.getSuperClass().getQualifiedName()); assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", compilationUnit.getSuperClass().typeParametersMap().getValueBySignature("com.github.javaparser.ast.body.CallableDeclaration.T").get().asReferenceType().getQualifiedName()); }