Search in sources :

Example 1 with ASTTypeArguments

use of net.sourceforge.pmd.lang.java.ast.ASTTypeArguments 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)

Example 2 with ASTTypeArguments

use of net.sourceforge.pmd.lang.java.ast.ASTTypeArguments in project pmd by pmd.

the class MethodTypeResolution method getMethodExplicitTypeArugments.

public static List<JavaTypeDefinition> getMethodExplicitTypeArugments(Node node) {
    ASTMemberSelector memberSelector = node.getFirstChildOfType(ASTMemberSelector.class);
    if (memberSelector == null) {
        return Collections.emptyList();
    }
    ASTTypeArguments typeArguments = memberSelector.getFirstChildOfType(ASTTypeArguments.class);
    if (typeArguments == null) {
        return Collections.emptyList();
    }
    List<JavaTypeDefinition> result = new ArrayList<>();
    for (int childIndex = 0; childIndex < typeArguments.jjtGetNumChildren(); ++childIndex) {
        result.add(((TypeNode) typeArguments.jjtGetChild(childIndex)).getTypeDefinition());
    }
    return result;
}
Also used : ASTTypeArguments(net.sourceforge.pmd.lang.java.ast.ASTTypeArguments) JavaTypeDefinition(net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition) ArrayList(java.util.ArrayList) ASTMemberSelector(net.sourceforge.pmd.lang.java.ast.ASTMemberSelector) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint)

Aggregations

ASTTypeArguments (net.sourceforge.pmd.lang.java.ast.ASTTypeArguments)2 JavaTypeDefinition (net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition)2 ArrayList (java.util.ArrayList)1 QualifiableNode (net.sourceforge.pmd.lang.ast.QualifiableNode)1 ASTMemberSelector (net.sourceforge.pmd.lang.java.ast.ASTMemberSelector)1 Constraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint)1