use of org.eclipse.n4js.n4JS.ExpressionStatement in project n4js by eclipse.
the class DeadCodeAnalyser method getReachableContainer.
/**
* Finds the nearest reachable {@link Block} of the given {@link ControlFlowElement}
*/
private EObject getReachableContainer(Set<ControlFlowElement> unreachableElems, ControlFlowElement unreachableElem, Set<ControlFlowElement> moreUnreachableElems) {
EObject elemContainer = unreachableElem.eContainer();
if (elemContainer instanceof ExpressionStatement) {
moreUnreachableElems.add((ExpressionStatement) elemContainer);
}
EObject block = EcoreUtil2.getContainerOfType(unreachableElem, Block.class);
if (block == null) {
block = EcoreUtil2.getContainerOfType(unreachableElem, Script.class);
}
EObject blockContainer = block.eContainer();
boolean isDeadContainer = blockContainer instanceof ControlFlowElement;
isDeadContainer &= isDeadContainer && FGUtils.isControlStatement((ControlFlowElement) blockContainer);
isDeadContainer &= isDeadContainer && isDeadCode((ControlFlowElement) blockContainer);
if (isDeadContainer) {
ControlFlowElement cfe = (ControlFlowElement) blockContainer;
moreUnreachableElems.add(cfe);
return getReachableContainer(unreachableElems, cfe, moreUnreachableElems);
}
return block;
}
Aggregations