use of org.drools.core.rule.constraint.NegConstraint in project drools by kiegroup.
the class PatternBuilder method buildExpression.
protected Constraint buildExpression(final RuleBuildContext context, final Pattern pattern, final BaseDescr d, final String expr, final Map<String, OperatorDescr> aliases) {
if ("_.neg".equals(expr)) {
pattern.setHasNegativeConstraint(true);
return new NegConstraint();
} else if ("!_.neg".equals(expr)) {
pattern.setHasNegativeConstraint(true);
return new NegConstraint(false);
}
RelationalExprDescr relDescr = d instanceof RelationalExprDescr ? (RelationalExprDescr) d : null;
boolean simple = isSimpleExpr(relDescr);
if (// simple means also relDescr is != null
simple && !ClassObjectType.Map_ObjectType.isAssignableFrom(pattern.getObjectType()) && !ClassObjectType.Match_ObjectType.isAssignableFrom(pattern.getObjectType())) {
String normalizedExpr = normalizeExpression(context, pattern, relDescr, expr);
return buildRelationalExpression(context, pattern, relDescr, normalizedExpr, aliases);
}
// Or it's a Map and we have to treat it as a special case
return createAndBuildPredicate(context, pattern, d, rewriteOrExpressions(context, pattern, d, expr), aliases);
}
use of org.drools.core.rule.constraint.NegConstraint in project drools by kiegroup.
the class PatternBuilder method build.
/**
* Build a pattern for the given descriptor in the current
* context and using the given utils object
*/
public RuleConditionElement build(RuleBuildContext context, PatternDescr patternDescr, Pattern prefixPattern) {
if (patternDescr.getObjectType() == null) {
lookupObjectType(context, patternDescr);
}
if (patternDescr.getObjectType() == null || patternDescr.getObjectType().equals("")) {
registerDescrBuildError(context, patternDescr, "ObjectType not correctly defined");
return null;
}
ObjectType objectType = getObjectType(context, patternDescr);
if (objectType == null) {
// if the objectType doesn't exist it has to be query
return buildQuery(context, patternDescr, patternDescr);
}
Pattern pattern = buildPattern(context, patternDescr, objectType);
processClassObjectType(context, objectType, pattern);
processAnnotations(context, patternDescr, pattern);
processSource(context, patternDescr, pattern);
processConstraintsAndBinds(context, patternDescr, pattern);
processBehaviors(context, patternDescr, pattern);
if (!pattern.hasNegativeConstraint() && "on".equals(System.getProperty("drools.negatable"))) {
// this is a non-negative pattern, so we must inject the constraint
pattern.addConstraint(new NegConstraint(false));
}
// poping the pattern
context.getDeclarationResolver().popBuildStack();
return pattern;
}
Aggregations