use of org.beetl.core.statement.SwitchStatement in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseSwitch.
protected SwitchStatement parseSwitch(SiwchStContext sctx) {
// this.pbCtx.enterBlock();
// this.pbCtx.current.canStopContinueBreakFlag = true;
ExpressionContext ect = sctx.parExpression().expression();
Expression exp = this.parseExpress(ect);
List<SwitchBlockStatementGroupContext> list = sctx.switchBlock().switchBlockStatementGroup();
LinkedHashMap<Expression, BlockStatement> condtionsStatementsMap = new LinkedHashMap<Expression, BlockStatement>();
List<Expression> conditionList = new ArrayList<Expression>();
BlockStatement defaultBlock = null;
for (SwitchBlockStatementGroupContext group : list) {
List<SwitchLabelContext> labels = group.switchLabel();
List<StatementContext> stats = group.statement();
BlockStatement block = stats != null ? this.parseBlock(stats, group) : null;
for (SwitchLabelContext label : labels) {
Expression caseExp = this.parseExpress(label.expression());
if (caseExp == null) {
// default
defaultBlock = block;
break;
} else {
conditionList.add(caseExp);
condtionsStatementsMap.put(caseExp, block);
}
}
}
SwitchStatement switchStat = new SwitchStatement(exp, condtionsStatementsMap, defaultBlock, this.getBTToken(sctx.getStart()));
return switchStat;
}
Aggregations