use of org.drools.javaparser.ast.expr.NullLiteralExpr in project drools by kiegroup.
the class ModelGenerator method ruleMetaAttributes.
/**
* Build a list of method calls, representing each needed {@link org.drools.model.impl.RuleBuilder#metadata(String, Object)}
* starting from a drools-compiler {@link RuleDescr}.
*/
private static List<MethodCallExpr> ruleMetaAttributes(RuleContext context, RuleDescr ruleDescr) {
List<MethodCallExpr> ruleMetaAttributes = new ArrayList<>();
for (String metaAttr : ruleDescr.getAnnotationNames()) {
MethodCallExpr metaAttributeCall = new MethodCallExpr(METADATA_CALL);
metaAttributeCall.addArgument(new StringLiteralExpr(metaAttr));
AnnotationDescr ad = ruleDescr.getAnnotation(metaAttr);
String adFqn = ad.getFullyQualifiedName();
if (adFqn != null) {
AnnotationDefinition annotationDefinition;
try {
annotationDefinition = AnnotationDefinition.build(context.getTypeResolver().resolveType(adFqn), ad.getValueMap(), context.getTypeResolver());
} catch (NoSuchMethodException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (annotationDefinition.getValues().size() == 1 && annotationDefinition.getValues().containsKey(AnnotationDescr.VALUE)) {
Object annValue = annotationDefinition.getPropertyValue(AnnotationDescr.VALUE);
metaAttributeCall.addArgument(new StringLiteralExpr(annValue.toString()));
} else {
Map<String, Object> map = new HashMap<>(annotationDefinition.getValues().size());
for (String key : annotationDefinition.getValues().keySet()) {
map.put(key, annotationDefinition.getPropertyValue(key));
}
metaAttributeCall.addArgument(objectAsJPExpression(map));
}
} else {
if (ad.hasValue()) {
if (ad.getValues().size() == 1) {
metaAttributeCall.addArgument(objectAsJPExpression(resolveValue(ad.getSingleValueAsString())));
} else {
metaAttributeCall.addArgument(objectAsJPExpression(ad.getValueMap()));
}
} else {
metaAttributeCall.addArgument(new NullLiteralExpr());
}
}
ruleMetaAttributes.add(metaAttributeCall);
}
return ruleMetaAttributes;
}
use of org.drools.javaparser.ast.expr.NullLiteralExpr in project drools by kiegroup.
the class ExpressionTyper method extractPrefixExpressions.
private void extractPrefixExpressions(NullSafeFieldAccessExpr drlxExpr, Expression previous) {
final BinaryExpr prefixExpression = new BinaryExpr(previous, new NullLiteralExpr(), BinaryExpr.Operator.NOT_EQUALS);
prefixExpressions.add(prefixExpression);
final Expression scope = drlxExpr.getScope();
if (scope != null) {
final Optional<TypedExpression> typedExpression1 = toTypedExpressionRec(scope);
typedExpression1.ifPresent(te -> {
final Expression expression = te.getExpression();
final BinaryExpr notNullScope = new BinaryExpr(expression, new NullLiteralExpr(), BinaryExpr.Operator.NOT_EQUALS);
prefixExpressions.add(0, notNullScope);
});
}
}
Aggregations