Search in sources :

Example 16 with Statement

use of org.eclipse.n4js.n4JS.Statement in project n4js by eclipse.

the class DeadCodeAnalyser method findPrecedingStatement.

private ControlFlowElement findPrecedingStatement(ControlFlowElement cfe) {
    ControlFlowElement precedingStatement = null;
    Statement stmt = EcoreUtil2.getContainerOfType(cfe, Statement.class);
    if (stmt != null) {
        EObject stmtContainer = stmt.eContainer();
        if (stmtContainer != null && stmtContainer instanceof Block) {
            Block block = (Block) stmtContainer;
            EList<Statement> stmts = block.getStatements();
            int index = stmts.indexOf(stmt);
            if (index > 0) {
                precedingStatement = stmts.get(index - 1);
            }
        }
    }
    return precedingStatement;
}
Also used : ExpressionStatement(org.eclipse.n4js.n4JS.ExpressionStatement) Statement(org.eclipse.n4js.n4JS.Statement) ReturnStatement(org.eclipse.n4js.n4JS.ReturnStatement) EObject(org.eclipse.emf.ecore.EObject) Block(org.eclipse.n4js.n4JS.Block) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Aggregations

Statement (org.eclipse.n4js.n4JS.Statement)16 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)6 ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)6 Expression (org.eclipse.n4js.n4JS.Expression)4 IfStatement (org.eclipse.n4js.n4JS.IfStatement)4 EObject (org.eclipse.emf.ecore.EObject)3 ForStatement (org.eclipse.n4js.n4JS.ForStatement)3 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)3 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)3 SuperLiteral (org.eclipse.n4js.n4JS.SuperLiteral)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 LinkedList (java.util.LinkedList)2 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)2 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)2 Node (org.eclipse.n4js.flowgraphs.model.Node)2 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)2 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)2 DoStatement (org.eclipse.n4js.n4JS.DoStatement)2 IterationStatement (org.eclipse.n4js.n4JS.IterationStatement)2 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)2