use of org.drools.core.factmodel.AnnotationDefinition in project drools by kiegroup.
the class AnnotationsOnPatternTest method testNestedAnnotationsWithMultiplicity.
@Test
public void testNestedAnnotationsWithMultiplicity() {
final String drl = "package org.drools.test; " + "import " + Outer.class.getName().replace("$", ".") + "; " + "import " + Inner.class.getName().replace("$", ".") + "; " + "rule Foo " + "when " + " String() @Outer( values = { @Inner( text = \"hello\" ), @Inner( text = \"world\" ) } ) " + "then " + "end ";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("annotations-test", kieBaseTestConfiguration, drl);
final Pattern p = ((Pattern) ((RuleImpl) kbase.getRule("org.drools.test", "Foo")).getLhs().getChildren().get(0));
final Map<String, AnnotationDefinition> defs = p.getAnnotations();
assertEquals(1, defs.size());
final AnnotationDefinition outer = defs.get(Outer.class.getName().replace("$", "."));
assertNotNull(outer);
final Object val = outer.getPropertyValue("values");
assertNotNull(val);
assertTrue(val instanceof AnnotationDefinition[]);
}
use of org.drools.core.factmodel.AnnotationDefinition in project drools by kiegroup.
the class TraitClassBuilderImpl method buildClass.
public byte[] buildClass(ClassDefinition classDef, ClassLoader classLoader) {
init(classDef);
String cName = BuildUtils.getInternalType(classDef.getClassName());
String genericTypes = BuildUtils.getGenericTypes(classDef.getInterfaces());
String superType = Type.getInternalName(Object.class);
String[] intfaces = null;
if (Object.class.getName().equals(classDef.getSuperClass())) {
String[] tmp = BuildUtils.getInternalTypes(classDef.getInterfaces());
intfaces = new String[tmp.length + 2];
System.arraycopy(tmp, 0, intfaces, 0, tmp.length);
intfaces[tmp.length] = Type.getInternalName(Serializable.class);
intfaces[tmp.length + 1] = Type.getInternalName(GeneratedFact.class);
} else {
String[] tmp = BuildUtils.getInternalTypes(classDef.getInterfaces());
intfaces = new String[tmp.length + 3];
System.arraycopy(tmp, 0, intfaces, 0, tmp.length);
intfaces[tmp.length] = BuildUtils.getInternalType(classDef.getSuperClass());
intfaces[tmp.length + 1] = Type.getInternalName(Serializable.class);
intfaces[tmp.length + 2] = Type.getInternalName(GeneratedFact.class);
}
ClassWriter cw = createClassWriter(classLoader, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, cName, genericTypes, superType, intfaces);
if (classDef.getDefinedClass() == null || classDef.getDefinedClass().getAnnotation(Trait.class) == null) {
AnnotationVisitor av0 = cw.visitAnnotation(Type.getDescriptor(Trait.class), true);
for (AnnotationDefinition adef : classDef.getAnnotations()) {
if (Trait.class.getName().equals(adef.getName())) {
addAnnotationAttribute(adef, av0);
break;
}
}
av0.visitEnd();
}
for (FieldDefinition field : classDef.getFieldsDefinitions()) {
buildField(cw, field);
}
finalizeCreation(classDef);
cw.visitEnd();
return cw.toByteArray();
}
use of org.drools.core.factmodel.AnnotationDefinition in project drools by kiegroup.
the class DefaultBeanClassBuilder method buildFieldAnnotations.
protected void buildFieldAnnotations(FieldDefinition fieldDef, FieldVisitor fv) {
if (fieldDef.getAnnotations() != null) {
for (AnnotationDefinition ad : fieldDef.getAnnotations()) {
AnnotationVisitor av = fv.visitAnnotation("L" + BuildUtils.getInternalType(ad.getName()) + ";", true);
addAnnotationAttribute(ad, av);
av.visitEnd();
}
}
}
Aggregations