use of org.eclipse.n4js.n4JS.ControlFlowElement 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.n4JS.ControlFlowElement in project n4js by eclipse.
the class FlowgraphsXpectMethod method performBranchAnalysis.
private AllBranchPrintVisitor performBranchAnalysis(IEObjectCoveringRegion offset, String directionName, IEObjectCoveringRegion referenceOffset) {
EObjectCoveringRegion offsetImpl = (EObjectCoveringRegion) offset;
EObjectCoveringRegion referenceOffsetImpl = (EObjectCoveringRegion) referenceOffset;
ControlFlowElement startCFE = getCFEWithReference(offsetImpl, referenceOffsetImpl);
ControlFlowElement referenceCFE = getCFE(referenceOffset);
TraverseDirection direction = getDirection(directionName);
ControlFlowElement container = FGUtils.getCFContainer(referenceCFE);
AllBranchPrintVisitor appw = new AllBranchPrintVisitor(container, startCFE, direction);
getFlowAnalyzer(referenceCFE).accept(appw);
return appw;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement 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);
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class FGUtils method getAllContainersOfTypeUptoCFContainer.
/**
* Returns all containers of the given {@link ControlFlowElement} that are assignable from the given class. The
* results are all in the same container like the given cfe is.
*/
@SuppressWarnings("unchecked")
public static <T> LinkedList<T> getAllContainersOfTypeUptoCFContainer(ControlFlowElement cfe, Class<T> clazz) {
LinkedList<T> results = new LinkedList<>();
ControlFlowElement curCFE = cfe;
while (curCFE != null && !isCFContainer(curCFE)) {
if (clazz.isAssignableFrom(curCFE.getClass())) {
results.add((T) curCFE);
}
curCFE = getContainer(curCFE);
}
return results;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class SuccessorPredecessorAnalysis method getPredecessors.
/**
* see {@link N4JSFlowAnalyser#getPredecessors(ControlFlowElement)}
*/
public Set<ControlFlowElement> getPredecessors(ControlFlowElement cfe) {
NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Backward();
Node nextNode = getNextNode(cfe, false, nextEdgesProvider);
Set<ControlFlowElement> predecessors = getNextCFEs(nextEdgesProvider, cfe, nextNode);
return predecessors;
}
Aggregations