Search in sources :

Example 6 with ExpressionStatement

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;
}
Also used : Script(org.eclipse.n4js.n4JS.Script) EObject(org.eclipse.emf.ecore.EObject) ExpressionStatement(org.eclipse.n4js.n4JS.ExpressionStatement) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Aggregations

ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)6 Expression (org.eclipse.n4js.n4JS.Expression)4 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)4 Statement (org.eclipse.n4js.n4JS.Statement)4 SuperLiteral (org.eclipse.n4js.n4JS.SuperLiteral)4 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 FunctionExpression (org.eclipse.n4js.n4JS.FunctionExpression)2 Script (org.eclipse.n4js.n4JS.Script)2 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)1 Annotation (org.eclipse.n4js.n4JS.Annotation)1 AnnotationList (org.eclipse.n4js.n4JS.AnnotationList)1 Argument (org.eclipse.n4js.n4JS.Argument)1 ArrayBindingPattern (org.eclipse.n4js.n4JS.ArrayBindingPattern)1 ArrayElement (org.eclipse.n4js.n4JS.ArrayElement)1 ArrayLiteral (org.eclipse.n4js.n4JS.ArrayLiteral)1 ArrayPadding (org.eclipse.n4js.n4JS.ArrayPadding)1 ArrowFunction (org.eclipse.n4js.n4JS.ArrowFunction)1 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)1