Search in sources :

Example 1 with ExitEdge

use of com.randomnoun.build.javaToGraphviz.dag.ExitEdge 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 ExitEdge

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

the class ControlFlowEdger method addThrowEdges.

// a throw will add an edge to throwEdges only
// (and returns an empty list as we won't have a normal exit edge)
private List<ExitEdge> addThrowEdges(Dag dag, DagNode breakNode, LexicalScope scope) {
    ExitEdge e = new ExitEdge();
    // e.label = "throw";
    e.n1 = breakNode;
    // e.gvAttributes.put("color", "purple");
    e.classes.add("throw");
    scope.throwEdges.add(e);
    return Collections.emptyList();
}
Also used : ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge)

Example 3 with ExitEdge

use of com.randomnoun.build.javaToGraphviz.dag.ExitEdge 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 4 with ExitEdge

use of com.randomnoun.build.javaToGraphviz.dag.ExitEdge 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 5 with ExitEdge

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

the class ControlFlowEdger method addMethodReferenceEdges.

private List<ExitEdge> addMethodReferenceEdges(Dag dag, DagNode thisNode, LexicalScope scope) {
    // CreationReference or ExpressionMethodReference or SuperMethodReference or TypeMethodReference
    MethodReference mr = (MethodReference) thisNode.astNode;
    // qualified reference
    thisNode.gvAttributes.put("name", mr.toString());
    ExitEdge e = new ExitEdge();
    e.n1 = thisNode;
    return Collections.singletonList(e);
}
Also used : ExitEdge(com.randomnoun.build.javaToGraphviz.dag.ExitEdge) MethodReference(org.eclipse.jdt.core.dom.MethodReference)

Aggregations

ExitEdge (com.randomnoun.build.javaToGraphviz.dag.ExitEdge)43 DagNode (com.randomnoun.build.javaToGraphviz.dag.DagNode)33 DagEdge (com.randomnoun.build.javaToGraphviz.dag.DagEdge)13 ArrayList (java.util.ArrayList)5 DagSubgraph (com.randomnoun.build.javaToGraphviz.dag.DagSubgraph)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 CastExpression (org.eclipse.jdt.core.dom.CastExpression)2 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)2 EnhancedForStatement (org.eclipse.jdt.core.dom.EnhancedForStatement)2 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)2 InstanceofExpression (org.eclipse.jdt.core.dom.InstanceofExpression)2 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)2 PostfixExpression (org.eclipse.jdt.core.dom.PostfixExpression)2 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)2 SuperConstructorInvocation (org.eclipse.jdt.core.dom.SuperConstructorInvocation)2 SuperFieldAccess (org.eclipse.jdt.core.dom.SuperFieldAccess)2 SuperMethodInvocation (org.eclipse.jdt.core.dom.SuperMethodInvocation)2 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)2 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)2 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)2