Search in sources :

Example 11 with Block

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

the class FGUtils method isCFContainer.

/**
 * @return true iff the given {@link ControlFlowElement} is a container such as a function's body.
 */
public static boolean isCFContainer(EObject cfe) {
    boolean isScript = cfe instanceof Script;
    boolean isBlock = cfe instanceof Block;
    boolean isExpression = cfe instanceof Expression;
    boolean isBindingPattern = cfe instanceof BindingPattern;
    if (!isScript && !isBlock && !isExpression && !isBindingPattern) {
        return false;
    }
    EObject cfeContainer = cfe.eContainer();
    EObject cfeContainer2 = (cfeContainer == null) ? null : cfeContainer.eContainer();
    boolean containerIsFunctionDeclaration = cfeContainer instanceof FunctionDeclaration;
    boolean containerIsFunctionDefinition = cfeContainer instanceof FunctionDefinition;
    boolean containerIsFieldAccessor = cfeContainer instanceof FieldAccessor;
    boolean containerIsFormalParameter = cfeContainer instanceof FormalParameter;
    boolean containerIsFieldDeclaration = cfeContainer instanceof N4FieldDeclaration;
    boolean containerIsAnnotationArgument = cfeContainer instanceof AnnotationArgument;
    boolean containerIsLiteralOrComputedPropertyName = cfeContainer instanceof LiteralOrComputedPropertyName;
    boolean containerIsExportSpecifier = cfeContainer instanceof ExportSpecifier;
    boolean containerIsExportDeclaration = cfeContainer instanceof ExportDeclaration;
    boolean containerIsN4ClassDefinition = cfeContainer instanceof N4ClassDefinition;
    boolean container2IsN4FieldDeclaration = cfeContainer2 instanceof N4FieldDeclaration;
    boolean isCFContainer = false;
    isCFContainer |= isScript;
    isCFContainer |= isBlock && containerIsFunctionDeclaration;
    isCFContainer |= isBlock && containerIsFunctionDefinition;
    isCFContainer |= isBlock && containerIsFieldAccessor;
    isCFContainer |= isBindingPattern && containerIsFormalParameter;
    isCFContainer |= isExpression && containerIsFormalParameter;
    isCFContainer |= isExpression && containerIsFieldDeclaration;
    isCFContainer |= isExpression && containerIsAnnotationArgument;
    isCFContainer |= isExpression && containerIsLiteralOrComputedPropertyName && container2IsN4FieldDeclaration;
    isCFContainer |= isExpression && containerIsN4ClassDefinition;
    isCFContainer |= isExpression && containerIsExportSpecifier;
    isCFContainer |= isExpression && containerIsExportDeclaration;
    return isCFContainer;
}
Also used : FormalParameter(org.eclipse.n4js.n4JS.FormalParameter) Script(org.eclipse.n4js.n4JS.Script) BindingPattern(org.eclipse.n4js.n4JS.BindingPattern) N4FieldDeclaration(org.eclipse.n4js.n4JS.N4FieldDeclaration) ExportSpecifier(org.eclipse.n4js.n4JS.ExportSpecifier) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) FieldAccessor(org.eclipse.n4js.n4JS.FieldAccessor) AnnotationArgument(org.eclipse.n4js.n4JS.AnnotationArgument) N4ClassDefinition(org.eclipse.n4js.n4JS.N4ClassDefinition) FunctionDeclaration(org.eclipse.n4js.n4JS.FunctionDeclaration) Expression(org.eclipse.n4js.n4JS.Expression) EObject(org.eclipse.emf.ecore.EObject) CatchBlock(org.eclipse.n4js.n4JS.CatchBlock) Block(org.eclipse.n4js.n4JS.Block) FunctionDefinition(org.eclipse.n4js.n4JS.FunctionDefinition) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)

Example 12 with Block

use of org.eclipse.n4js.n4JS.Block 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

Block (org.eclipse.n4js.n4JS.Block)12 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)4 CatchBlock (org.eclipse.n4js.n4JS.CatchBlock)3 EObject (org.eclipse.emf.ecore.EObject)2 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)2 ExportDeclaration (org.eclipse.n4js.n4JS.ExportDeclaration)2 ExportSpecifier (org.eclipse.n4js.n4JS.ExportSpecifier)2 ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)2 FormalParameter (org.eclipse.n4js.n4JS.FormalParameter)2 FunctionDeclaration (org.eclipse.n4js.n4JS.FunctionDeclaration)2 LiteralOrComputedPropertyName (org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)2 N4FieldDeclaration (org.eclipse.n4js.n4JS.N4FieldDeclaration)2 ReturnStatement (org.eclipse.n4js.n4JS.ReturnStatement)2 Script (org.eclipse.n4js.n4JS.Script)2 EPackage (org.eclipse.emf.ecore.EPackage)1 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)1 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)1 Node (org.eclipse.n4js.flowgraphs.model.Node)1 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)1