use of org.eclipse.xpect.parameter.ParameterParser in project n4js by eclipse.
the class FlowgraphsXpectMethod method allEdges.
/**
* This xpect method can evaluate all edges of the containing function.
*/
@ParameterParser(syntax = "('from' arg1=OFFSET)?")
@Xpect
public void allEdges(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion offset) {
ControlFlowElement cfe = null;
if (offset != null) {
cfe = getCFE(offset);
}
cfe = FGUtils.getCFContainer(cfe);
AllNodesAndEdgesPrintVisitor anaepw = new AllNodesAndEdgesPrintVisitor(cfe);
getFlowAnalyzer(cfe).accept(anaepw);
List<String> pathStrings = anaepw.getAllEdgeStrings();
expectation.assertEquals(pathStrings);
}
use of org.eclipse.xpect.parameter.ParameterParser 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.xpect.parameter.ParameterParser in project n4js by eclipse.
the class FlowgraphsXpectMethod method allMergeBranches.
/**
* This xpect method can evaluate all branches that are merged at the given node name.
*/
@ParameterParser(syntax = "('pleaseNeverUseThisParameterSinceItExistsOnlyToGetAReferenceOffset' arg1=OFFSET)?")
@Xpect
public void allMergeBranches(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion referenceOffset) {
N4JSFlowAnalyserDataRecorder.setEnabled(true);
GraphVisitor dfv = new DummyForwardVisitor();
GraphVisitor dbv = new DummyBackwardVisitor();
ControlFlowElement referenceCFE = getCFE(referenceOffset);
getFlowAnalyzer(referenceCFE).accept(dfv, dbv);
N4JSFlowAnalyserDataRecorder.setEnabled(false);
performBranchAnalysis(referenceOffset, null, referenceOffset);
List<String> edgeStrings = new LinkedList<>();
int groupIdx = 0;
List<Pair<Node, List<ControlFlowEdge>>> mergedEdges = N4JSFlowAnalyserDataRecorder.getMergedEdges();
for (Pair<Node, List<ControlFlowEdge>> pair : mergedEdges) {
Node startNode = pair.getKey();
List<ControlFlowEdge> edges = pair.getValue();
for (ControlFlowEdge edge : edges) {
String c = edge.start == startNode ? "B" : "F";
edgeStrings.add(c + groupIdx + ": " + edge.toString());
}
groupIdx++;
}
Collections.sort(edgeStrings);
expectation.assertEquals(edgeStrings);
}
use of org.eclipse.xpect.parameter.ParameterParser 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.xpect.parameter.ParameterParser in project n4js by eclipse.
the class FlowgraphsXpectMethod method commonPreds.
/**
* This xpect method can evaluate all common predecessors of two {@link ControlFlowElement}s.
*/
@ParameterParser(syntax = "'of' arg1=OFFSET 'and' arg2=OFFSET")
@Xpect
public void commonPreds(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion a, IEObjectCoveringRegion b) {
ControlFlowElement aCFE = getCFE(a);
ControlFlowElement bCFE = getCFE(b);
Set<ControlFlowElement> commonPreds = getFlowAnalyzer(aCFE).getCommonPredecessors(aCFE, bCFE);
List<String> commonPredStrs = new LinkedList<>();
for (ControlFlowElement commonPred : commonPreds) {
String commonPredStr = FGUtils.getSourceText(commonPred);
commonPredStrs.add(commonPredStr);
}
expectation.assertEquals(commonPredStrs);
}
Aggregations