use of org.eclipse.n4js.flowgraphs.ControlFlowType in project n4js by eclipse.
the class FlowgraphsXpectMethod method filterByControlFlowType.
private void filterByControlFlowType(ControlFlowElement start, Collection<ControlFlowElement> succList, ControlFlowType cfType) {
if (cfType == null)
return;
for (Iterator<ControlFlowElement> succIt = succList.iterator(); succIt.hasNext(); ) {
N4JSFlowAnalyser flowAnalyzer = getFlowAnalyzer(start);
Set<ControlFlowType> currCFTypes = flowAnalyzer.getControlFlowTypeToSuccessors(start, succIt.next());
if (!currCFTypes.contains(cfType)) {
succIt.remove();
}
}
}
use of org.eclipse.n4js.flowgraphs.ControlFlowType in project n4js by eclipse.
the class FlowgraphsXpectMethod method succs.
/**
* This xpect method can evaluate the direct successors of a code element. The successors can be limited when
* specifying the edge type.
* <p>
* <b>Attention:</b> The type parameter <i>does not</i> work on self loops!
*/
@ParameterParser(syntax = "('type' arg1=STRING)? ('at' arg2=OFFSET)?")
@Xpect
public void succs(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, String type, IEObjectCoveringRegion offset) {
ControlFlowType cfType = getControlFlowType(type);
ControlFlowElement cfe = getCFE(offset);
Set<ControlFlowElement> succs = getFlowAnalyzer(cfe).getSuccessorsSkipInternal(cfe);
filterByControlFlowType(cfe, succs, cfType);
List<String> succTexts = new LinkedList<>();
for (ControlFlowElement succ : succs) {
String succText = FGUtils.getSourceText(succ);
succTexts.add(succText);
}
expectation.assertEquals(succTexts);
}
use of org.eclipse.n4js.flowgraphs.ControlFlowType in project n4js by eclipse.
the class FlowgraphsXpectMethod method preds.
/**
* This xpect method can evaluate the direct predecessors of a code element. The predecessors can be limited when
* specifying the edge type.
* <p>
* <b>Attention:</b> The type parameter <i>does not</i> work on self loops!
*/
@ParameterParser(syntax = "('type' arg1=STRING)? ('at' arg2=OFFSET)?")
@Xpect
public void preds(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, String type, IEObjectCoveringRegion offset) {
ControlFlowType cfType = getControlFlowType(type);
ControlFlowElement cfe = getCFE(offset);
Set<ControlFlowElement> preds = getFlowAnalyzer(cfe).getPredecessorsSkipInternal(cfe);
filterByControlFlowType(cfe, preds, cfType);
List<String> predTexts = new LinkedList<>();
for (ControlFlowElement succ : preds) {
String predText = FGUtils.getSourceText(succ);
predTexts.add(predText);
}
expectation.assertEquals(predTexts);
}
use of org.eclipse.n4js.flowgraphs.ControlFlowType in project n4js by eclipse.
the class CFEdge method setColor.
/**
* Sets the color of the {@link GC} depending on the edge type.
*/
void setColor(GC gc) {
Display displ = Display.getCurrent();
Color color = GraphUtils.getColor(50, 50, 50);
if (isDead || cfTypes.contains(ControlFlowType.DeadCode)) {
color = displ.getSystemColor(SWT.COLOR_GRAY);
} else {
for (ControlFlowType cfType : cfTypes) {
switch(cfType) {
case LoopEnter:
case LoopReenter:
case LoopInfinite:
case Break:
case Continue:
case Return:
color = displ.getSystemColor(SWT.COLOR_BLUE);
break;
case Throw:
color = displ.getSystemColor(SWT.COLOR_RED);
break;
default:
break;
}
}
}
gc.setForeground(color);
}
use of org.eclipse.n4js.flowgraphs.ControlFlowType in project n4js by eclipse.
the class CFEdge method drawLabel.
/**
* Draws the label between jumping control flow elements.
*/
void drawLabel(GC gc, Point p) {
label = "";
for (ControlFlowType cfType : cfTypes) {
switch(cfType) {
case Break:
case Continue:
case Return:
case Throw:
case LoopEnter:
case LoopReenter:
case LoopInfinite:
if (!label.isEmpty())
label += "|";
label += cfType.name();
break;
default:
}
}
org.eclipse.swt.graphics.Point size = gc.stringExtent(label);
float x = p.x - size.x / 2;
float y = p.y - size.y / 2;
GraphUtils.drawString(gc, label, x, y);
}
Aggregations