use of org.beetl.core.statement.JsonMapExpression in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseJson.
protected Expression parseJson(JsonContext ctx) {
if (ctx.LEFT_SQBR() != null) {
// array
JsonArrayExpression json = null;
List<ExpressionContext> listCtx = ctx.expression();
if (listCtx.size() == 0) {
json = new JsonArrayExpression(Collections.EMPTY_LIST, this.getBTToken(ctx.LEFT_SQBR().getSymbol()));
} else {
List<Expression> list = new ArrayList<Expression>(listCtx.size());
for (ExpressionContext expCtx : listCtx) {
list.add(this.parseExpress(expCtx));
}
json = new JsonArrayExpression(list, this.getBTToken(ctx.LEFT_SQBR().getSymbol()));
}
return json;
} else {
// map
JsonMapExpression json = null;
List<JsonKeyValueContext> listCtx = ctx.jsonKeyValue();
if (listCtx.size() == 0) {
json = new JsonMapExpression(Collections.EMPTY_MAP, this.getBTToken(ctx.LEFT_BRACE().getSymbol()));
} else {
Map<String, Expression> map = new LinkedHashMap<String, Expression>(listCtx.size());
for (JsonKeyValueContext kvCtx : listCtx) {
String key = null;
if (kvCtx.StringLiteral() != null) {
key = this.getStringValue(kvCtx.StringLiteral().getText());
} else {
key = kvCtx.Identifier().getSymbol().getText();
}
Expression exp = this.parseExpress(kvCtx.expression());
map.put(key, exp);
}
json = new JsonMapExpression(map, this.getBTToken(ctx.LEFT_BRACE().getSymbol()));
}
return json;
}
}
Aggregations