use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitExpr_array_list.
@Override
public Code visitExpr_array_list(Expr_array_listContext ctx) {
String source = "Collections.EMPTY_LIST";
Expression_listContext expression_list = ctx.expression_list();
if (expression_list != null) {
Code code = expression_list.accept(this);
source = "Arrays.asList(" + code.toString() + ")";
}
return new SegmentCode(List.class, source, ctx);
}
use of jetbrick.template.parser.code.SegmentCode in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitExpr_identifier.
@Override
public Code visitExpr_identifier(Expr_identifierContext ctx) {
String name = assert_java_identifier(ctx.IDENTIFIER(), false);
// 特殊处理 for 变量
if ("for".equals(name)) {
assert_inside_of_for_directive(ctx, "Local variable \"for\"");
// 强制映射成 JetForStatus $for
// 取出 forStatus 的实际变量名
String forStatus = forStack.peek();
return new SegmentCode(TypedKlass.JetForStatus, forStatus, ctx);
}
// 找到变量的类型
TypedKlass resultKlass = scopeCode.resolve(name, false);
if (resultKlass == null) {
// 没有定义过,继续向上深度查找
resultKlass = scopeCode.resolve(name, true);
// 没有定义过,则查找全局定义
if (resultKlass == null) {
resultKlass = resolver.resolveVariable(name);
}
if (scopeCode.define(name, resultKlass, true)) {
if (resultKlass == TypedKlass.Object) {
//removed unsed warning in 1.2.0
//log.warn("line " + ctx.getStart().getLine() + ": Implicit definition for context variable: " + resultKlass.toString() + " " + name);
}
}
}
return new SegmentCode(resultKlass, name, ctx);
}
Aggregations