Search in sources :

Example 61 with Label

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);
            }
        }
    }
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) ParserContext(org.mvel2.ParserContext) DroolsParserException(org.drools.compiler.compiler.DroolsParserException) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 62 with Label

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);
}
Also used : Label(org.mvel2.asm.Label)

Example 63 with Label

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);
}
Also used : Label(org.mvel2.asm.Label)

Example 64 with Label

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);
}
Also used : Label(org.mvel2.asm.Label)

Example 65 with Label

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);
}
Also used : Label(org.mvel2.asm.Label)

Aggregations

Label (org.mvel2.asm.Label)97 MethodVisitor (org.mvel2.asm.MethodVisitor)49 FieldDefinition (org.drools.core.factmodel.FieldDefinition)24 Map (java.util.Map)18 Type (org.mvel2.asm.Type)12 IOException (java.io.IOException)10 BitSet (java.util.BitSet)8 FieldVisitor (org.mvel2.asm.FieldVisitor)8 Method (java.lang.reflect.Method)7 CompiledInvoker (org.drools.core.spi.CompiledInvoker)7 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)5 ObjectInput (java.io.ObjectInput)4 ObjectOutput (java.io.ObjectOutput)4 Collection (java.util.Collection)4 Thing (org.drools.core.factmodel.traits.Thing)4 Declaration (org.drools.core.rule.Declaration)4 ClassGenerator (org.drools.core.rule.builder.dialect.asm.ClassGenerator)4 ClassWriter (org.mvel2.asm.ClassWriter)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3