Search in sources :

Example 1 with DagNode

use of com.randomnoun.build.javaToGraphviz.dag.DagNode in project java-to-graphviz by randomnoun.

the class ControlFlowEdger method addArrayCreationEdges.

private List<ExitEdge> addArrayCreationEdges(Dag dag, DagNode node, LexicalScope scope) {
    ArrayCreation ac = (ArrayCreation) node.astNode;
    List<DagNode> dimensionDags = getDagChildren(node.children, ac.dimensions(), null);
    DagNode arrayInitDag = getDagChild(node.children, ac.getInitializer(), null);
    node.gvAttributes.put("type", ac.getType().toString());
    List<ExitEdge> prevNodes = null;
    if (arrayInitDag != null || dimensionDags.size() > 0) {
        // move methodInvocation node after the expression & argument nodes
        Rejigger rejigger = hoistNode(dag, node, dimensionDags.size() == 0 ? arrayInitDag : dimensionDags.get(0));
        for (DagNode a : dimensionDags) {
            if (prevNodes != null) {
                for (ExitEdge e : prevNodes) {
                    e.n2 = a;
                    // e.classes.add("invocationArgument");
                    addEdge(e);
                }
            }
            prevNodes = addExpressionEdges(dag, a, scope);
        }
        // expression is null for method calls within the same object
        if (arrayInitDag != null) {
            if (prevNodes != null) {
                for (ExitEdge e : prevNodes) {
                    e.n2 = arrayInitDag;
                    // e.classes.add("invocationArgument");
                    addEdge(e);
                }
            }
            prevNodes = addExpressionEdges(dag, arrayInitDag, scope);
        }
        prevNodes = rejigger.unhoistNode(dag, prevNodes);
    } else {
        ExitEdge e = new ExitEdge();
        e.n1 = node;
        prevNodes = Collections.singletonList(e);
    }
    return prevNodes;
}
Also used : DagNode(com.randomnoun.build.javaToGraphviz.dag.DagNode) ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge) ArrayCreation(org.eclipse.jdt.core.dom.ArrayCreation)

Example 2 with DagNode

use of com.randomnoun.build.javaToGraphviz.dag.DagNode in project java-to-graphviz by randomnoun.

the class ControlFlowEdger method addPostfixExpressionEdges.

private List<ExitEdge> addPostfixExpressionEdges(Dag dag, DagNode node, LexicalScope scope) {
    PostfixExpression pe = (PostfixExpression) node.astNode;
    DagNode operandDag = getDagChild(node.children, pe.getOperand(), null);
    PostfixExpression.Operator op = pe.getOperator();
    node.gvAttributes.put("operatorToken", op.toString());
    // @TODO camelcase
    node.gvAttributes.put("operatorName", Text.getLastComponent(op.getClass().getName()));
    Rejigger rejigger = hoistNode(dag, node, operandDag);
    List<ExitEdge> prevNodes = addExpressionEdges(dag, operandDag, scope);
    prevNodes = rejigger.unhoistNode(dag, prevNodes);
    return prevNodes;
}
Also used : DagNode(com.randomnoun.build.javaToGraphviz.dag.DagNode) ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge) PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression)

Example 3 with DagNode

use of com.randomnoun.build.javaToGraphviz.dag.DagNode in project java-to-graphviz by randomnoun.

the class ControlFlowEdger method addMethodInvocationEdges.

private List<ExitEdge> addMethodInvocationEdges(Dag dag, DagNode methodInvocationNode, LexicalScope scope) {
    MethodInvocation mi = (MethodInvocation) methodInvocationNode.astNode;
    DagNode expressionDag = getDagChild(methodInvocationNode.children, mi.getExpression(), null);
    DagNode nameDag = getDagChild(methodInvocationNode.children, mi.getName(), null);
    List<DagNode> argumentDags = getDagChildren(methodInvocationNode.children, mi.arguments(), null);
    methodInvocationNode.gvAttributes.put("methodName", mi.getName().toString());
    // for combined charts only
    addEdges(dag, nameDag, scope);
    List<ExitEdge> prevNodes = null;
    if (expressionDag != null || argumentDags.size() > 0) {
        // move methodInvocation node after the expression & argument nodes
        Rejigger rejigger = hoistNode(dag, methodInvocationNode, expressionDag != null ? expressionDag : argumentDags.get(0));
        // expression is null for method calls within the same object
        if (expressionDag != null) {
            prevNodes = addExpressionEdges(dag, expressionDag, scope);
        }
        for (DagNode a : argumentDags) {
            if (prevNodes != null) {
                for (ExitEdge e : prevNodes) {
                    e.n2 = a;
                    e.classes.add("invocationArgument");
                    addEdge(e);
                }
            }
            prevNodes = addExpressionEdges(dag, a, scope);
        }
        // what's the opposite of rejiggering ?
        // hoisting ? petarding ? right I'm just going to say unhoist
        prevNodes = rejigger.unhoistNode(dag, prevNodes);
    } else {
        ExitEdge e = new ExitEdge();
        e.n1 = methodInvocationNode;
        prevNodes = Collections.singletonList(e);
    }
    return prevNodes;
}
Also used : DagNode(com.randomnoun.build.javaToGraphviz.dag.DagNode) ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation)

Example 4 with DagNode

use of com.randomnoun.build.javaToGraphviz.dag.DagNode in project java-to-graphviz by randomnoun.

the class ControlFlowEdger method addEnhancedForEdges.

// draw branches into and out of extended for body
private List<ExitEdge> addEnhancedForEdges(Dag dag, DagNode forNode, LexicalScope scope) {
    // draw the edges
    EnhancedForStatement fs = (EnhancedForStatement) forNode.astNode;
    DagNode initialiserDag = getDagChild(forNode.children, fs.getParameter(), "initialiser");
    DagNode exprDag = getDagChild(forNode.children, fs.getExpression(), "expression");
    DagNode repeatingBlock = getDagChild(forNode.children, fs.getBody(), null);
    // move forStatement node after the initialisation & expression nodes
    Rejigger rejigger = hoistNode(dag, forNode, initialiserDag);
    // expression is null for method calls within the same object
    List<ExitEdge> prevNodes = addEdges(dag, initialiserDag, scope);
    DagEdge firstExpressionEdge = null;
    if (prevNodes != null) {
        for (ExitEdge e : prevNodes) {
            e.n2 = exprDag;
            addEdge(e);
            firstExpressionEdge = e;
        }
    }
    prevNodes = addExpressionEdges(dag, exprDag, scope);
    // this is the node we loop back to
    DagNode firstExpressionNode = firstExpressionEdge == null ? rejigger.inEdge.n2 : firstExpressionEdge.n2;
    prevNodes = rejigger.unhoistNode(dag, prevNodes);
    DagEdge forTrue = prevNodes.get(0);
    forTrue.classes.add("enhancedFor");
    forTrue.classes.add("true");
    forTrue.n2 = repeatingBlock;
    addEdge(forTrue);
    LexicalScope newScope = scope.newBreakContinueScope(forNode, firstExpressionNode);
    prevNodes = addEdges(dag, repeatingBlock, newScope);
    for (ExitEdge e : prevNodes) {
        // exprDag
        DagEdge backEdge = dag.addBackEdge(e.n1, firstExpressionNode, null);
        backEdge.classes.add("enhancedFor");
    }
    // the entire for
    prevNodes = new ArrayList<>();
    // prevNodes.addAll(repeatingBlockPrevNodes);  // could add hidden edges here to force the 'after loop' nodes to appear under the for
    // forward edges for any breaks inside the for scoped to this for
    prevNodes.addAll(newScope.breakEdges);
    ExitEdge forFalse = new ExitEdge();
    forFalse.n1 = forNode;
    forFalse.classes.add("enhancedFor");
    forFalse.classes.add("false");
    prevNodes.add(forFalse);
    return prevNodes;
}
Also used : DagNode(com.randomnoun.build.javaToGraphviz.dag.DagNode) ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) DagEdge(com.randomnoun.build.javaToGraphviz.dag.DagEdge)

Example 5 with DagNode

use of com.randomnoun.build.javaToGraphviz.dag.DagNode in project java-to-graphviz by randomnoun.

the class ControlFlowEdger method addLabeledStatementEdges.

private List<ExitEdge> addLabeledStatementEdges(Dag dag, DagNode labeledStatementNode, LexicalScope scope) {
    // remember this statement in the lexical scope so we can break/continue to it
    LabeledStatement ls = (LabeledStatement) labeledStatementNode.astNode;
    DagNode c = getDagChild(labeledStatementNode.children, ls.getBody(), null);
    String label = ls.getLabel() == null ? null : ls.getLabel().toString();
    addEdge(labeledStatementNode, c);
    c.javaLabel = label;
    List<ExitEdge> lsPrevNodes = addEdges(dag, c, scope);
    List<ExitEdge> prevNodes = new ArrayList<ExitEdge>();
    // Y branch
    prevNodes.addAll(lsPrevNodes);
    return prevNodes;
}
Also used : DagNode(com.randomnoun.build.javaToGraphviz.dag.DagNode) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge) ArrayList(java.util.ArrayList)

Aggregations

DagNode (com.randomnoun.build.javaToGraphviz.dag.DagNode)55 ExitEdge (com.randomnoun.build.javaToGraphviz.dag.ExitEdge)33 DagEdge (com.randomnoun.build.javaToGraphviz.dag.DagEdge)20 DagSubgraph (com.randomnoun.build.javaToGraphviz.dag.DagSubgraph)11 ArrayList (java.util.ArrayList)8 DagElement (com.randomnoun.build.javaToGraphviz.dom.DagElement)6 GvComment (com.randomnoun.build.javaToGraphviz.comment.GvComment)3 ExceptionErrorHandler (com.randomnoun.build.javaToGraphviz.dom.StylesheetApplier.ExceptionErrorHandler)3 CSSOMParser (com.steadystate.css.parser.CSSOMParser)3 ASTNode (org.eclipse.jdt.core.dom.ASTNode)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)3 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)3 InstanceofExpression (org.eclipse.jdt.core.dom.InstanceofExpression)3 CommentText (com.randomnoun.build.javaToGraphviz.comment.CommentText)2 GvEndGraphComment (com.randomnoun.build.javaToGraphviz.comment.GvEndGraphComment)2 GvEndSubgraphComment (com.randomnoun.build.javaToGraphviz.comment.GvEndSubgraphComment)2 GvGraphComment (com.randomnoun.build.javaToGraphviz.comment.GvGraphComment)2 GvKeepNodeComment (com.randomnoun.build.javaToGraphviz.comment.GvKeepNodeComment)2 GvLiteralComment (com.randomnoun.build.javaToGraphviz.comment.GvLiteralComment)2