Search in sources :

Example 1 with PredicateDescr

use of org.drools.drl.ast.descr.PredicateDescr in project drools by kiegroup.

the class AbstractASMEvalBuilder method build.

public RuleConditionElement build(RuleBuildContext context, BaseDescr descr, Pattern prefixPattern) {
    if (prefixPattern == null) {
        return build(context, descr);
    }
    EvalDescr evalDescr = (EvalDescr) descr;
    PredicateDescr predicateDescr = new PredicateDescr(context.getRuleDescr().getResource(), evalDescr.getContent());
    AnalysisResult analysis = buildAnalysis(context, prefixPattern, predicateDescr, null);
    Declaration[] declarations = getUsedDeclarations(context, prefixPattern, analysis);
    return buildEval(context, evalDescr, analysis, declarations);
}
Also used : EvalDescr(org.drools.drl.ast.descr.EvalDescr) Declaration(org.drools.core.rule.Declaration) PredicateDescr(org.drools.drl.ast.descr.PredicateDescr) AnalysisResult(org.drools.compiler.compiler.AnalysisResult)

Example 2 with PredicateDescr

use of org.drools.drl.ast.descr.PredicateDescr in project drools by kiegroup.

the class PatternBuilder method processAtomicExpression.

protected Constraint processAtomicExpression(RuleBuildContext context, Pattern pattern, BaseDescr d, String expr, Map<String, OperatorDescr> aliases) {
    if (d instanceof AtomicExprDescr) {
        Matcher m = evalRegexp.matcher(((AtomicExprDescr) d).getExpression());
        if (m.find()) {
            // MVELDumper already stripped the eval
            // this will build the eval using the specified dialect
            PredicateDescr pdescr = new PredicateDescr(context.getRuleDescr().getResource(), expr);
            pdescr.copyLocation(d);
            return buildEval(context, pattern, pdescr, aliases, expr, true);
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) AtomicExprDescr(org.drools.drl.ast.descr.AtomicExprDescr) PredicateDescr(org.drools.drl.ast.descr.PredicateDescr)

Example 3 with PredicateDescr

use of org.drools.drl.ast.descr.PredicateDescr in project drools by kiegroup.

the class PatternBuilder method createAndBuildPredicate.

protected Constraint createAndBuildPredicate(RuleBuildContext context, Pattern pattern, BaseDescr base, String expr, Map<String, OperatorDescr> aliases) {
    Dialect dialect = context.getDialect();
    context.setDialect(context.getDialect("mvel"));
    PredicateDescr pdescr = new PredicateDescr(context.getRuleDescr().getResource(), expr);
    pdescr.copyParameters(base);
    pdescr.copyLocation(base);
    Constraint evalConstraint = buildEval(context, pattern, pdescr, aliases, expr, false);
    // fall back to original dialect
    context.setDialect(dialect);
    return evalConstraint;
}
Also used : XpathConstraint(org.drools.core.rule.constraint.XpathConstraint) PredicateConstraint(org.drools.core.rule.PredicateConstraint) NegConstraint(org.drools.core.rule.constraint.NegConstraint) Constraint(org.drools.core.spi.Constraint) Dialect(org.drools.compiler.compiler.Dialect) PredicateDescr(org.drools.drl.ast.descr.PredicateDescr)

Example 4 with PredicateDescr

use of org.drools.drl.ast.descr.PredicateDescr in project drools by kiegroup.

the class MVELConstraintBuilder method buildCompilationUnit.

private MVELCompilationUnit buildCompilationUnit(RuleBuildContext context, Pattern pattern, String expression, Map<String, OperatorDescr> aliases) {
    Dialect dialect = context.getDialect();
    context.setDialect(context.getDialect("mvel"));
    try {
        PredicateDescr predicateDescr = new PredicateDescr(context.getRuleDescr().getResource(), expression);
        AnalysisResult analysis = buildAnalysis(context, pattern, predicateDescr, aliases);
        if (analysis == null) {
            // something bad happened
            return null;
        }
        Declaration[][] usedDeclarations = getUsedDeclarations(context, pattern, analysis);
        return buildCompilationUnit(context, usedDeclarations[0], usedDeclarations[1], predicateDescr, analysis);
    } finally {
        context.setDialect(dialect);
    }
}
Also used : MVELDialect(org.drools.mvel.builder.MVELDialect) Dialect(org.drools.compiler.compiler.Dialect) PredicateDescr(org.drools.drl.ast.descr.PredicateDescr) AnalysisResult(org.drools.compiler.compiler.AnalysisResult) MVELAnalysisResult(org.drools.mvel.builder.MVELAnalysisResult)

Aggregations

PredicateDescr (org.drools.drl.ast.descr.PredicateDescr)4 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)2 Dialect (org.drools.compiler.compiler.Dialect)2 Matcher (java.util.regex.Matcher)1 Declaration (org.drools.core.rule.Declaration)1 PredicateConstraint (org.drools.core.rule.PredicateConstraint)1 NegConstraint (org.drools.core.rule.constraint.NegConstraint)1 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)1 Constraint (org.drools.core.spi.Constraint)1 AtomicExprDescr (org.drools.drl.ast.descr.AtomicExprDescr)1 EvalDescr (org.drools.drl.ast.descr.EvalDescr)1 MVELAnalysisResult (org.drools.mvel.builder.MVELAnalysisResult)1 MVELDialect (org.drools.mvel.builder.MVELDialect)1