Search in sources :

Example 1 with ControlFlowType

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();
        }
    }
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) N4JSFlowAnalyser(org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 2 with ControlFlowType

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);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 3 with ControlFlowType

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);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 4 with ControlFlowType

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);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) Color(org.eclipse.swt.graphics.Color) Display(org.eclipse.swt.widgets.Display)

Example 5 with ControlFlowType

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);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType)

Aggregations

ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)9 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)5 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)4 Node (org.eclipse.n4js.flowgraphs.model.Node)4 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)3 LinkedList (java.util.LinkedList)2 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)2 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)2 Xpect (org.eclipse.xpect.runner.Xpect)2 N4JSFlowAnalyser (org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser)1 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)1 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)1 JumpToken (org.eclipse.n4js.flowgraphs.model.JumpToken)1 Block (org.eclipse.n4js.n4JS.Block)1 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)1 Color (org.eclipse.swt.graphics.Color)1 Display (org.eclipse.swt.widgets.Display)1