use of org.apache.groovy.parser.antlr4.GroovyParser.SwitchBlockStatementGroupContext in project groovy by apache.
the class AstBuilder method visitSwitchBlockStatementGroup.
@Override
@SuppressWarnings("unchecked")
public List<Statement> visitSwitchBlockStatementGroup(final SwitchBlockStatementGroupContext ctx) {
int labelCnt = ctx.switchLabel().size();
List<Token> firstLabelHolder = new ArrayList<>(1);
return (List<Statement>) ctx.switchLabel().stream().map(e -> (Object) this.visitSwitchLabel(e)).reduce(new ArrayList<Statement>(4), (r, e) -> {
List<Statement> statementList = (List<Statement>) r;
Tuple2<Token, Expression> tuple = (Tuple2<Token, Expression>) e;
boolean isLast = labelCnt - 1 == statementList.size();
switch(tuple.getV1().getType()) {
case CASE:
{
if (!asBoolean(statementList)) {
firstLabelHolder.add(tuple.getV1());
}
statementList.add(configureAST(new CaseStatement(tuple.getV2(), // check whether processing the last label. if yes, block statement should be attached.
isLast ? this.visitBlockStatements(ctx.blockStatements()) : EmptyStatement.INSTANCE), firstLabelHolder.get(0)));
break;
}
case DEFAULT:
{
BlockStatement blockStatement = this.visitBlockStatements(ctx.blockStatements());
blockStatement.putNodeMetaData(IS_SWITCH_DEFAULT, true);
statementList.add(// this.configureAST(blockStatement, tuple.getKey())
blockStatement);
break;
}
}
return statementList;
});
}
Aggregations