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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations