Search in sources :

Example 26 with Structure

use of net.sourceforge.pmd.lang.dfa.Structure in project pmd by pmd.

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTExpression node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    String loggerTag = "parent";
    Node parent = node.jjtGetParent();
    // TODO what about throw stmts?
    if (parent instanceof ASTIfStatement) {
        // START IF
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.IF_EXPR, dataFlow.getLast());
        tryToLog(loggerTag, NodeType.IF_EXPR, node);
    } else if (parent instanceof ASTWhileStatement) {
        // START WHILE
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.WHILE_EXPR, dataFlow.getLast());
        tryToLog(loggerTag, NodeType.WHILE_EXPR, node);
    } else if (parent instanceof ASTSwitchStatement) {
        // START SWITCH
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.SWITCH_START, dataFlow.getLast());
        tryToLog(loggerTag, NodeType.SWITCH_START, node);
    } else if (parent instanceof ASTForStatement) {
        // FOR EXPR
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.FOR_EXPR, dataFlow.getLast());
        tryToLog(loggerTag, NodeType.FOR_EXPR, node);
    } else if (parent instanceof ASTDoStatement) {
        // DO EXPR
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.DO_EXPR, dataFlow.getLast());
        tryToLog(loggerTag, NodeType.DO_EXPR, node);
    } else if (parent instanceof ASTAssertStatement) {
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.ASSERT_STATEMENT, dataFlow.getLast());
        tryToLog(loggerTag, NodeType.ASSERT_STATEMENT, node);
    }
    return super.visit(node, data);
}
Also used : ASTWhileStatement(net.sourceforge.pmd.lang.java.ast.ASTWhileStatement) ASTDoStatement(net.sourceforge.pmd.lang.java.ast.ASTDoStatement) Node(net.sourceforge.pmd.lang.ast.Node) JavaNode(net.sourceforge.pmd.lang.java.ast.JavaNode) ASTIfStatement(net.sourceforge.pmd.lang.java.ast.ASTIfStatement) ASTSwitchStatement(net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement) ASTAssertStatement(net.sourceforge.pmd.lang.java.ast.ASTAssertStatement) Structure(net.sourceforge.pmd.lang.dfa.Structure) ASTForStatement(net.sourceforge.pmd.lang.java.ast.ASTForStatement)

Example 27 with Structure

use of net.sourceforge.pmd.lang.dfa.Structure in project pmd by pmd.

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTReturnStatement node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    dataFlow.createNewNode(node);
    dataFlow.pushOnStack(NodeType.RETURN_STATEMENT, dataFlow.getLast());
    tryToLog(NodeType.RETURN_STATEMENT, node);
    return super.visit(node, data);
}
Also used : Structure(net.sourceforge.pmd.lang.dfa.Structure)

Example 28 with Structure

use of net.sourceforge.pmd.lang.dfa.Structure in project pmd by pmd.

the class StatementAndBraceFinder method visit.

// ----------------------------------------------------------------------------
// BRANCH OUT
@Override
public Object visit(ASTStatement node, Object data) {
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("entry ASTStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn() + " -> " + node.getClass().getCanonicalName());
    }
    if (!(data instanceof Structure)) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("immediate return ASTStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
        return data;
    }
    Structure dataFlow = (Structure) data;
    if (node.jjtGetParent() instanceof ASTForStatement) {
        ASTForStatement st = (ASTForStatement) node.jjtGetParent();
        if (node.equals(st.getFirstChildOfType(ASTStatement.class))) {
            addForExpressionNode(node, dataFlow);
            dataFlow.pushOnStack(NodeType.FOR_BEFORE_FIRST_STATEMENT, dataFlow.getLast());
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("pushOnStack FOR_BEFORE_FIRST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
            }
        }
    } else if (node.jjtGetParent() instanceof ASTLoopStatement) {
        ASTLoopStatement st = (ASTLoopStatement) node.jjtGetParent();
        if (node.equals(st.getFirstChildOfType(ASTStatement.class))) {
            dataFlow.pushOnStack(NodeType.DO_BEFORE_FIRST_STATEMENT, dataFlow.getLast());
            dataFlow.createNewNode(node.jjtGetParent());
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("pushOnStack DO_BEFORE_FIRST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
            }
        }
    }
    super.visit(node, data);
    if (node.jjtGetParent() instanceof ASTElseClause) {
        List<ASTStatement> allStatements = node.jjtGetParent().findChildrenOfType(ASTStatement.class);
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("ElseClause has " + allStatements.size() + " Statements ");
        }
    /*
             * //Restrict to the last Statement of the Else Clause if (node ==
             * allStatements.get(allStatements.size()-1) ) { if
             * (node.jjtGetParent().jjtGetParent() instanceof ASTCaseStatement)
             * { dataFlow.pushOnStack(NodeType.SWITCH_LAST_DEFAULT_STATEMENT,
             * dataFlow.getLast()); LOGGER.finest(
             * "pushOnStack (Else-Below Case) SWITCH_LAST_DEFAULT_STATEMENT: line "
             * + node.getBeginLine() +", column " + node.getBeginColumn()); }
             * /*SRT else // if (node == node.jjtGetParent() instanceof
             * ASTElseClause) { {
             * dataFlow.pushOnStack(NodeType.ELSE_LAST_STATEMENT,
             * dataFlow.getLast()); LOGGER.finest(
             * "pushOnStack (Else-Below If) ELSE_LAST_STATEMENT: line " +
             * node.getBeginLine() +", column " + node.getBeginColumn()); }
             */
    // }
    } else if (node.jjtGetParent() instanceof ASTWhileStatement) {
        ASTWhileStatement statement = (ASTWhileStatement) node.jjtGetParent();
        List<ASTStatement> children = statement.findChildrenOfType(ASTStatement.class);
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("(LastChildren): size " + children.size());
        }
        ASTStatement lastChild = children.get(children.size() - 1);
        // the FOR Statment
        if (node.equals(lastChild)) {
            dataFlow.pushOnStack(NodeType.WHILE_LAST_STATEMENT, dataFlow.getLast());
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("pushOnStack WHILE_LAST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
            }
        }
    } else if (node.jjtGetParent() instanceof ASTForStatement) {
        ASTForStatement statement = (ASTForStatement) node.jjtGetParent();
        List<ASTStatement> children = statement.findChildrenOfType(ASTStatement.class);
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("(LastChildren): size " + children.size());
        }
        ASTStatement lastChild = children.get(children.size() - 1);
        // the FOR Statment
        if (node.equals(lastChild)) {
            dataFlow.pushOnStack(NodeType.FOR_END, dataFlow.getLast());
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("pushOnStack (LastChildStatemnt) FOR_END: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
            }
        }
    } else if (node.jjtGetParent() instanceof ASTLabelledStatement) {
        dataFlow.pushOnStack(NodeType.LABEL_LAST_STATEMENT, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack LABEL_LAST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    }
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("exit ASTStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn() + " -> " + node.getClass().getCanonicalName() + " ->-> " + node.jjtGetParent().getClass().getCanonicalName());
    }
    return data;
}
Also used : ASTWhileStatement(net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement) ASTLabelledStatement(net.sourceforge.pmd.lang.plsql.ast.ASTLabelledStatement) ASTElseClause(net.sourceforge.pmd.lang.plsql.ast.ASTElseClause) ASTLoopStatement(net.sourceforge.pmd.lang.plsql.ast.ASTLoopStatement) List(java.util.List) Structure(net.sourceforge.pmd.lang.dfa.Structure) ASTForStatement(net.sourceforge.pmd.lang.plsql.ast.ASTForStatement) ASTStatement(net.sourceforge.pmd.lang.plsql.ast.ASTStatement)

Example 29 with Structure

use of net.sourceforge.pmd.lang.dfa.Structure in project pmd by pmd.

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTCaseStatement node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    // CASE is "searched case statement"
    if (null == node.getFirstChildOfType(ASTExpression.class)) {
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.SWITCH_START, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack SWITCH_START: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    }
    super.visit(node, data);
    dataFlow.pushOnStack(NodeType.SWITCH_END, dataFlow.getLast());
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("pushOnStack SWITCH_END: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
    }
    return data;
}
Also used : Structure(net.sourceforge.pmd.lang.dfa.Structure) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression)

Example 30 with Structure

use of net.sourceforge.pmd.lang.dfa.Structure in project pmd by pmd.

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTElsifClause node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    dataFlow.pushOnStack(NodeType.IF_LAST_STATEMENT, dataFlow.getLast());
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("pushOnStack (Visit ASTElsifClause) IF_LAST_STATEMENT: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        LOGGER.finest("ElsifClause) super.visit line");
    }
    super.visit(node, data);
    return data;
}
Also used : Structure(net.sourceforge.pmd.lang.dfa.Structure)

Aggregations

Structure (net.sourceforge.pmd.lang.dfa.Structure)36 Node (net.sourceforge.pmd.lang.ast.Node)2 Linker (net.sourceforge.pmd.lang.dfa.Linker)2 LinkerException (net.sourceforge.pmd.lang.dfa.LinkerException)2 SequenceException (net.sourceforge.pmd.lang.dfa.SequenceException)2 ASTDoStatement (net.sourceforge.pmd.lang.java.ast.ASTDoStatement)2 ASTForStatement (net.sourceforge.pmd.lang.java.ast.ASTForStatement)2 ASTIfStatement (net.sourceforge.pmd.lang.java.ast.ASTIfStatement)2 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)2 ASTWhileStatement (net.sourceforge.pmd.lang.java.ast.ASTWhileStatement)2 ASTElseClause (net.sourceforge.pmd.lang.plsql.ast.ASTElseClause)2 ASTElsifClause (net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause)2 ASTForStatement (net.sourceforge.pmd.lang.plsql.ast.ASTForStatement)2 ASTIfStatement (net.sourceforge.pmd.lang.plsql.ast.ASTIfStatement)2 ASTLabelledStatement (net.sourceforge.pmd.lang.plsql.ast.ASTLabelledStatement)2 ASTLoopStatement (net.sourceforge.pmd.lang.plsql.ast.ASTLoopStatement)2 ASTWhileStatement (net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement)2 List (java.util.List)1 ASTAssertStatement (net.sourceforge.pmd.lang.java.ast.ASTAssertStatement)1 ASTConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration)1