use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class AbstractTraitFactory method invokeExtractor.
public static void invokeExtractor(MethodVisitor mv, String masterName, ClassDefinition trait, ClassDefinition core, FieldDefinition field) {
FieldDefinition tgtField = core.getFieldByAlias(field.resolveAlias());
String fieldType = tgtField.getTypeName();
String returnType = BuildUtils.getTypeDescriptor(fieldType);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, BuildUtils.getInternalType(masterName), "object", BuildUtils.getTypeDescriptor(core.getClassName()));
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(core.getDefinedClass()), tgtField.getReadMethod(), Type.getMethodDescriptor(Type.getType(returnType)), false);
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class AbstractTraitFactory method invokeInjector.
public static void invokeInjector(MethodVisitor mv, String masterName, ClassDefinition core, FieldDefinition field, boolean toNull, int pointer) {
FieldDefinition tgtField = core.getFieldByAlias(field.resolveAlias());
String fieldType = tgtField.getTypeName();
String returnType = BuildUtils.getTypeDescriptor(fieldType);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, BuildUtils.getInternalType(masterName), "object", BuildUtils.getTypeDescriptor(core.getName()));
if (toNull) {
mv.visitInsn(BuildUtils.zero(field.getTypeName()));
} else {
mv.visitVarInsn(BuildUtils.varType(fieldType), pointer);
}
if (!BuildUtils.isPrimitive(fieldType)) {
mv.visitTypeInsn(CHECKCAST, BuildUtils.getInternalType(fieldType));
}
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(core.getDefinedClass()), tgtField.getWriteMethod(), Type.getMethodDescriptor(Type.getType(void.class), Type.getType(returnType)), false);
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitMapPropertyWrapperClassBuilderImpl method buildRemove.
protected void buildRemove(ClassWriter cw, String wrapperName, ClassDefinition trait, ClassDefinition core, BitSet mask) {
String internalWrapper = BuildUtils.getInternalType(wrapperName);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "remove", "(" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Object.class), null, null);
mv.visitCode();
for (FieldDefinition field : core.getFieldsDefinitions()) {
invokeRemove(mv, wrapperName, core, field.getName(), field);
}
int j = 0;
for (FieldDefinition field : trait.getFieldsDefinitions()) {
boolean isSoftField = TraitRegistry.isSoftField(field, j++, mask);
if (isSoftField) {
mv.visitLdcInsn(field.getName());
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(String.class), "equals", "(" + Type.getDescriptor(Object.class) + ")Z", false);
Label l2 = new Label();
mv.visitJumpInsn(IFEQ, l2);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitLdcInsn(field.getName());
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "get", "(" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Object.class), true);
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitLdcInsn(field.getName());
mv.visitInsn(BuildUtils.zero(field.getTypeName()));
if (BuildUtils.isPrimitive(field.getTypeName())) {
TraitFactory.valueOf(mv, field.getTypeName());
}
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "put", "(" + Type.getDescriptor(Object.class) + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Object.class), true);
mv.visitInsn(POP);
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
}
}
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "remove", "(" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Object.class), true);
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitMapPropertyWrapperClassBuilderImpl method buildContainsKey.
protected void buildContainsKey(ClassWriter cw, String name, ClassDefinition core) {
String internalWrapper = BuildUtils.getInternalType(name);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "containsKey", "(" + Type.getDescriptor(Object.class) + ")Z", null, null);
mv.visitCode();
for (FieldDefinition field : core.getFieldsDefinitions()) {
invokeContainsKey(mv, field.getName());
}
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "containsKey", "(" + Type.getDescriptor(Object.class) + ")Z", true);
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitMapPropertyWrapperClassBuilderImpl method initSoftFields.
protected void initSoftFields(MethodVisitor mv, ClassDefinition trait, ClassDefinition core, String internalWrapper, BitSet mask, int varNum) {
int j = 0;
for (FieldDefinition field : trait.getFieldsDefinitions()) {
boolean isSoftField = TraitRegistry.isSoftField(field, j++, mask);
if (isSoftField) {
mv.visitVarInsn(ALOAD, varNum);
mv.visitLdcInsn(field.resolveAlias());
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "containsKey", Type.getMethodDescriptor(Type.getType(boolean.class), Type.getType(Object.class)), true);
Label l0 = new Label();
mv.visitJumpInsn(IFNE, l0);
mv.visitVarInsn(ALOAD, varNum);
mv.visitLdcInsn(field.resolveAlias());
mv.visitInsn(BuildUtils.zero(field.getTypeName()));
if (BuildUtils.isPrimitive(field.getTypeName())) {
TraitFactory.valueOf(mv, field.getTypeName());
}
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "put", Type.getMethodDescriptor(Type.getType(Object.class), Type.getType(Object.class), Type.getType(Object.class)), true);
mv.visitInsn(POP);
if (core.isFullTraiting()) {
registerLogicalField(mv, internalWrapper, field, core);
}
mv.visitLabel(l0);
}
}
}
Aggregations