Search in sources :

Example 36 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class JavassistInterfaceDeclaration method getAncestors.

@Override
public List<ResolvedReferenceType> getAncestors() {
    List<ResolvedReferenceType> ancestors = new ArrayList<>();
    try {
        for (CtClass interfaze : ctClass.getInterfaces()) {
            ResolvedReferenceType superInterfaze = JavassistFactory.typeUsageFor(interfaze, typeSolver).asReferenceType();
            ancestors.add(superInterfaze);
        }
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }
    ancestors = ancestors.stream().filter(a -> a.getQualifiedName() != Object.class.getCanonicalName()).collect(Collectors.toList());
    ancestors.add(new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver));
    return ancestors;
}
Also used : CtClass(javassist.CtClass) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) NotFoundException(javassist.NotFoundException)

Example 37 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class ReflectionClassAdapter method getAncestors.

public List<ResolvedReferenceType> getAncestors() {
    List<ResolvedReferenceType> ancestors = new LinkedList<>();
    if (getSuperClass() != null) {
        ReferenceTypeImpl superClass = getSuperClass();
        ancestors.add(superClass);
    } else {
        ReferenceTypeImpl object = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver);
        ancestors.add(object);
    }
    ancestors.addAll(getInterfaces());
    for (int i = 0; i < ancestors.size(); i++) {
        ResolvedReferenceType ancestor = ancestors.get(i);
        if (ancestor.hasName() && ancestor.getQualifiedName().equals(Object.class.getCanonicalName())) {
            ancestors.remove(i);
            i--;
        }
    }
    return ancestors;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)

Example 38 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class AbstractClassDeclaration method getAllInterfaces.

@Override
public final List<ResolvedReferenceType> getAllInterfaces() {
    List<ResolvedReferenceType> interfaces = new ArrayList<>();
    for (ResolvedReferenceType interfaceDeclaration : getInterfaces()) {
        interfaces.add(interfaceDeclaration);
        interfaces.addAll(interfaceDeclaration.getAllInterfacesAncestors());
    }
    ResolvedReferenceType superClass = this.getSuperClass();
    if (superClass != null) {
        interfaces.addAll(superClass.getAllInterfacesAncestors());
    }
    return interfaces;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) ArrayList(java.util.ArrayList)

Example 39 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class AbstractClassDeclaration method getAllSuperClasses.

@Override
public final List<ResolvedReferenceType> getAllSuperClasses() {
    List<ResolvedReferenceType> superclasses = new ArrayList<>();
    ResolvedReferenceType superClass = getSuperClass();
    if (superClass != null) {
        superclasses.add(superClass);
        superclasses.addAll(superClass.getAllClassesAncestors());
    }
    if (superclasses.removeIf(s -> s.getQualifiedName().equals(Object.class.getCanonicalName()))) {
        superclasses.add(object());
    }
    return superclasses;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) ArrayList(java.util.ArrayList)

Example 40 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class AbstractTypeDeclaration method getAllMethods.

@Override
public final Set<MethodUsage> getAllMethods() {
    Set<MethodUsage> methods = new HashSet<>();
    Set<String> methodsSignatures = new HashSet<>();
    for (ResolvedMethodDeclaration methodDeclaration : getDeclaredMethods()) {
        methods.add(new MethodUsage(methodDeclaration));
        methodsSignatures.add(methodDeclaration.getSignature());
    }
    for (ResolvedReferenceType ancestor : getAllAncestors()) {
        for (MethodUsage mu : ancestor.getDeclaredMethods()) {
            String signature = mu.getDeclaration().getSignature();
            if (!methodsSignatures.contains(signature)) {
                methodsSignatures.add(signature);
                methods.add(mu);
            }
        }
    }
    return methods;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) MethodUsage(com.github.javaparser.resolution.MethodUsage) HashSet(java.util.HashSet) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)

Aggregations

ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)55 Test (org.junit.Test)34 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)28 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)15 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)14 MethodUsage (com.github.javaparser.resolution.MethodUsage)9 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)9 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)8 Collectors (java.util.stream.Collectors)8 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ResolvedTypeVariable (com.github.javaparser.resolution.types.ResolvedTypeVariable)5 AccessSpecifier (com.github.javaparser.ast.AccessSpecifier)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4 JavaParserClassDeclaration (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration)4 SymbolReference (com.github.javaparser.symbolsolver.model.resolution.SymbolReference)4 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)4 ImmutableList (com.google.common.collect.ImmutableList)4 Before (org.junit.Before)4