Search in sources :

Example 66 with BLangBlockStmt

use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addFinallyBlock.

public void addFinallyBlock(DiagnosticPos poc, Set<Whitespace> ws) {
    BLangBlockStmt blockNode = (BLangBlockStmt) this.blockNodeStack.pop();
    BLangTryCatchFinally rootTry = tryCatchFinallyNodesStack.peek();
    rootTry.finallyBody = blockNode;
    rootTry.addWS(ws);
    blockNode.pos = poc;
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally)

Example 67 with BLangBlockStmt

use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.

the class BlockStatementScopeResolver method getTransactionBlockComponentEndLine.

private int getTransactionBlockComponentEndLine(BLangTransaction bLangTransaction, BLangBlockStmt bLangBlockStmt) {
    BLangBlockStmt transactionBody = bLangTransaction.transactionBody;
    BLangBlockStmt failedBody = bLangTransaction.onRetryBody;
    List<BLangBlockStmt> components = new ArrayList<>();
    components.add(transactionBody);
    components.add(failedBody);
    components.sort(Comparator.comparing(component -> {
        if (component != null) {
            return CommonUtil.toZeroBasedPosition(component.getPosition()).getEndLine();
        } else {
            return -1;
        }
    }));
    int blockStmtIndex = components.indexOf(bLangBlockStmt);
    if (blockStmtIndex == components.size() - 1) {
        return CommonUtil.toZeroBasedPosition(bLangTransaction.getPosition()).eLine;
    } else if (components.get(blockStmtIndex + 1) != null) {
        return CommonUtil.toZeroBasedPosition(components.get(blockStmtIndex + 1).getPosition()).sLine;
    } else {
        // Ideally should not invoke this
        return -1;
    }
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Name(org.wso2.ballerinalang.compiler.util.Name) ArrayList(java.util.ArrayList) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) TreeVisitor(org.ballerinalang.langserver.completions.TreeVisitor) List(java.util.List) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) Node(org.ballerinalang.model.tree.Node) Map(java.util.Map) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) Comparator(java.util.Comparator) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) ArrayList(java.util.ArrayList)

Example 68 with BLangBlockStmt

use of org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt in project ballerina by ballerina-lang.

the class BlockStatementScopeResolver method isWithinScopeAfterLastChildNode.

private boolean isWithinScopeAfterLastChildNode(TreeVisitor treeVisitor, boolean lastChild, int nodeELine, int nodeECol, int line, int col, Node node) {
    if (!lastChild) {
        return false;
    } else {
        BLangBlockStmt bLangBlockStmt = treeVisitor.getBlockStmtStack().peek();
        Node blockOwner = treeVisitor.getBlockOwnerStack().peek();
        int blockOwnerELine = this.getBlockOwnerELine(blockOwner, bLangBlockStmt);
        int blockOwnerECol = this.getBlockOwnerECol(blockOwner, bLangBlockStmt);
        boolean isWithinScope = (line < blockOwnerELine || (line == blockOwnerELine && col <= blockOwnerECol)) && (line > nodeELine || (line == nodeELine && col > nodeECol));
        if (isWithinScope) {
            treeVisitor.setPreviousNode((BLangNode) node);
        }
        return isWithinScope;
    }
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) Node(org.ballerinalang.model.tree.Node)

Aggregations

BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)33 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)22 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)19 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)16 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)12 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)8 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)8 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)7 BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)6 BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)6 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)6 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)6 Name (org.wso2.ballerinalang.compiler.util.Name)6 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)5 BLangMatchStmtPatternClause (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause)5 ArrayList (java.util.ArrayList)4 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)4 BLangForeach (org.wso2.ballerinalang.compiler.tree.statements.BLangForeach)4 Whitespace (org.ballerinalang.model.Whitespace)3