Search in sources :

Example 1 with ASTLabeledStatement

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

the class StatementAndBraceFinder method visit.

// ----------------------------------------------------------------------------
// BRANCH OUT
@Override
public Object visit(ASTStatement node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    if (node.jjtGetParent() instanceof ASTForStatement) {
        this.addForExpressionNode(node, dataFlow);
        dataFlow.pushOnStack(NodeType.FOR_BEFORE_FIRST_STATEMENT, dataFlow.getLast());
        tryToLog(NodeType.FOR_BEFORE_FIRST_STATEMENT, node);
    } else if (node.jjtGetParent() instanceof ASTDoStatement) {
        dataFlow.pushOnStack(NodeType.DO_BEFORE_FIRST_STATEMENT, dataFlow.getLast());
        dataFlow.createNewNode(node.jjtGetParent());
        tryToLog(NodeType.DO_BEFORE_FIRST_STATEMENT, node);
    }
    super.visit(node, data);
    if (node.jjtGetParent() instanceof ASTIfStatement) {
        ASTIfStatement st = (ASTIfStatement) node.jjtGetParent();
        if (!st.hasElse()) {
            dataFlow.pushOnStack(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE, dataFlow.getLast());
            tryToLog(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE, node);
        } else if (st.hasElse() && !st.jjtGetChild(1).equals(node)) {
            dataFlow.pushOnStack(NodeType.ELSE_LAST_STATEMENT, dataFlow.getLast());
            tryToLog(NodeType.ELSE_LAST_STATEMENT, node);
        } else {
            dataFlow.pushOnStack(NodeType.IF_LAST_STATEMENT, dataFlow.getLast());
            tryToLog(NodeType.IF_LAST_STATEMENT, node);
        }
    } else if (node.jjtGetParent() instanceof ASTWhileStatement) {
        dataFlow.pushOnStack(NodeType.WHILE_LAST_STATEMENT, dataFlow.getLast());
        tryToLog(NodeType.WHILE_LAST_STATEMENT, node);
    } else if (node.jjtGetParent() instanceof ASTForStatement) {
        dataFlow.pushOnStack(NodeType.FOR_END, dataFlow.getLast());
        tryToLog(NodeType.FOR_END, node);
    } else if (node.jjtGetParent() instanceof ASTLabeledStatement) {
        dataFlow.pushOnStack(NodeType.LABEL_LAST_STATEMENT, dataFlow.getLast());
        tryToLog(NodeType.LABEL_LAST_STATEMENT, node);
    }
    return data;
}
Also used : ASTWhileStatement(net.sourceforge.pmd.lang.java.ast.ASTWhileStatement) ASTDoStatement(net.sourceforge.pmd.lang.java.ast.ASTDoStatement) ASTLabeledStatement(net.sourceforge.pmd.lang.java.ast.ASTLabeledStatement) ASTIfStatement(net.sourceforge.pmd.lang.java.ast.ASTIfStatement) Structure(net.sourceforge.pmd.lang.dfa.Structure) ASTForStatement(net.sourceforge.pmd.lang.java.ast.ASTForStatement)

Aggregations

Structure (net.sourceforge.pmd.lang.dfa.Structure)1 ASTDoStatement (net.sourceforge.pmd.lang.java.ast.ASTDoStatement)1 ASTForStatement (net.sourceforge.pmd.lang.java.ast.ASTForStatement)1 ASTIfStatement (net.sourceforge.pmd.lang.java.ast.ASTIfStatement)1 ASTLabeledStatement (net.sourceforge.pmd.lang.java.ast.ASTLabeledStatement)1 ASTWhileStatement (net.sourceforge.pmd.lang.java.ast.ASTWhileStatement)1