use of org.mvel2.asm.Label in project drools by kiegroup.
the class PatternBuilder method setInputs.
protected void setInputs(RuleBuildContext context, ExprBindings descrBranch, Class<?> thisClass, String expr) {
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel");
ParserConfiguration conf = data.getParserConfiguration();
conf.setClassLoader(context.getKnowledgeBuilder().getRootClassLoader());
final ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(false);
pctx.setStrongTyping(false);
pctx.addInput("this", thisClass);
// overrides the mvel empty label
pctx.addInput("empty", boolean.class);
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;
try {
MVEL.analysisCompile(expr, pctx);
} catch (Exception e) {
// reported during expression analysis, so swallow it at the moment
return;
}
if (!pctx.getInputs().isEmpty()) {
for (String v : pctx.getInputs().keySet()) {
// to an "empty" property, or the if will evaluate to true even if it doesn't
if ("this".equals(v) || (PropertyTools.getFieldOrAccessor(thisClass, v) != null && expr.matches("(^|.*\\W)empty($|\\W.*)"))) {
descrBranch.getFieldAccessors().add(v);
} else if ("empty".equals(v)) {
// do nothing
} else if (!context.getPkg().getGlobals().containsKey(v)) {
descrBranch.getRuleBindings().add(v);
} else {
descrBranch.getGlobalBindings().add(v);
}
}
}
}
use of org.mvel2.asm.Label in project drools by kiegroup.
the class AbstractPropertyWrapperClassBuilderImpl method invokePut.
protected void invokePut(MethodVisitor mv, String wrapperName, ClassDefinition core, String fieldName, FieldDefinition field) {
mv.visitLdcInsn(fieldName);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(String.class), "equals", "(" + Type.getDescriptor(Object.class) + ")Z", false);
Label l1 = new Label();
mv.visitJumpInsn(IFEQ, l1);
mv.visitVarInsn(ALOAD, 2);
if (BuildUtils.isPrimitive(field.getTypeName())) {
TraitFactory.primitiveValue(mv, field.getTypeName());
mv.visitVarInsn(BuildUtils.storeType(field.getTypeName()), 3);
TraitFactory.invokeInjector(mv, wrapperName, core, field, false, 3);
} else {
TraitFactory.invokeInjector(mv, wrapperName, core, field, false, 2);
}
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
mv.visitLabel(l1);
}
use of org.mvel2.asm.Label in project drools by kiegroup.
the class AbstractPropertyWrapperClassBuilderImpl method invokeRemove.
protected void invokeRemove(MethodVisitor mv, String wrapperName, ClassDefinition core, String fieldName, FieldDefinition field) {
mv.visitLdcInsn(fieldName);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(String.class), "equals", "(" + Type.getDescriptor(Object.class) + ")Z", false);
Label l1 = new Label();
mv.visitJumpInsn(IFEQ, l1);
TraitFactory.invokeExtractor(mv, wrapperName, trait, core, field);
if (BuildUtils.isPrimitive(field.getTypeName())) {
TraitFactory.valueOf(mv, field.getTypeName());
}
mv.visitVarInsn(ASTORE, 2);
TraitFactory.invokeInjector(mv, wrapperName, core, field, true, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
mv.visitLabel(l1);
}
use of org.mvel2.asm.Label in project drools by kiegroup.
the class AbstractPropertyWrapperClassBuilderImpl method registerLogicalField.
protected void registerLogicalField(MethodVisitor mv, String internalWrapper, FieldDefinition field, ClassDefinition core) {
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "object", Type.getDescriptor(core.getDefinedClass()));
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(TraitableBean.class));
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(TraitableBean.class), "_getFieldTMS", Type.getMethodDescriptor(Type.getType(TraitFieldTMS.class)), true);
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 1);
mv.visitLdcInsn(field.resolveAlias());
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(TraitFieldTMS.class), "isManagingField", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(String.class)), true);
Label l1 = new Label();
mv.visitJumpInsn(IFNE, l1);
mv.visitVarInsn(ALOAD, 1);
mv.visitLdcInsn(Type.getType(BuildUtils.getTypeDescriptor(core.getClassName())));
mv.visitLdcInsn(field.resolveAlias());
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(TraitFieldTMS.class), "registerField", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Class.class), Type.getType(String.class)), true);
mv.visitLabel(l1);
}
use of org.mvel2.asm.Label in project drools by kiegroup.
the class AbstractPropertyWrapperClassBuilderImpl method extractAndTestNotNull.
protected void extractAndTestNotNull(MethodVisitor mv, String wrapperName, ClassDefinition core, FieldDefinition field) {
TraitFactory.invokeExtractor(mv, wrapperName, trait, core, field);
Label l1 = new Label();
mv.visitJumpInsn(IFNONNULL, l1);
mv.visitInsn(ICONST_1);
mv.visitInsn(IRETURN);
mv.visitLabel(l1);
}
Aggregations