Search in sources :

Example 1 with ASTMemberSelector

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

the class NameFinder method checkForNameChild.

private void checkForNameChild(JavaNode node) {
    if (node.getImage() != null) {
        add(new JavaNameOccurrence(node, node.getImage()));
    }
    if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
        ASTName grandchild = (ASTName) node.jjtGetChild(0);
        for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens(); ) {
            add(new JavaNameOccurrence(grandchild, st.nextToken()));
        }
    }
    if (node.jjtGetNumChildren() > 1 && node.jjtGetChild(1) instanceof ASTMethodReference) {
        ASTMethodReference methodRef = (ASTMethodReference) node.jjtGetChild(1);
        add(new JavaNameOccurrence(methodRef, methodRef.getImage()));
    }
    if (node instanceof ASTPrimarySuffix) {
        ASTPrimarySuffix suffix = (ASTPrimarySuffix) node;
        if (suffix.isArguments()) {
            JavaNameOccurrence occurrence = names.get(names.size() - 1);
            occurrence.setIsMethodOrConstructorInvocation();
            ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0);
            occurrence.setArgumentCount(args.getArgumentCount());
        } else if (suffix.jjtGetNumChildren() == 1 && suffix.jjtGetChild(0) instanceof ASTMemberSelector) {
            ASTMemberSelector member = (ASTMemberSelector) suffix.jjtGetChild(0);
            if (member.jjtGetNumChildren() == 1 && member.jjtGetChild(0) instanceof ASTMethodReference) {
                ASTMethodReference methodRef = (ASTMethodReference) member.jjtGetChild(0);
                add(new JavaNameOccurrence(methodRef, methodRef.getImage()));
            } else {
                add(new JavaNameOccurrence(member, member.getImage()));
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ASTMethodReference(net.sourceforge.pmd.lang.java.ast.ASTMethodReference) ASTName(net.sourceforge.pmd.lang.java.ast.ASTName) ASTArguments(net.sourceforge.pmd.lang.java.ast.ASTArguments) ASTPrimarySuffix(net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix) ASTMemberSelector(net.sourceforge.pmd.lang.java.ast.ASTMemberSelector)

Example 2 with ASTMemberSelector

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

ASTMemberSelector (net.sourceforge.pmd.lang.java.ast.ASTMemberSelector)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 ASTArguments (net.sourceforge.pmd.lang.java.ast.ASTArguments)1 ASTMethodReference (net.sourceforge.pmd.lang.java.ast.ASTMethodReference)1 ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)1 ASTPrimarySuffix (net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix)1 ASTTypeArguments (net.sourceforge.pmd.lang.java.ast.ASTTypeArguments)1 JavaTypeDefinition (net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition)1 Constraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint)1