Search in sources :

Example 6 with MutableTypeConstraint

use of org.drools.core.rule.MutableTypeConstraint in project drools by kiegroup.

the class JavaAccumulateBuilder method bindReaderToDeclaration.

private void bindReaderToDeclaration(RuleBuildContext context, AccumulateDescr accumDescr, Pattern pattern, AccumulateFunctionCallDescr fc, InternalReadAccessor readAccessor, Class<?> resultType, int index) {
    if (fc.getBind() != null) {
        if (context.getDeclarationResolver().isDuplicated(context.getRule(), fc.getBind(), resultType.getName())) {
            if (!fc.isUnification()) {
                context.addError(new DescrBuildError(context.getParentDescr(), accumDescr, null, "Duplicate declaration for variable '" + fc.getBind() + "' in the rule '" + context.getRule().getName() + "'"));
            } else {
                Declaration inner = context.getDeclarationResolver().getDeclaration(fc.getBind());
                Constraint c = new MvelConstraint(Collections.singletonList(context.getPkg().getName()), index >= 0 ? "this[ " + index + " ] == " + fc.getBind() : "this == " + fc.getBind(), new Declaration[] { inner }, null, null, IndexUtil.ConstraintType.EQUAL, context.getDeclarationResolver().getDeclaration(fc.getBind()), index >= 0 ? new ArrayElementReader(readAccessor, index, resultType) : readAccessor, true);
                ((MutableTypeConstraint) c).setType(Constraint.ConstraintType.BETA);
                pattern.addConstraint(c);
            }
        } else {
            Declaration declr = pattern.addDeclaration(fc.getBind());
            declr.setReadAccessor(readAccessor);
        }
    }
}
Also used : DescrBuildError(org.drools.compiler.compiler.DescrBuildError) MutableTypeConstraint(org.drools.core.rule.MutableTypeConstraint) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) Constraint(org.drools.core.spi.Constraint) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) MutableTypeConstraint(org.drools.core.rule.MutableTypeConstraint) ArrayElementReader(org.drools.core.base.extractors.ArrayElementReader) Declaration(org.drools.core.rule.Declaration)

Aggregations

MutableTypeConstraint (org.drools.core.rule.MutableTypeConstraint)6 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)6 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)4 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 ArrayElementReader (org.drools.core.base.extractors.ArrayElementReader)2 Declaration (org.drools.core.rule.Declaration)2 Constraint (org.drools.core.spi.Constraint)2 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)1 AccumulateFunctionCallDescr (org.drools.compiler.lang.descr.AccumulateDescr.AccumulateFunctionCallDescr)1 MVELAccumulatorFunctionExecutor (org.drools.core.base.accumulators.MVELAccumulatorFunctionExecutor)1 SelfReferenceClassFieldReader (org.drools.core.base.extractors.SelfReferenceClassFieldReader)1 MVELAccumulator (org.drools.core.base.mvel.MVELAccumulator)1 MVELCompilationUnit (org.drools.core.base.mvel.MVELCompilationUnit)1 IndexableConstraint (org.drools.core.rule.IndexableConstraint)1 Pattern (org.drools.core.rule.Pattern)1 Accumulator (org.drools.core.spi.Accumulator)1 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)1 MvelAccumulator (org.drools.core.spi.MvelAccumulator)1 AccumulateFunction (org.kie.api.runtime.rule.AccumulateFunction)1