Search in sources :

Example 1 with QualifiableNode

use of net.sourceforge.pmd.lang.ast.QualifiableNode in project pmd by pmd.

the class ClassTypeResolver method visit.

@Override
public Object visit(ASTClassOrInterfaceType node, Object data) {
    super.visit(node, data);
    String typeName = node.getImage();
    if (node.isAnonymousClass()) {
        QualifiableNode parent = node.getFirstParentOfAnyType(ASTAllocationExpression.class, ASTEnumConstant.class);
        if (parent != null) {
            typeName = parent.getQualifiedName().toString();
        }
    }
    populateType(node, typeName, node.getArrayDepth());
    ASTTypeArguments typeArguments = node.getFirstChildOfType(ASTTypeArguments.class);
    if (typeArguments != null) {
        final JavaTypeDefinition[] boundGenerics = new JavaTypeDefinition[typeArguments.jjtGetNumChildren()];
        for (int i = 0; i < typeArguments.jjtGetNumChildren(); ++i) {
            boundGenerics[i] = ((TypeNode) typeArguments.jjtGetChild(i)).getTypeDefinition();
        }
        node.setTypeDefinition(JavaTypeDefinition.forClass(node.getType(), boundGenerics));
    }
    return data;
}
Also used : ASTTypeArguments(net.sourceforge.pmd.lang.java.ast.ASTTypeArguments) JavaTypeDefinition(net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition) QualifiableNode(net.sourceforge.pmd.lang.ast.QualifiableNode)

Aggregations

QualifiableNode (net.sourceforge.pmd.lang.ast.QualifiableNode)1 ASTTypeArguments (net.sourceforge.pmd.lang.java.ast.ASTTypeArguments)1 JavaTypeDefinition (net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition)1