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;
}
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;
}
}
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;
}
}
Aggregations