Search in sources :

Example 21 with Structure

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

the class StructureTest method testAddResultsinDFANodeContainingAddedNode.

@Test
public void testAddResultsinDFANodeContainingAddedNode() {
    Structure s = new Structure(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler().getDataFlowHandler());
    Node n = new ASTMethodDeclaration(1);
    assertEquals(n, s.createNewNode(n).getNode());
}
Also used : ASTMethodDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration) Node(net.sourceforge.pmd.lang.ast.Node) Structure(net.sourceforge.pmd.lang.dfa.Structure) Test(org.junit.Test)

Example 22 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 23 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 24 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 25 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 (!(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)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