use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class BLangPackageBuilder method getExpressionsInTemplate.
// Private methods
private List<BLangExpression> getExpressionsInTemplate(DiagnosticPos pos, Set<Whitespace> ws, Stack<String> precedingTextFragments, String endingText, NodeKind targetStrExprKind) {
List<BLangExpression> expressions = new ArrayList<>();
endingText = endingText == null ? "" : StringEscapeUtils.unescapeJava(endingText);
addLiteralValue(pos, ws, TypeTags.STRING, endingText);
expressions.add((BLangExpression) exprNodeStack.pop());
while (!precedingTextFragments.empty()) {
expressions.add((BLangExpression) exprNodeStack.pop());
String textFragment = precedingTextFragments.pop();
textFragment = textFragment == null ? "" : StringEscapeUtils.unescapeJava(textFragment);
addLiteralValue(pos, ws, TypeTags.STRING, textFragment);
expressions.add((BLangExpression) exprNodeStack.pop());
}
Collections.reverse(expressions);
return expressions;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addThrowStmt.
public void addThrowStmt(DiagnosticPos poc, Set<Whitespace> ws) {
ExpressionNode throwExpr = this.exprNodeStack.pop();
BLangThrow throwNode = (BLangThrow) TreeBuilder.createThrowNode();
throwNode.pos = poc;
throwNode.addWS(ws);
throwNode.expr = (BLangExpression) throwExpr;
addStmtToCurrentBlock(throwNode);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addExpressionStmt.
public void addExpressionStmt(DiagnosticPos pos, Set<Whitespace> ws) {
BLangExpressionStmt exprStmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
exprStmt.pos = pos;
exprStmt.addWS(ws);
exprStmt.expr = (BLangExpression) exprNodeStack.pop();
addStmtToCurrentBlock(exprStmt);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addRetryCountExpression.
public void addRetryCountExpression() {
BLangTransaction transaction = (BLangTransaction) transactionNodeStack.peek();
transaction.retryCount = (BLangExpression) exprNodeStack.pop();
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createTernaryExpr.
public void createTernaryExpr(DiagnosticPos pos, Set<Whitespace> ws) {
BLangTernaryExpr ternaryExpr = (BLangTernaryExpr) TreeBuilder.createTernaryExpressionNode();
ternaryExpr.pos = pos;
ternaryExpr.addWS(ws);
ternaryExpr.elseExpr = (BLangExpression) exprNodeStack.pop();
ternaryExpr.thenExpr = (BLangExpression) exprNodeStack.pop();
ternaryExpr.expr = (BLangExpression) exprNodeStack.pop();
if (ternaryExpr.expr.getKind() == NodeKind.TERNARY_EXPR) {
// Re-organizing ternary expression tree if there nested ternary expressions.
BLangTernaryExpr root = (BLangTernaryExpr) ternaryExpr.expr;
BLangTernaryExpr parent = root;
while (parent.elseExpr.getKind() == NodeKind.TERNARY_EXPR) {
parent = (BLangTernaryExpr) parent.elseExpr;
}
ternaryExpr.expr = parent.elseExpr;
parent.elseExpr = ternaryExpr;
ternaryExpr = root;
}
addExpressionNode(ternaryExpr);
}
Aggregations