Search in sources :

Example 1 with NodeWithTypeParameters

use of com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters in project javaparser by javaparser.

the class JavaParserTypeAdapter method solveType.

public SymbolReference<ResolvedTypeDeclaration> solveType(String name, TypeSolver typeSolver) {
    if (wrappedNode instanceof NodeWithTypeParameters<?>) {
        NodeList<TypeParameter> typeParameters = ((NodeWithTypeParameters<?>) wrappedNode).getTypeParameters();
        for (com.github.javaparser.ast.type.TypeParameter typeParameter : typeParameters) {
            if (typeParameter.getName().getId().equals(name)) {
                return SymbolReference.solved(new JavaParserTypeVariableDeclaration(typeParameter, typeSolver));
            }
        }
    }
    // Internal classes
    for (BodyDeclaration<?> member : this.wrappedNode.getMembers()) {
        if (member instanceof com.github.javaparser.ast.body.TypeDeclaration) {
            com.github.javaparser.ast.body.TypeDeclaration<?> internalType = (com.github.javaparser.ast.body.TypeDeclaration<?>) member;
            String prefix = internalType.getName() + ".";
            if (internalType.getName().getId().equals(name)) {
                if (internalType instanceof ClassOrInterfaceDeclaration) {
                    return SymbolReference.solved(new JavaParserClassDeclaration((com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) internalType, typeSolver));
                } else if (internalType instanceof EnumDeclaration) {
                    return SymbolReference.solved(new JavaParserEnumDeclaration((com.github.javaparser.ast.body.EnumDeclaration) internalType, typeSolver));
                } else {
                    throw new UnsupportedOperationException();
                }
            } else if (name.startsWith(prefix) && name.length() > prefix.length()) {
                if (internalType instanceof ClassOrInterfaceDeclaration) {
                    return new JavaParserClassDeclaration((com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) internalType, typeSolver).solveType(name.substring(prefix.length()), typeSolver);
                } else if (internalType instanceof EnumDeclaration) {
                    return new SymbolSolver(typeSolver).solveTypeInType(new JavaParserEnumDeclaration((com.github.javaparser.ast.body.EnumDeclaration) internalType, typeSolver), name.substring(prefix.length()));
                } else {
                    throw new UnsupportedOperationException();
                }
            }
        }
    }
    return SymbolReference.unsolved(ResolvedTypeDeclaration.class);
}
Also used : NodeWithTypeParameters(com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters) TypeParameter(com.github.javaparser.ast.type.TypeParameter) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) TypeParameter(com.github.javaparser.ast.type.TypeParameter) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration) SymbolSolver(com.github.javaparser.symbolsolver.resolution.SymbolSolver) ResolvedTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)

Aggregations

ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 NodeWithTypeParameters (com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters)1 TypeParameter (com.github.javaparser.ast.type.TypeParameter)1 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)1 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)1 SymbolSolver (com.github.javaparser.symbolsolver.resolution.SymbolSolver)1