Search in sources :

Example 31 with FieldVisitor

use of org.mvel2.asm.FieldVisitor in project drools by kiegroup.

the class DefaultBeanClassBuilder method buildDynamicPropertyMap.

/**
 * A traitable class is a special class with support for dynamic properties and types.
 *
 * This method builds the property map, containing the key/values pairs to implement
 * any property defined in a trait interface but not supported by the traited class
 * fields.
 *
 * @param cw
 * @param def
 */
protected void buildDynamicPropertyMap(ClassWriter cw, ClassDefinition def) {
    FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, TraitableBean.MAP_FIELD_NAME, Type.getDescriptor(Map.class), "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null);
    fv.visitEnd();
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "_getDynamicProperties", Type.getMethodDescriptor(Type.getType(Map.class), new Type[] {}), "()Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, BuildUtils.getInternalType(def.getName()), TraitableBean.MAP_FIELD_NAME, Type.getDescriptor(Map.class));
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mv = cw.visitMethod(ACC_PUBLIC, "_setDynamicProperties", Type.getMethodDescriptor(Type.getType(void.class), new Type[] { Type.getType(Map.class) }), "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)V", null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, BuildUtils.getInternalType(def.getName()), TraitableBean.MAP_FIELD_NAME, Type.getDescriptor(Map.class));
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : Type(org.mvel2.asm.Type) FieldVisitor(org.mvel2.asm.FieldVisitor) Map(java.util.Map) MethodVisitor(org.mvel2.asm.MethodVisitor)

Aggregations

FieldVisitor (org.mvel2.asm.FieldVisitor)28 MethodVisitor (org.mvel2.asm.MethodVisitor)18 BitSet (java.util.BitSet)12 Map (java.util.Map)12 ClassWriter (org.mvel2.asm.ClassWriter)10 Label (org.mvel2.asm.Label)8 Type (org.mvel2.asm.Type)8 IOException (java.io.IOException)6 ObjectInput (java.io.ObjectInput)6 ObjectOutput (java.io.ObjectOutput)6 Serializable (java.io.Serializable)6 ClassGenerator.createClassWriter (org.drools.core.rule.builder.dialect.asm.ClassGenerator.createClassWriter)5 ClassGenerator.createClassWriter (org.drools.mvel.asm.ClassGenerator.createClassWriter)5 Externalizable (java.io.Externalizable)4 Collection (java.util.Collection)4 Thing (org.drools.core.factmodel.traits.Thing)4 AnnotationVisitor (org.mvel2.asm.AnnotationVisitor)4 TraitFieldTMS (org.drools.core.factmodel.traits.TraitFieldTMS)3 ReactiveObject (org.drools.core.phreak.ReactiveObject)3 Constructor (java.lang.reflect.Constructor)2