use of org.wso2.ballerinalang.compiler.tree.statements.BLangMatch in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createMatchNode.
public void createMatchNode(DiagnosticPos pos, Set<Whitespace> ws) {
if (this.matchStmtStack == null) {
this.matchStmtStack = new ArrayDeque<>();
}
BLangMatch matchStmt = (BLangMatch) TreeBuilder.createMatchStatement();
matchStmt.pos = pos;
matchStmt.addWS(ws);
matchStmt.patternClauses = new ArrayList<>();
this.matchStmtStack.addFirst(matchStmt);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangMatch in project ballerina by ballerina-lang.
the class Desugar method generateIfElseStmt.
private BLangStatement generateIfElseStmt(BLangMatch matchStmt, BLangVariable matchExprVar) {
List<BLangMatchStmtPatternClause> patterns = matchStmt.patternClauses;
if (patterns.size() == 1) {
return getMatchPatternBody(patterns.get(0), matchExprVar);
}
BLangIf parentIfNode = generateIfElseStmt(patterns.get(0), matchExprVar);
BLangIf currentIfNode = parentIfNode;
for (int i = 1; i < patterns.size(); i++) {
if (i == patterns.size() - 1) {
// This is the last pattern
currentIfNode.elseStmt = getMatchPatternBody(patterns.get(i), matchExprVar);
} else {
currentIfNode.elseStmt = generateIfElseStmt(patterns.get(i), matchExprVar);
currentIfNode = (BLangIf) currentIfNode.elseStmt;
}
}
//
return parentIfNode;
}
Aggregations