Search in sources :

Example 11 with Structure

use of net.sourceforge.pmd.lang.dfa.Structure 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 12 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 13 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 14 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 15 with Structure

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

the class StatementAndBraceFinder method visit.

/**
 * PL/SQL does not have a do/while statement or repeat/until statement: the
 * equivalent is a LOOP statement. A PL/SQL LOOP statement is exited using
 * an explicit EXIT ( == break;) statement It does not have a test
 * expression, so the Java control processing (on the expression) does not
 * fire. The best way to cope it to push a DO_EXPR after the loop.
 */
@Override
public Object visit(ASTLoopStatement node, Object data) {
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("entry ASTLoopStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
    }
    if (!(data instanceof Structure)) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("immediate return ASTLoopStatement: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
        }
        return data;
    }
    Structure dataFlow = (Structure) data;
    // process the contents on the LOOP statement
    super.visit(node, data);
    dataFlow.createNewNode(node);
    dataFlow.pushOnStack(NodeType.DO_EXPR, dataFlow.getLast());
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("pushOnStack (ASTLoopStatement) DO_EXPR: line " + node.getBeginLine() + ", column " + node.getBeginColumn());
    }
    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