use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitTriplePropertyWrapperClassBuilderImpl method buildContainsValue.
protected void buildContainsValue(ClassWriter cw, String wrapperName, ClassDefinition core) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "containsValue", "(" + Type.getDescriptor(Object.class) + ")Z", null, null);
mv.visitCode();
boolean hasNillable = false;
for (FieldDefinition field : core.getFieldsDefinitions()) {
if (!BuildUtils.isPrimitive(field.getTypeName())) {
hasNillable = true;
}
}
Label l99 = null;
if (hasNillable) {
mv.visitVarInsn(ALOAD, 1);
l99 = new Label();
mv.visitJumpInsn(IFNONNULL, l99);
}
core.getFieldsDefinitions().size();
for (FieldDefinition field : core.getFieldsDefinitions()) {
if (!BuildUtils.isPrimitive(field.getTypeName())) {
extractAndTestNotNull(mv, wrapperName, core, field);
}
}
if (hasNillable) {
mv.visitLabel(l99);
}
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(TripleBasedStruct.class), "containsValue", "(" + Type.getDescriptor(Object.class) + ")Z", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class TraitTriplePropertyWrapperClassBuilderImpl method buildEntryset.
protected void buildEntryset(ClassVisitor cw, String wrapperName, ClassDefinition core) {
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.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(TripleBasedStruct.class), "entrySet", "()" + Type.getDescriptor(Set.class), false);
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 TraitTriplePropertyWrapperClassBuilderImpl method buildValues.
protected void buildValues(ClassVisitor cw, String wrapperName, ClassDefinition core) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "values", "()" + Type.getDescriptor(Collection.class), "()Ljava/util/Collection<Ljava/lang/Object;>;", null);
mv.visitCode();
mv.visitTypeInsn(NEW, Type.getInternalName(ArrayList.class));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(ArrayList.class), "<init>", "()V", false);
mv.visitVarInsn(ASTORE, 1);
for (FieldDefinition field : core.getFieldsDefinitions()) {
extractAndCollect(mv, wrapperName, field, core);
}
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(TripleBasedStruct.class), "values", "()" + Type.getDescriptor(Collection.class), false);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Collection.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 TraitTriplePropertyWrapperClassBuilderImpl method buildContainsKey.
protected void buildContainsKey(ClassWriter cw, ClassDefinition core) {
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.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(TripleBasedStruct.class), "containsKey", "(" + Type.getDescriptor(Object.class) + ")Z", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.drools.core.factmodel.FieldDefinition in project drools by kiegroup.
the class ClassDefinitionFactory method wireFields.
protected boolean wireFields(AbstractClassTypeDeclarationDescr typeDescr, TypeDeclaration type, ClassDefinition def, PackageRegistry pkgRegistry, List<TypeDefinition> unresolvedTypeDefinitions) {
// Fields are SORTED in the process
if (!typeDescr.getFields().isEmpty()) {
if (unresolvedTypeDefinitions != null && !unresolvedTypeDefinitions.isEmpty()) {
for (TypeFieldDescr fld : typeDescr.getFields().values()) {
if (unresolvedTypeDefinitions != null) {
for (TypeDefinition typeDef : unresolvedTypeDefinitions) {
if (fld.getPattern().getObjectType().equals(typeDef.getTypeClassName())) {
return false;
}
}
}
}
}
List<FieldDefinition> fieldDefs = sortFields(typeDescr.getFields(), pkgRegistry.getTypeResolver(), kbuilder);
int i = 0;
for (FieldDefinition fieldDef : fieldDefs) {
fieldDef.setIndex(i++);
def.addField(fieldDef);
}
}
return true;
}
Aggregations