Search in sources :

Example 16 with ASTType

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

the class CouplingBetweenObjectsRule method handleASTTypeChildren.

/**
 * convience method to handle hierarchy. This is probably too much work and
 * will go away once I figure out the framework
 */
private void handleASTTypeChildren(Node node) {
    for (int x = 0; x < node.jjtGetNumChildren(); x++) {
        Node sNode = node.jjtGetChild(x);
        if (sNode instanceof ASTType) {
            Node nameNode = sNode.jjtGetChild(0);
            checkVariableType(nameNode, nameNode.getImage());
        }
    }
}
Also used : ASTType(net.sourceforge.pmd.lang.java.ast.ASTType) Node(net.sourceforge.pmd.lang.ast.Node) JavaNode(net.sourceforge.pmd.lang.java.ast.JavaNode)

Example 17 with ASTType

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

the class AvoidCatchingThrowableRule method visit.

@Override
public Object visit(ASTCatchStatement node, Object data) {
    ASTType type = node.getFirstDescendantOfType(ASTType.class);
    ASTClassOrInterfaceType name = type.getFirstDescendantOfType(ASTClassOrInterfaceType.class);
    if (name.hasImageEqualTo("Throwable")) {
        addViolation(data, name);
    }
    return super.visit(node, data);
}
Also used : ASTType(net.sourceforge.pmd.lang.java.ast.ASTType) ASTClassOrInterfaceType(net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType)

Example 18 with ASTType

use of net.sourceforge.pmd.lang.java.ast.ASTType in project pmd-eclipse-plugin by pmd.

the class ASTUtil method getFieldLabel.

public static String getFieldLabel(ASTFieldDeclaration pmdField) {
    StringBuilder sb = new StringBuilder();
    addModifiers(pmdField, sb);
    ASTType type = pmdField.getFirstChildOfType(ASTType.class);
    if (type != null) {
        sb.append(' ').append(type.getTypeImage());
    }
    sb.append(' ').append(pmdField.getVariableName());
    return sb.toString();
}
Also used : ASTType(net.sourceforge.pmd.lang.java.ast.ASTType)

Example 19 with ASTType

use of net.sourceforge.pmd.lang.java.ast.ASTType in project pmd-eclipse-plugin by pmd.

the class ASTUtil method getLocalVarDeclarationLabel.

public static String getLocalVarDeclarationLabel(ASTLocalVariableDeclaration node) {
    StringBuilder sb = new StringBuilder();
    addModifiers(node, sb);
    ASTType type = node.getTypeNode();
    sb.append(' ').append(type.getTypeImage());
    for (int i = 0; i < node.getArrayDepth(); i++) {
        sb.append("[]");
    }
    sb.append(' ').append(node.getVariableName());
    return sb.toString();
}
Also used : ASTType(net.sourceforge.pmd.lang.java.ast.ASTType)

Aggregations

ASTType (net.sourceforge.pmd.lang.java.ast.ASTType)19 Node (net.sourceforge.pmd.lang.ast.Node)8 ASTReferenceType (net.sourceforge.pmd.lang.java.ast.ASTReferenceType)8 ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType)6 ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)5 ArrayList (java.util.ArrayList)4 ASTFormalParameter (net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)4 ASTPrimaryExpression (net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression)4 ASTPrimaryPrefix (net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix)3 ASTStatementExpression (net.sourceforge.pmd.lang.java.ast.ASTStatementExpression)3 JavaNode (net.sourceforge.pmd.lang.java.ast.JavaNode)3 ASTArgumentList (net.sourceforge.pmd.lang.java.ast.ASTArgumentList)2 ASTLocalVariableDeclaration (net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration)2 ASTMethodDeclarator (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator)2 ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)2 ASTPrimitiveType (net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType)2 ASTReturnStatement (net.sourceforge.pmd.lang.java.ast.ASTReturnStatement)2 ASTTryStatement (net.sourceforge.pmd.lang.java.ast.ASTTryStatement)2 Dimensionable (net.sourceforge.pmd.lang.java.ast.Dimensionable)2 VariableNameDeclaration (net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration)2