use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitExpr_new_array.
@Override
public Code visitExpr_new_array(Expr_new_arrayContext ctx) {
SegmentCode code = (SegmentCode) ctx.type().accept(this);
if (code.getKlass().isArray()) {
throw reportError("Cannot specify an array dimension after an empty dimension", ctx.type());
}
StringBuilder typeSource = new StringBuilder(code.toString());
// ็ๆไปฃ็
StringBuilder source = new StringBuilder(32);
source.append("(new ").append(code.toString());
for (ExpressionContext expression : ctx.expression()) {
SegmentCode c = (SegmentCode) expression.accept(this);
if (!ClassUtils.isAssignable(Integer.TYPE, c.getKlass())) {
throw reportError("Type mismatch: cannot convert from " + c.getKlassName() + " to int.", expression);
}
source.append('[').append(c.toString()).append(']');
typeSource.append("[]");
}
source.append(')');
TypedKlass resultKlass = resolver.resolveTypedKlass(typeSource.toString());
return new SegmentCode(resultKlass, source.toString(), ctx);
}
use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitDefine_expression.
@Override
public Code visitDefine_expression(Define_expressionContext ctx) {
SegmentCode code = (SegmentCode) ctx.type().accept(this);
String name = assert_java_identifier(ctx.IDENTIFIER(), true);
return new DefineExpressionCode(code.getTypedKlass(), name, ctx);
}
use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitExpr_class_cast.
@Override
public Code visitExpr_class_cast(Expr_class_castContext ctx) {
SegmentCode code = (SegmentCode) ctx.type().accept(this);
Code expr_code = ctx.expression().accept(this);
String source = "((" + code.toString() + ")" + expr_code.toString() + ")";
return new SegmentCode(code.getTypedKlass(), source, ctx);
}
use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitExpr_hash_map.
@Override
public Code visitExpr_hash_map(Expr_hash_mapContext ctx) {
String source = "Collections.EMPTY_MAP";
Hash_map_entry_listContext hash_map_entry_list = ctx.hash_map_entry_list();
if (hash_map_entry_list != null) {
Code code = hash_map_entry_list.accept(this);
source = "JetUtils.asMap(" + code.toString() + ")";
}
return new SegmentCode(Map.class, source, ctx);
}
use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitExpr_instanceof.
@Override
public Code visitExpr_instanceof(Expr_instanceofContext ctx) {
SegmentCode lhs = (SegmentCode) ctx.expression().accept(this);
SegmentCode rhs = (SegmentCode) ctx.type().accept(this);
if (!ClassUtils.isAssignable(lhs.getKlass(), rhs.getKlass()) && !ClassUtils.isAssignable(lhs.getKlass(), rhs.getKlass())) {
throw reportError("Incompatible conditional operand types " + lhs.getKlassName() + " and " + rhs.getKlassName(), ctx.getChild(1));
}
String source = "(" + lhs.toString() + " instanceof " + rhs.toString() + ")";
return new SegmentCode(Boolean.TYPE, source, ctx);
}
Aggregations