use of org.eclipse.n4js.flowgraphs.model.ControlFlowEdge in project n4js by eclipse.
the class FinallyFlowContext method findFinallyBlockContextEdge.
/**
* This method searches all FinallyBlock-entry/exit edges E to chose the correct next following edges. The following
* rules are implemented:
* <ul>
* <li/>If there exists no next edge with a context, then null is returned.
* <li/>If there exists a next edge with a context, and the current {@link EdgeGuide} instance has no context that
* matches with one of the next edges, then all edges without context are returned.
* <li/>If there exists a next edge with a context, and the current {@link EdgeGuide} instance has a context that
* matches with one of the next edges, the matching edge is returned.
* </ul>
*/
private List<ControlFlowEdge> findFinallyBlockContextEdge(List<ControlFlowEdge> nextEdges) {
LinkedList<ControlFlowEdge> fbContextFreeEdges = new LinkedList<>();
Map<JumpToken, ControlFlowEdge> contextEdges = new HashMap<>();
mapFinallyBlockContextEdges(nextEdges, fbContextFreeEdges, contextEdges);
if (contextEdges.isEmpty()) {
return Lists.newLinkedList();
}
ControlFlowEdge matchedFBContextEdge = null;
Map.Entry<JumpToken, ControlFlowEdge> otherEdgePair = null;
for (Map.Entry<JumpToken, ControlFlowEdge> ctxEdgePair : contextEdges.entrySet()) {
JumpToken fbContext = ctxEdgePair.getKey();
otherEdgePair = ctxEdgePair;
if (finallyBlockContexts.contains(fbContext)) {
matchedFBContextEdge = ctxEdgePair.getValue();
}
}
if (matchedFBContextEdge != null) {
return Collections2.newLinkedList(matchedFBContextEdge);
} else if (!fbContextFreeEdges.isEmpty()) {
return fbContextFreeEdges;
} else if (otherEdgePair != null) {
LinkedList<ControlFlowEdge> contextAndDeadEdges = new LinkedList<>();
contextAndDeadEdges.add(otherEdgePair.getValue());
for (ControlFlowEdge edge : nextEdges) {
if (edge.cfType == ControlFlowType.DeadCode) {
contextAndDeadEdges.add(edge);
}
}
return contextAndDeadEdges;
}
return null;
}
Aggregations