Search in sources :

Example 1 with OperatorDescr

use of org.drools.compiler.lang.descr.OperatorDescr in project drools by kiegroup.

the class PatternBuilder method buildCcdDescr.

protected Constraint buildCcdDescr(RuleBuildContext context, PatternDescr patternDescr, Pattern pattern, BaseDescr d, ConstraintConnectiveDescr ccd, MVELDumper.MVELDumperContext mvelCtx) {
    d.copyLocation(patternDescr);
    mvelCtx.clear();
    String expr = context.getCompilerFactory().getExpressionProcessor().dump(d, ccd, mvelCtx);
    Map<String, OperatorDescr> aliases = mvelCtx.getAliases();
    // create bindings
    TypeDeclaration typeDeclaration = getTypeDeclaration(pattern, context);
    for (BindingDescr bind : mvelCtx.getBindings()) {
        buildRuleBindings(context, patternDescr, pattern, bind, typeDeclaration);
    }
    if (expr.length() == 0) {
        return null;
    }
    // check if it is an atomic expression
    Constraint constraint = processAtomicExpression(context, pattern, d, expr, aliases);
    // otherwise check if it is a simple expression
    return constraint != null ? constraint : buildExpression(context, pattern, d, expr, aliases);
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) XpathConstraint(org.drools.core.rule.constraint.XpathConstraint) NegConstraint(org.drools.core.rule.constraint.NegConstraint) Constraint(org.drools.core.spi.Constraint) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) EvaluatorConstraint(org.drools.core.rule.constraint.EvaluatorConstraint) PredicateConstraint(org.drools.core.rule.PredicateConstraint) OperatorDescr(org.drools.compiler.lang.descr.OperatorDescr) TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 2 with OperatorDescr

use of org.drools.compiler.lang.descr.OperatorDescr in project drools by kiegroup.

the class PatternBuilder method buildOperators.

protected static Map<String, EvaluatorWrapper> buildOperators(RuleBuildContext context, Pattern pattern, BaseDescr predicateDescr, Map<String, OperatorDescr> aliases) {
    if (aliases.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<String, EvaluatorWrapper> operators = new HashMap<String, EvaluatorWrapper>();
    for (Map.Entry<String, OperatorDescr> entry : aliases.entrySet()) {
        OperatorDescr op = entry.getValue();
        Declaration leftDecl = createDeclarationForOperator(context, pattern, op.getLeftString());
        Declaration rightDecl = createDeclarationForOperator(context, pattern, op.getRightString());
        Target left = leftDecl != null && leftDecl.isPatternDeclaration() ? Target.HANDLE : Target.FACT;
        Target right = rightDecl != null && rightDecl.isPatternDeclaration() ? Target.HANDLE : Target.FACT;
        op.setLeftIsHandle(left == Target.HANDLE);
        op.setRightIsHandle(right == Target.HANDLE);
        Evaluator evaluator = getConstraintBuilder(context).getEvaluator(context, predicateDescr, ValueType.OBJECT_TYPE, op.getOperator(), // the rewrite takes care of negation
        false, op.getParametersText(), left, right);
        EvaluatorWrapper wrapper = getConstraintBuilder(context).wrapEvaluator(evaluator, leftDecl, rightDecl);
        operators.put(entry.getKey(), wrapper);
    }
    return operators;
}
Also used : Target(org.drools.core.base.evaluators.EvaluatorDefinition.Target) EvaluatorWrapper(org.drools.core.base.EvaluatorWrapper) HashMap(java.util.HashMap) OperatorDescr(org.drools.compiler.lang.descr.OperatorDescr) Declaration(org.drools.core.rule.Declaration) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Evaluator(org.drools.core.spi.Evaluator) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

OperatorDescr (org.drools.compiler.lang.descr.OperatorDescr)2 TypeDeclaration (org.drools.core.rule.TypeDeclaration)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)1 EvaluatorWrapper (org.drools.core.base.EvaluatorWrapper)1 Target (org.drools.core.base.evaluators.EvaluatorDefinition.Target)1 Declaration (org.drools.core.rule.Declaration)1 PredicateConstraint (org.drools.core.rule.PredicateConstraint)1 EvaluatorConstraint (org.drools.core.rule.constraint.EvaluatorConstraint)1 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)1 NegConstraint (org.drools.core.rule.constraint.NegConstraint)1 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)1 Constraint (org.drools.core.spi.Constraint)1 Evaluator (org.drools.core.spi.Evaluator)1