Search in sources :

Example 6 with BLangTransaction

use of org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction 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)

Aggregations

BLangTransaction (org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction)5 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)1 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)1 CommonUtil (org.ballerinalang.langserver.common.utils.CommonUtil)1 TreeVisitor (org.ballerinalang.langserver.completions.TreeVisitor)1 Node (org.ballerinalang.model.tree.Node)1 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)1 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)1 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)1 BLangCatch (org.wso2.ballerinalang.compiler.tree.statements.BLangCatch)1 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)1