Search in sources :

Example 1 with ASTElsifClause

use of net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause in project pmd by pmd.

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTIfStatement node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    LOGGER.finest("ElsifClause) super.visit line");
    super.visit(node, data);
    /*
         * PLSQL AST now has explicit ELSIF and ELSE clauses All of the
         * ELSE_END_STATEMENTS in an IF clause should point to the outer last
         * clause because we have to convert a single PL/SQL IF/ELSIF/ELSE
         * satement into the equivalent set of nested Java if/else {if/else
         * {if/else}} statements
         */
    List<ASTElsifClause> elsifs = node.findChildrenOfType(ASTElsifClause.class);
    ASTElseClause elseClause = node.getFirstChildOfType(ASTElseClause.class);
    // statement
    if (null == elseClause && elsifs.isEmpty()) {
        dataFlow.pushOnStack(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack (ASTIfClause - no ELSIFs) IF_LAST_STATEMENT_WITHOUT_ELSE: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    } else {
        if (!elsifs.isEmpty()) {
            ASTElsifClause lastElsifClause = elsifs.get(elsifs.size() - 1);
            for (ASTElsifClause elsifClause : elsifs) {
                /*
                     * If last ELSIF clause is not followed by a ELSE clause
                     * then the last ELSIF is equivalent to an if statement
                     * without an else Otherwise, it is equivalent to an if/else
                     * statement
                     */
                if (lastElsifClause.equals(elsifClause) && elseClause == null) {
                    dataFlow.pushOnStack(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE, dataFlow.getLast());
                    if (LOGGER.isLoggable(Level.FINEST)) {
                        LOGGER.finest("pushOnStack (ASTIfClause - with ELSIFs) IF_LAST_STATEMENT_WITHOUT_ELSE: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
                    }
                }
                {
                    dataFlow.pushOnStack(NodeType.ELSE_LAST_STATEMENT, dataFlow.getLast());
                    if (LOGGER.isLoggable(Level.FINEST)) {
                        LOGGER.finest("pushOnStack (ASTIfClause - with ELSIFs) ELSE_LAST_STATEMENT : line " + node.getBeginLine() + ", column " + node.getBeginColumn());
                    }
                }
            }
        }
        if (null != elseClause) {
            // Output one terminating else
            dataFlow.pushOnStack(NodeType.ELSE_LAST_STATEMENT, dataFlow.getLast());
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("pushOnStack (ASTIfClause - with ELSE) ELSE_LAST_STATEMENT : line " + node.getBeginLine() + ", column " + node.getBeginColumn());
            }
        }
    }
    return data;
}
Also used : ASTElsifClause(net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause) ASTElseClause(net.sourceforge.pmd.lang.plsql.ast.ASTElseClause) Structure(net.sourceforge.pmd.lang.dfa.Structure)

Example 2 with ASTElsifClause

use of net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause in project pmd by pmd.

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTExpression node, Object data) {
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("Entry ASTExpression: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
    }
    if (!(data instanceof Structure)) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("immediate return ASTExpression: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
        return data;
    }
    Structure dataFlow = (Structure) data;
    // an UnLabelledStatement
    if (node.jjtGetParent() instanceof ASTUnlabelledStatement) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("createNewNode ASTSUnlabelledStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
        dataFlow.createNewNode(node);
    } else if (node.jjtGetParent() instanceof ASTIfStatement) {
        // TODO what about throw stmts?
        // START IF
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.IF_EXPR, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack parent IF_EXPR: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    } else if (node.jjtGetParent() instanceof ASTElsifClause) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("parent (Elsif) IF_EXPR at  " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
        // START IF
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.IF_EXPR, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack parent (Elsif) IF_EXPR: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    } else if (node.jjtGetParent() instanceof ASTWhileStatement) {
        // START WHILE
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.WHILE_EXPR, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack parent WHILE_EXPR: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    } else if (node.jjtGetParent() instanceof ASTCaseStatement) {
        // START SWITCH
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.SWITCH_START, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack parent SWITCH_START: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    } else if (node.jjtGetParent() instanceof ASTForStatement) {
        /*
             * A PL/SQL loop control: [<REVERSE>] Expression()[".."Expression()]
             */
        if (node.equals(node.jjtGetParent().getFirstChildOfType(ASTExpression.class))) {
            // FOR EXPR
            dataFlow.createNewNode(node);
            dataFlow.pushOnStack(NodeType.FOR_EXPR, dataFlow.getLast());
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("pushOnStack parent FOR_EXPR: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
            }
        }
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("parent (ASTForStatement): line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    } else if (node.jjtGetParent() instanceof ASTLoopStatement) {
        // DO EXPR
        dataFlow.createNewNode(node);
        dataFlow.pushOnStack(NodeType.DO_EXPR, dataFlow.getLast());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("pushOnStack parent DO_EXPR: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
    }
    return super.visit(node, data);
}
Also used : ASTWhileStatement(net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement) ASTCaseStatement(net.sourceforge.pmd.lang.plsql.ast.ASTCaseStatement) ASTIfStatement(net.sourceforge.pmd.lang.plsql.ast.ASTIfStatement) ASTElsifClause(net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause) ASTLoopStatement(net.sourceforge.pmd.lang.plsql.ast.ASTLoopStatement) Structure(net.sourceforge.pmd.lang.dfa.Structure) ASTForStatement(net.sourceforge.pmd.lang.plsql.ast.ASTForStatement) ASTUnlabelledStatement(net.sourceforge.pmd.lang.plsql.ast.ASTUnlabelledStatement)

Aggregations

Structure (net.sourceforge.pmd.lang.dfa.Structure)2 ASTElsifClause (net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause)2 ASTCaseStatement (net.sourceforge.pmd.lang.plsql.ast.ASTCaseStatement)1 ASTElseClause (net.sourceforge.pmd.lang.plsql.ast.ASTElseClause)1 ASTForStatement (net.sourceforge.pmd.lang.plsql.ast.ASTForStatement)1 ASTIfStatement (net.sourceforge.pmd.lang.plsql.ast.ASTIfStatement)1 ASTLoopStatement (net.sourceforge.pmd.lang.plsql.ast.ASTLoopStatement)1 ASTUnlabelledStatement (net.sourceforge.pmd.lang.plsql.ast.ASTUnlabelledStatement)1 ASTWhileStatement (net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement)1