use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method test_el2.
@Test
public void test_el2() throws Exception {
El el = new El("sayhi(name)");
Context ctx = Lang.context();
ctx.set("name", "wendal");
ctx.set("sayhi", getClass().getMethod("sayhi", String.class));
assertEquals("hi,wendal", el.eval(ctx));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class ElFieldMacro method onAfter.
public void onAfter(Connection conn, ResultSet rs, Statement stmt) throws SQLException {
Context context = entityField.getEntity().wrapAsContext(getOperatingObject());
context.set("field", entityField.getColumnName());
context.set("view", entityField.getEntity());
Object value = bin.eval(context);
entityField.setValue(getOperatingObject(), value);
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class AccessOpt method calculate.
public Object calculate() {
//如果直接调用计算方法,那基本上就是直接调用属性了吧...我也不知道^^
Object obj = fetchVar();
if (obj == null) {
throw new ElException("obj is NULL, can't call obj." + right);
}
if (obj instanceof Map) {
Map<?, ?> om = (Map<?, ?>) obj;
if (om.containsKey(right.toString())) {
return om.get(right.toString());
}
}
if (obj instanceof Context) {
Context sc = (Context) obj;
if (sc.has(right.toString())) {
return sc.get(right.toString());
}
}
Mirror<?> me = Mirror.me(obj);
return me.getValue(obj, right.toString());
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El method render.
public static String render(CharSegment seg, Map<String, El> els, Context ctx) {
Context main = Lang.context();
for (String key : seg.keys()) {
El el = els.get(key);
if (el == null)
el = new El(key);
main.putAll(key, el.eval(ctx));
}
return seg.render(main).toString();
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class SegmentsTest method test_issue_722.
@Test
public void test_issue_722() {
Context ctx = Lang.context();
assertEquals("^.+abc.+$", Segments.replace("^.+abc.+$", ctx));
// assertEquals("^.+abc.+${", Segments.replace("^.+abc.+${", ctx));
}
Aggregations