use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class DeadCodeValidator method getStatementDescription.
private String getStatementDescription(DeadCodeRegion deadCodeRegion) {
ControlFlowElement reachablePred = deadCodeRegion.getReachablePredecessor();
if (reachablePred == null) {
return null;
}
boolean addKeyword = false;
addKeyword |= reachablePred instanceof ReturnStatement;
addKeyword |= reachablePred instanceof BreakStatement;
addKeyword |= reachablePred instanceof ContinueStatement;
addKeyword |= reachablePred instanceof ThrowStatement;
if (addKeyword) {
String keyword = keywordProvider.keyword(reachablePred);
if (Strings.isNullOrEmpty(keyword)) {
keyword = reachablePred.eClass().getName();
}
return keyword;
}
return null;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement 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.n4js.n4JS.ControlFlowElement 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.n4JS.ControlFlowElement 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.n4JS.ControlFlowElement 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);
}
Aggregations