use of org.mvel2.integration.PropertyHandler in project mvel by mikebrock.
the class ASMAccessorOptimizer method _finishJIT.
private void _finishJIT() {
if (deferFinish) {
return;
}
if (returnType != null && returnType.isPrimitive()) {
//noinspection unchecked
wrapPrimitive(returnType);
}
if (returnType == void.class) {
assert debug("ACONST_NULL");
mv.visitInsn(ACONST_NULL);
}
assert debug("ARETURN");
mv.visitInsn(ARETURN);
assert debug("\n{METHOD STATS (maxstack=" + stacksize + ")}\n");
// dump advanced debugging if necessary
dumpAdvancedDebugging();
mv.visitMaxs(stacksize, maxlocals);
mv.visitEnd();
mv = cw.visitMethod(ACC_PUBLIC, "getKnownEgressType", "()Ljava/lang/Class;", null, null);
mv.visitCode();
mv.visitLdcInsn(org.mvel2.asm.Type.getType(returnType != null ? returnType : Object.class));
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
if (propNull) {
cw.visitField(ACC_PUBLIC, "nullPropertyHandler", "L" + NAMESPACE + "integration/PropertyHandler;", null, null).visitEnd();
}
if (methNull) {
cw.visitField(ACC_PUBLIC, "nullMethodHandler", "L" + NAMESPACE + "integration/PropertyHandler;", null, null).visitEnd();
}
buildInputs();
if (buildLog != null && buildLog.length() != 0 && expr != null) {
mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLdcInsn(buildLog.toString() + "\n\n## { " + new String(expr) + " }");
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
cw.visitEnd();
}
use of org.mvel2.integration.PropertyHandler in project mvel by mikebrock.
the class ASMAccessorOptimizer method writeOutNullHandler.
private void writeOutNullHandler(Member member, int type) {
assert debug("DUP");
mv.visitInsn(DUP);
Label j = new Label();
assert debug("IFNONNULL : jump");
mv.visitJumpInsn(IFNONNULL, j);
assert debug("POP");
mv.visitInsn(POP);
assert debug("ALOAD 0");
mv.visitVarInsn(ALOAD, 0);
if (type == 0) {
this.propNull = true;
assert debug("GETFIELD 'nullPropertyHandler'");
mv.visitFieldInsn(GETFIELD, className, "nullPropertyHandler", "L" + NAMESPACE + "integration/PropertyHandler;");
} else {
this.methNull = true;
assert debug("GETFIELD 'nullMethodHandler'");
mv.visitFieldInsn(GETFIELD, className, "nullMethodHandler", "L" + NAMESPACE + "integration/PropertyHandler;");
}
assert debug("LDC '" + member.getName() + "'");
mv.visitLdcInsn(member.getName());
assert debug("ALOAD 1");
mv.visitVarInsn(ALOAD, 1);
assert debug("ALOAD 3");
mv.visitVarInsn(ALOAD, 3);
assert debug("INVOKEINTERFACE PropertyHandler.getProperty");
mv.visitMethodInsn(INVOKEINTERFACE, NAMESPACE + "integration/PropertyHandler", "getProperty", "(Ljava/lang/String;Ljava/lang/Object;L" + NAMESPACE + "integration/VariableResolverFactory;)Ljava/lang/Object;");
assert debug("LABEL:jump");
mv.visitLabel(j);
}
use of org.mvel2.integration.PropertyHandler in project mvel by mikebrock.
the class ReflectiveAccessorOptimizer method propHandlerSet.
public void propHandlerSet(String property, Object ctx, Class handler, Object value) {
PropertyHandler ph = getPropertyHandler(handler);
addAccessorNode(new PropertyHandlerAccessor(property, handler, ph));
ph.setProperty(property, ctx, variableFactory, value);
}
use of org.mvel2.integration.PropertyHandler in project mvel by mikebrock.
the class ReflectiveAccessorOptimizer method propHandler.
private Object propHandler(String property, Object ctx, Class handler) {
PropertyHandler ph = getPropertyHandler(handler);
addAccessorNode(new PropertyHandlerAccessor(property, handler, ph));
return ph.getProperty(property, ctx, variableFactory);
}
use of org.mvel2.integration.PropertyHandler in project mvel by mikebrock.
the class PropertyHandlerTests method testNullPropertyHandler2.
public void testNullPropertyHandler2() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
OptimizerFactory.setDefaultOptimizer("reflective");
PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
return "NULL";
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return "NULL";
}
});
Foo foo = new Foo();
Bar bar = foo.getBar();
foo.setBar(null);
Map map = new HashMap();
map.put("foo", foo);
Serializable s = MVEL.compileExpression("foo.bar");
assertEquals("NULL", MVEL.executeExpression(s, map));
assertEquals("NULL", MVEL.executeExpression(s, map));
foo.setBar(bar);
assertEquals(bar, MVEL.executeExpression(s, map));
}
Aggregations