Search in sources :

Example 6 with ASTPrimitiveType

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

the class MethodNameDeclaration method hashCode.

@Override
public int hashCode() {
    int hash = node.getImage().hashCode() * 31 + ((ASTMethodDeclarator) node).getParameterCount();
    ASTFormalParameters myParams = (ASTFormalParameters) node.jjtGetChild(0);
    for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
        ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
        Node myTypeNode = myParam.getTypeNode().jjtGetChild(0);
        String myTypeImg;
        if (myTypeNode instanceof ASTPrimitiveType) {
            myTypeImg = myTypeNode.getImage();
        } else {
            myTypeImg = myTypeNode.jjtGetChild(0).getImage();
        }
        hash = hash * 31 + myTypeImg.hashCode();
    }
    return hash;
}
Also used : ASTPrimitiveType(net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType) Node(net.sourceforge.pmd.lang.ast.Node) ASTFormalParameters(net.sourceforge.pmd.lang.java.ast.ASTFormalParameters) ASTFormalParameter(net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)

Example 7 with ASTPrimitiveType

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

the class ConstructorCallsOverridableMethodRule method getMethodDeclaratorParameterTypes.

private static List<String> getMethodDeclaratorParameterTypes(Node methodOrConstructorDeclarator) {
    List<ASTFormalParameter> parameters = methodOrConstructorDeclarator.findDescendantsOfType(ASTFormalParameter.class);
    List<String> parameterTypes = new ArrayList<>();
    if (parameters != null) {
        for (ASTFormalParameter p : parameters) {
            ASTType type = p.getFirstChildOfType(ASTType.class);
            if (type.jjtGetChild(0) instanceof ASTPrimitiveType) {
                parameterTypes.add(type.jjtGetChild(0).getImage());
            } else if (type.jjtGetChild(0) instanceof ASTReferenceType) {
                parameterTypes.add("ref");
            } else {
                parameterTypes.add("<unkown>");
            }
        }
    }
    return parameterTypes;
}
Also used : ASTPrimitiveType(net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType) ASTType(net.sourceforge.pmd.lang.java.ast.ASTType) ArrayList(java.util.ArrayList) ASTFormalParameter(net.sourceforge.pmd.lang.java.ast.ASTFormalParameter) ASTReferenceType(net.sourceforge.pmd.lang.java.ast.ASTReferenceType)

Aggregations

ASTPrimitiveType (net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType)7 Node (net.sourceforge.pmd.lang.ast.Node)4 ASTFormalParameter (net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)4 ASTFormalParameters (net.sourceforge.pmd.lang.java.ast.ASTFormalParameters)3 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)2 ASTMethodDeclarator (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator)2 ASTReferenceType (net.sourceforge.pmd.lang.java.ast.ASTReferenceType)2 ASTResultType (net.sourceforge.pmd.lang.java.ast.ASTResultType)2 ASTType (net.sourceforge.pmd.lang.java.ast.ASTType)2 ArrayList (java.util.ArrayList)1 ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType)1 ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)1 JavaNameOccurrence (net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence)1 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)1