Search in sources :

Example 1 with Structure

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

the class StatementAndBraceFinder method buildDataFlowFor.

public void buildDataFlowFor(JavaNode node) {
    if (!(node instanceof ASTMethodDeclaration) && !(node instanceof ASTConstructorDeclaration)) {
        throw new RuntimeException("Can't build a data flow for anything other than a method or a constructor");
    }
    this.dataFlow = new Structure(dataFlowHandler);
    this.dataFlow.createStartNode(node.getBeginLine());
    this.dataFlow.createNewNode(node);
    node.jjtAccept(this, dataFlow);
    this.dataFlow.createEndNode(node.getEndLine());
    if (LOGGER.isLoggable(Level.FINE)) {
        // TODO SRT Remove after development
        LOGGER.fine("DataFlow is " + this.dataFlow.dump());
    }
    Linker linker = new Linker(dataFlowHandler, dataFlow.getBraceStack(), dataFlow.getContinueBreakReturnStack());
    try {
        linker.computePaths();
    } catch (SequenceException | LinkerException e) {
        e.printStackTrace();
    }
}
Also used : LinkerException(net.sourceforge.pmd.lang.dfa.LinkerException) ASTConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration) ASTMethodDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration) SequenceException(net.sourceforge.pmd.lang.dfa.SequenceException) Structure(net.sourceforge.pmd.lang.dfa.Structure) Linker(net.sourceforge.pmd.lang.dfa.Linker)

Example 2 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 3 with Structure

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

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTSwitchLabel node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    // super.visit(node, data);
    if (node.jjtGetNumChildren() == 0) {
        dataFlow.pushOnStack(NodeType.SWITCH_LAST_DEFAULT_STATEMENT, dataFlow.getLast());
        tryToLog(NodeType.SWITCH_LAST_DEFAULT_STATEMENT, node);
    } else {
        dataFlow.pushOnStack(NodeType.CASE_LAST_STATEMENT, dataFlow.getLast());
        tryToLog(NodeType.CASE_LAST_STATEMENT, node);
    }
    return data;
}
Also used : Structure(net.sourceforge.pmd.lang.dfa.Structure)

Example 4 with Structure

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

the class StatementAndBraceFinder method visit.

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

Example 5 with Structure

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

the class StatementAndBraceFinder method visit.

@Override
public Object visit(ASTForUpdate node, Object data) {
    if (!(data instanceof Structure)) {
        return data;
    }
    Structure dataFlow = (Structure) data;
    this.addForExpressionNode(node, dataFlow);
    super.visit(node, data);
    dataFlow.pushOnStack(NodeType.FOR_UPDATE, dataFlow.getLast());
    tryToLog(NodeType.FOR_UPDATE, node);
    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