use of org.mvel2.asm.Type in project drools by kiegroup.
the class TraitTripleProxyClassBuilderImpl method buildSoftSetter.
protected void buildSoftSetter(ClassVisitor cw, FieldDefinition field, String proxy, ClassDefinition core, String setterName, int accessMode) {
String type = field.getTypeName();
MethodVisitor mv = cw.visitMethod(accessMode, setterName, "(" + Type.getDescriptor(field.getType()) + ")V", null, null);
mv.visitCode();
if (core.isFullTraiting()) {
logicalSetter(mv, field, proxy, core);
}
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, BuildUtils.getInternalType(proxy), "store", Type.getDescriptor(TripleStore.class));
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn(field.resolveAlias());
mv.visitVarInsn(BuildUtils.varType(type), 1);
if (BuildUtils.isPrimitive(type)) {
TraitFactory.valueOf(mv, type);
}
mv.visitMethodInsn(INVOKEVIRTUAL, BuildUtils.getInternalType(proxy), "property", "(" + Type.getDescriptor(String.class) + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Triple.class), false);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(TripleStore.class), "put", "(" + Type.getDescriptor(Triple.class) + ")Z", false);
mv.visitInsn(POP);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.mvel2.asm.Type in project drools by kiegroup.
the class DefaultBeanClassBuilder method buildDefaultConstructor.
/**
* Creates a default constructor for the class
*
* @param cw
*/
protected void buildDefaultConstructor(ClassVisitor cw, ClassDefinition classDef) {
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);
mv.visitCode();
Label l0 = null;
if (this.debug) {
l0 = new Label();
mv.visitLabel(l0);
}
boolean hasObjects = defaultConstructorStart(mv, classDef);
mv.visitInsn(Opcodes.RETURN);
Label l1 = null;
if (this.debug) {
l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", BuildUtils.getTypeDescriptor(classDef.getClassName()), null, l0, l1, 0);
}
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.mvel2.asm.Type in project drools by kiegroup.
the class DefaultBeanClassBuilder method fieldConstructorStart.
protected void fieldConstructorStart(MethodVisitor mv, ClassDefinition classDef, Collection<FieldDefinition> fieldDefs) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
String sup = "";
try {
sup = Type.getInternalName(Class.forName(classDef.getSuperClass()));
} catch (ClassNotFoundException e) {
sup = BuildUtils.getInternalType(classDef.getSuperClass());
}
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, sup, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
// local vars start at 1, as 0 is "this"
int index = 1;
for (FieldDefinition field : fieldDefs) {
if (this.debug) {
Label l11 = new Label();
mv.visitLabel(l11);
}
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Type.getType(BuildUtils.getTypeDescriptor(field.getTypeName())).getOpcode(Opcodes.ILOAD), index++);
if (field.getTypeName().equals("long") || field.getTypeName().equals("double")) {
// long and double variables use 2 words on the variables table
index++;
}
if (!field.isInherited()) {
mv.visitFieldInsn(Opcodes.PUTFIELD, BuildUtils.getInternalType(classDef.getClassName()), field.getName(), BuildUtils.getTypeDescriptor(field.getTypeName()));
} else {
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, BuildUtils.getInternalType(classDef.getClassName()), field.getWriteMethod(), Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(BuildUtils.getTypeDescriptor(field.getTypeName())) }));
}
}
for (FieldDefinition field : classDef.getFieldsDefinitions()) {
if (!fieldDefs.contains(field) && field.getInitExpr() != null && !"".equals(field.getInitExpr().trim())) {
initFieldWithDefaultValue(mv, classDef, field);
}
}
if (classDef.isTraitable()) {
initializeDynamicTypeStructures(mv, classDef);
}
}
use of org.mvel2.asm.Type in project drools by kiegroup.
the class DefaultBeanClassBuilder method buildFieldTMS.
/**
* A traitable class is a special class with support for dynamic properties and types.
*
* A traitable class in logical mode provides additional control over the values
* and type(s) of its fields.
*
* @param cw
* @param def
*/
protected void buildFieldTMS(ClassWriter cw, ClassDefinition def) {
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor(TraitFieldTMS.class), null, null);
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "_getFieldTMS", Type.getMethodDescriptor(Type.getType(TraitFieldTMS.class), new Type[] {}), null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, BuildUtils.getInternalType(def.getName()), TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor(TraitFieldTMS.class));
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
mv = cw.visitMethod(ACC_PUBLIC, "_setFieldTMS", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(TraitFieldTMS.class) }), null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitFieldInsn(PUTFIELD, BuildUtils.getInternalType(def.getName()), TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor(TraitFieldTMS.class));
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.mvel2.asm.Type in project drools by kiegroup.
the class DefaultBeanClassBuilder method buildConstructorWithFields.
/**
* Creates a constructor that takes and assigns values to all
* fields in the order they are declared.
*
* @param cw
* @param classDef
*/
protected void buildConstructorWithFields(ClassVisitor cw, ClassDefinition classDef, Collection<FieldDefinition> fieldDefs) {
Type[] params = new Type[fieldDefs.size()];
int index = 0;
for (FieldDefinition field : fieldDefs) {
params[index++] = Type.getType(BuildUtils.getTypeDescriptor(field.getTypeName()));
}
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, params), null, null);
mv.visitCode();
Label l0 = null;
if (this.debug) {
l0 = new Label();
mv.visitLabel(l0);
}
fieldConstructorStart(mv, classDef, fieldDefs);
mv.visitInsn(Opcodes.RETURN);
Label l1 = null;
if (this.debug) {
l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", BuildUtils.getTypeDescriptor(classDef.getClassName()), null, l0, l1, 0);
for (FieldDefinition field : classDef.getFieldsDefinitions()) {
Label l11 = new Label();
mv.visitLabel(l11);
mv.visitLocalVariable(field.getName(), BuildUtils.getTypeDescriptor(field.getTypeName()), null, l0, l1, 0);
}
}
mv.visitMaxs(0, 0);
mv.visitEnd();
}
Aggregations