use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitMapPropertyWrapperClassBuilderImpl method buildEntryset.
protected void buildEntryset(ClassVisitor cw, String wrapperName, ClassDefinition core) {
String internalWrapper = BuildUtils.getInternalType(wrapperName);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "entrySet", "()" + Type.getDescriptor(Set.class), "()Ljava/util/Set<Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/Object;>;>;", null);
mv.visitCode();
mv.visitTypeInsn(NEW, Type.getInternalName(HashSet.class));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(HashSet.class), "<init>", "()V", false);
mv.visitVarInsn(ASTORE, 1);
for (FieldDefinition field : core.getFieldsDefinitions()) {
buildEntry(mv, field, wrapperName, core);
}
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "entrySet", "()" + Type.getDescriptor(Set.class), true);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Set.class), "addAll", "(" + Type.getDescriptor(Collection.class) + ")Z", true);
mv.visitInsn(POP);
mv.visitVarInsn(ALOAD, 1);
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 buildKeyset.
protected void buildKeyset(ClassVisitor cw, String wrapperName, ClassDefinition core) {
String internalWrapper = BuildUtils.getInternalType(wrapperName);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "keySet", "()" + Type.getDescriptor(Set.class), "()Ljava/util/Set<Ljava/lang/String;>;", null);
mv.visitCode();
mv.visitTypeInsn(NEW, Type.getInternalName(HashSet.class));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(HashSet.class), "<init>", "()V", false);
mv.visitVarInsn(ASTORE, 1);
for (FieldDefinition field : core.getFieldsDefinitions()) {
mv.visitVarInsn(ALOAD, 1);
mv.visitLdcInsn(field.getName());
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Set.class), "add", "(" + Type.getDescriptor(Object.class) + ")Z", true);
mv.visitInsn(POP);
}
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "keySet", "()" + Type.getDescriptor(Set.class), true);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Set.class), "addAll", "(" + Type.getDescriptor(Collection.class) + ")Z", true);
mv.visitInsn(POP);
mv.visitVarInsn(ALOAD, 1);
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 buildPut.
protected void buildPut(ClassVisitor cw, String wrapperName, ClassDefinition core) {
String internalWrapper = BuildUtils.getInternalType(wrapperName);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "put", "(" + Type.getDescriptor(String.class) + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Object.class), null, null);
mv.visitCode();
if (core.getFieldsDefinitions().size() > 0) {
for (FieldDefinition field : core.getFieldsDefinitions()) {
invokePut(mv, wrapperName, core, field.getName(), field);
}
}
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalWrapper, "map", Type.getDescriptor(Map.class));
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Map.class), "put", "(" + Type.getDescriptor(Object.class) + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Object.class), true);
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitMapProxyClassBuilderImpl method buildFields.
protected void buildFields(ClassDefinition core, BitSet mask, String masterName, MixinInfo mixinInfo, ClassWriter cw) {
int j = 0;
for (FieldDefinition field : trait.getFieldsDefinitions()) {
boolean hardField = !TraitRegistry.isSoftField(field, j++, mask);
if (core.isFullTraiting()) {
buildLogicalGetter(cw, field, masterName, core);
if (hardField) {
buildHardSetter(cw, field, masterName, trait, core);
} else {
buildSoftSetter(cw, field, masterName, core);
}
} else {
if (!hardField) {
if (mixinInfo == null || !mixinInfo.isMixinGetter(field)) {
buildSoftGetter(cw, field, masterName);
buildSoftSetter(cw, field, masterName, core);
}
} else {
buildHardGetter(cw, field, masterName, trait, core);
buildHardSetter(cw, field, masterName, trait, core);
}
}
}
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitRegistry method bind.
private BitSet bind(String trait, String traitable) throws UnsupportedOperationException {
ClassDefinition traitDef = getTrait(trait);
if (traitDef == null) {
throw new UnsupportedOperationException(" Unable to apply trait " + trait + " to class " + traitable + " : not a trait ");
}
ClassDefinition traitableDef = getTraitable(traitable);
if (traitableDef == null) {
throw new UnsupportedOperationException(" Unable to apply trait " + trait + " to class " + traitable + " : not a traitable ");
}
int j = 0;
BitSet bitmask = new BitSet(traitDef.getFields().size());
for (FactField field : traitDef.getFields()) {
String alias = ((FieldDefinition) field).resolveAlias();
FieldDefinition concreteField = traitableDef.getFieldByAlias(alias);
if (concreteField != null) {
if (!traitableDef.isFullTraiting() && !concreteField.getType().isAssignableFrom(field.getType())) {
throw new UnsupportedOperationException(" Unable to apply trait " + trait + " to class " + traitable + " :" + " trait field " + field.getName() + ":" + ((FieldDefinition) field).getTypeName() + " is incompatible with" + " concrete hard field " + concreteField.getName() + ":" + concreteField.getTypeName() + ". Consider enabling logical traiting" + " mode using @Traitable( logical = true )");
}
bitmask.set(j);
}
j++;
}
return bitmask;
}
Aggregations