Search in sources :

Example 36 with BindingDescr

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

the class DRL5Expressions method singleRestriction.

// $ANTLR end "andRestriction"
// $ANTLR start "singleRestriction"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:421:1: singleRestriction returns [BaseDescr result] : (op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression ) | LEFT_PAREN or= orRestriction RIGHT_PAREN );
public final BaseDescr singleRestriction() throws RecognitionException {
    BaseDescr result = null;
    ParserRuleReturnScope op = null;
    java.util.List<String> sa = null;
    ParserRuleReturnScope value = null;
    BaseDescr or = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:422:3: (op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression ) | LEFT_PAREN or= orRestriction RIGHT_PAREN )
        int alt44 = 2;
        int LA44_0 = input.LA(1);
        if ((LA44_0 == EQUALS || (LA44_0 >= GREATER && LA44_0 <= GREATER_EQUALS) || (LA44_0 >= LESS && LA44_0 <= LESS_EQUALS) || LA44_0 == NOT_EQUALS || LA44_0 == TILDE)) {
            alt44 = 1;
        } else if ((LA44_0 == ID) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) || ((helper.isPluggableEvaluator(false)))))) {
            alt44 = 1;
        } else if ((LA44_0 == LEFT_PAREN)) {
            alt44 = 2;
        } else {
            if (state.backtracking > 0) {
                state.failed = true;
                return result;
            }
            NoViableAltException nvae = new NoViableAltException("", 44, 0, input);
            throw nvae;
        }
        switch(alt44) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:422:6: op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression )
                {
                    pushFollow(FOLLOW_operator_in_singleRestriction1963);
                    op = operator();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:424:6: ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression )
                    int alt43 = 2;
                    int LA43_0 = input.LA(1);
                    if ((LA43_0 == LEFT_SQUARE)) {
                        int LA43_1 = input.LA(2);
                        if ((synpred11_DRL5Expressions())) {
                            alt43 = 1;
                        } else if ((true)) {
                            alt43 = 2;
                        }
                    } else if ((LA43_0 == BOOL || (LA43_0 >= DECIMAL && LA43_0 <= DECR) || LA43_0 == FLOAT || LA43_0 == HEX || (LA43_0 >= ID && LA43_0 <= INCR) || LA43_0 == LEFT_PAREN || LA43_0 == LESS || LA43_0 == MINUS || LA43_0 == NEGATION || LA43_0 == NULL || LA43_0 == PLUS || (LA43_0 >= STAR && LA43_0 <= TIME_INTERVAL))) {
                        alt43 = 2;
                    } else {
                        if (state.backtracking > 0) {
                            state.failed = true;
                            return result;
                        }
                        NoViableAltException nvae = new NoViableAltException("", 43, 0, input);
                        throw nvae;
                    }
                    switch(alt43) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:424:8: ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression
                            {
                                pushFollow(FOLLOW_squareArguments_in_singleRestriction1992);
                                sa = squareArguments();
                                state._fsp--;
                                if (state.failed)
                                    return result;
                                pushFollow(FOLLOW_shiftExpression_in_singleRestriction1996);
                                value = shiftExpression();
                                state._fsp--;
                                if (state.failed)
                                    return result;
                            }
                            break;
                        case 2:
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:425:10: value= shiftExpression
                            {
                                pushFollow(FOLLOW_shiftExpression_in_singleRestriction2009);
                                value = shiftExpression();
                                state._fsp--;
                                if (state.failed)
                                    return result;
                            }
                            break;
                    }
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            BaseDescr descr = ((value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null) != null && ((!((value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null) instanceof AtomicExprDescr)) || ((value != null ? input.toString(value.start, value.stop) : null).equals(((AtomicExprDescr) (value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null)).getExpression())))) ? (value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null) : new AtomicExprDescr((value != null ? input.toString(value.start, value.stop) : null));
                            result = new RelationalExprDescr((op != null ? ((DRL5Expressions.operator_return) op).opr : null), (op != null ? ((DRL5Expressions.operator_return) op).negated : false), sa, relationalExpression_stack.peek().lsd, descr);
                            if (relationalExpression_stack.peek().lsd instanceof BindingDescr) {
                                relationalExpression_stack.peek().lsd = new AtomicExprDescr(((BindingDescr) relationalExpression_stack.peek().lsd).getExpression());
                            }
                        }
                        helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
                    }
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:440:6: LEFT_PAREN or= orRestriction RIGHT_PAREN
                {
                    match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_singleRestriction2034);
                    if (state.failed)
                        return result;
                    pushFollow(FOLLOW_orRestriction_in_singleRestriction2038);
                    or = orRestriction();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_singleRestriction2040);
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        result = or;
                    }
                }
                break;
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr)

Example 37 with BindingDescr

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

the class DRL5Expressions method unaryExpressionNotPlusMinus.

// $ANTLR start "unaryExpressionNotPlusMinus"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:486:1: unaryExpressionNotPlusMinus returns [BaseDescr result] : ( TILDE unaryExpression | NEGATION unaryExpression | ( castExpression )=> castExpression | ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )? left= primary ( ( selector )=> selector )* ( ( INCR | DECR )=> ( INCR | DECR ) )? );
public final DRL5Expressions.unaryExpressionNotPlusMinus_return unaryExpressionNotPlusMinus() throws RecognitionException {
    DRL5Expressions.unaryExpressionNotPlusMinus_return retval = new DRL5Expressions.unaryExpressionNotPlusMinus_return();
    retval.start = input.LT(1);
    Token var = null;
    Token COLON9 = null;
    Token UNIFY10 = null;
    BaseDescr left = null;
    boolean isLeft = false;
    BindingDescr bind = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:488:5: ( TILDE unaryExpression | NEGATION unaryExpression | ( castExpression )=> castExpression | ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )? left= primary ( ( selector )=> selector )* ( ( INCR | DECR )=> ( INCR | DECR ) )? )
        int alt53 = 4;
        switch(input.LA(1)) {
            case TILDE:
                {
                    alt53 = 1;
                }
                break;
            case NEGATION:
                {
                    alt53 = 2;
                }
                break;
            case LEFT_PAREN:
                {
                    int LA53_3 = input.LA(2);
                    if ((synpred14_DRL5Expressions())) {
                        alt53 = 3;
                    } else if ((true)) {
                        alt53 = 4;
                    }
                }
                break;
            case BOOL:
            case DECIMAL:
            case FLOAT:
            case HEX:
            case ID:
            case LEFT_SQUARE:
            case LESS:
            case NULL:
            case STAR:
            case STRING:
            case TIME_INTERVAL:
                {
                    alt53 = 4;
                }
                break;
            default:
                if (state.backtracking > 0) {
                    state.failed = true;
                    return retval;
                }
                NoViableAltException nvae = new NoViableAltException("", 53, 0, input);
                throw nvae;
        }
        switch(alt53) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:488:9: TILDE unaryExpression
                {
                    match(input, TILDE, FOLLOW_TILDE_in_unaryExpressionNotPlusMinus2371);
                    if (state.failed)
                        return retval;
                    pushFollow(FOLLOW_unaryExpression_in_unaryExpressionNotPlusMinus2373);
                    unaryExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:489:8: NEGATION unaryExpression
                {
                    match(input, NEGATION, FOLLOW_NEGATION_in_unaryExpressionNotPlusMinus2382);
                    if (state.failed)
                        return retval;
                    pushFollow(FOLLOW_unaryExpression_in_unaryExpressionNotPlusMinus2384);
                    unaryExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 3:
                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:490:9: ( castExpression )=> castExpression
                {
                    pushFollow(FOLLOW_castExpression_in_unaryExpressionNotPlusMinus2398);
                    castExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 4:
                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:491:9: ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )? left= primary ( ( selector )=> selector )* ( ( INCR | DECR )=> ( INCR | DECR ) )?
                {
                    if (state.backtracking == 0) {
                        isLeft = helper.getLeftMostExpr() == null;
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:492:9: ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )?
                    int alt50 = 3;
                    int LA50_0 = input.LA(1);
                    if ((LA50_0 == ID)) {
                        int LA50_1 = input.LA(2);
                        if ((LA50_1 == COLON)) {
                            int LA50_3 = input.LA(3);
                            if (((inMap == 0 && ternOp == 0 && input.LA(2) == DRL5Lexer.COLON))) {
                                alt50 = 1;
                            }
                        } else if ((LA50_1 == UNIFY)) {
                            alt50 = 2;
                        }
                    }
                    switch(alt50) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:492:11: ({...}? (var= ID COLON ) )
                            {
                                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:492:11: ({...}? (var= ID COLON ) )
                                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:492:12: {...}? (var= ID COLON )
                                {
                                    if (!((inMap == 0 && ternOp == 0 && input.LA(2) == DRL5Lexer.COLON))) {
                                        if (state.backtracking > 0) {
                                            state.failed = true;
                                            return retval;
                                        }
                                        throw new FailedPredicateException(input, "unaryExpressionNotPlusMinus", "inMap == 0 && ternOp == 0 && input.LA(2) == DRL5Lexer.COLON");
                                    }
                                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:492:75: (var= ID COLON )
                                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:492:76: var= ID COLON
                                    {
                                        var = (Token) match(input, ID, FOLLOW_ID_in_unaryExpressionNotPlusMinus2426);
                                        if (state.failed)
                                            return retval;
                                        COLON9 = (Token) match(input, COLON, FOLLOW_COLON_in_unaryExpressionNotPlusMinus2428);
                                        if (state.failed)
                                            return retval;
                                        if (state.backtracking == 0) {
                                            hasBindings = true;
                                            helper.emit(var, DroolsEditorType.IDENTIFIER_VARIABLE);
                                            helper.emit(COLON9, DroolsEditorType.SYMBOL);
                                            if (buildDescr) {
                                                bind = new BindingDescr((var != null ? var.getText() : null), null, false);
                                                helper.setStart(bind, var);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case 2:
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:494:11: ({...}? (var= ID UNIFY ) )
                            {
                                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:494:11: ({...}? (var= ID UNIFY ) )
                                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:494:12: {...}? (var= ID UNIFY )
                                {
                                    if (!((inMap == 0 && ternOp == 0 && input.LA(2) == DRL5Lexer.UNIFY))) {
                                        if (state.backtracking > 0) {
                                            state.failed = true;
                                            return retval;
                                        }
                                        throw new FailedPredicateException(input, "unaryExpressionNotPlusMinus", "inMap == 0 && ternOp == 0 && input.LA(2) == DRL5Lexer.UNIFY");
                                    }
                                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:494:75: (var= ID UNIFY )
                                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:494:76: var= ID UNIFY
                                    {
                                        var = (Token) match(input, ID, FOLLOW_ID_in_unaryExpressionNotPlusMinus2467);
                                        if (state.failed)
                                            return retval;
                                        UNIFY10 = (Token) match(input, UNIFY, FOLLOW_UNIFY_in_unaryExpressionNotPlusMinus2469);
                                        if (state.failed)
                                            return retval;
                                        if (state.backtracking == 0) {
                                            hasBindings = true;
                                            helper.emit(var, DroolsEditorType.IDENTIFIER_VARIABLE);
                                            helper.emit(UNIFY10, DroolsEditorType.SYMBOL);
                                            if (buildDescr) {
                                                bind = new BindingDescr((var != null ? var.getText() : null), null, true);
                                                helper.setStart(bind, var);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                    }
                    pushFollow(FOLLOW_primary_in_unaryExpressionNotPlusMinus2514);
                    left = primary();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            retval.result = left;
                        }
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:498:9: ( ( selector )=> selector )*
                    loop51: while (true) {
                        int alt51 = 2;
                        int LA51_0 = input.LA(1);
                        if ((LA51_0 == DOT) && (synpred15_DRL5Expressions())) {
                            alt51 = 1;
                        } else if ((LA51_0 == LEFT_SQUARE) && (synpred15_DRL5Expressions())) {
                            alt51 = 1;
                        }
                        switch(alt51) {
                            case 1:
                                // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:498:10: ( selector )=> selector
                                {
                                    pushFollow(FOLLOW_selector_in_unaryExpressionNotPlusMinus2531);
                                    selector();
                                    state._fsp--;
                                    if (state.failed)
                                        return retval;
                                }
                                break;
                            default:
                                break loop51;
                        }
                    }
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            String expr = input.toString(retval.start, input.LT(-1));
                            if (isLeft) {
                                helper.setLeftMostExpr(expr);
                            }
                            if (bind != null) {
                                if (bind.isUnification()) {
                                    expr = expr.substring(expr.indexOf(":=") + 2).trim();
                                } else {
                                    expr = expr.substring(expr.indexOf(":") + 1).trim();
                                }
                                bind.setExpressionAndBindingField(expr);
                                helper.setEnd(bind);
                                retval.result = bind;
                            }
                        }
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:517:9: ( ( INCR | DECR )=> ( INCR | DECR ) )?
                    int alt52 = 2;
                    int LA52_0 = input.LA(1);
                    if ((LA52_0 == DECR || LA52_0 == INCR) && (synpred16_DRL5Expressions())) {
                        alt52 = 1;
                    }
                    switch(alt52) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:517:10: ( INCR | DECR )=> ( INCR | DECR )
                            {
                                if (input.LA(1) == DECR || input.LA(1) == INCR) {
                                    input.consume();
                                    state.errorRecovery = false;
                                    state.failed = false;
                                } else {
                                    if (state.backtracking > 0) {
                                        state.failed = true;
                                        return retval;
                                    }
                                    MismatchedSetException mse = new MismatchedSetException(null, input);
                                    throw mse;
                                }
                            }
                            break;
                    }
                }
                break;
        }
        retval.stop = input.LT(-1);
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return retval;
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr)

Example 38 with BindingDescr

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

the class JavaAccumulateBuilderTest method testBuildRuleBuildContextBaseDescr.

@Test
public void testBuildRuleBuildContextBaseDescr() {
    // $total : Integer() from accumulate( Cheese( $price : price ) init( int x = 0; ) action( x += $price ) result( new Integer( x ) ) )
    AccumulateDescr accumDescr = new AccumulateDescr();
    BindingDescr price = new BindingDescr("$price", "price");
    PatternDescr cheeseDescr = new PatternDescr("org.drools.compiler.Cheese");
    cheeseDescr.addConstraint(price);
    accumDescr.setInputPattern(cheeseDescr);
    accumDescr.setInitCode("int x = 0; int y = 0;");
    accumDescr.setActionCode("x += $price;");
    accumDescr.setResultCode("new Integer( x )");
    // org.drools.core.rule.Package pkg = new org.kie.rule.Package( "org.kie" );
    final KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl();
    pkgBuilder.addPackage(new PackageDescr("org.drools"));
    final KnowledgeBuilderConfigurationImpl conf = pkgBuilder.getBuilderConfiguration();
    PackageRegistry pkgReg = pkgBuilder.getPackageRegistry("org.drools");
    InternalKnowledgePackage pkg = pkgReg.getPackage();
    DialectCompiletimeRegistry dialectRegistry = pkgReg.getDialectCompiletimeRegistry();
    Dialect dialect = dialectRegistry.getDialect("java");
    RuleDescr ruleDescr = new RuleDescr("test rule");
    RuleBuildContext context = new RuleBuildContext(pkgBuilder, ruleDescr, dialectRegistry, pkg, dialect);
    Accumulate accumulate = (Accumulate) builder.build(context, accumDescr);
    String generatedCode = (String) context.getMethods().get(0);
    assertTrue(generatedCode.contains("private int x;"));
    assertTrue(generatedCode.contains("private int y;"));
    assertTrue(generatedCode.contains("x = 0;y = 0;"));
// System.out.println( context.getInvokers() );
// System.out.println( context.getMethods() );
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleBuildContext(org.drools.compiler.rule.builder.RuleBuildContext) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr) Accumulate(org.drools.core.rule.Accumulate) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Dialect(org.drools.compiler.compiler.Dialect) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Example 39 with BindingDescr

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

the class DRLExprParserTest method testDeepBinding.

@Test
public void testDeepBinding() throws Exception {
    String source = "($a : a > $b : b[10].prop || 10 != 20) && $x : someMethod(10) == 20";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    ConstraintConnectiveDescr or = (ConstraintConnectiveDescr) result.getDescrs().get(0);
    assertEquals(ConnectiveType.OR, or.getConnective());
    assertEquals(2, or.getDescrs().size());
    RelationalExprDescr expr = (RelationalExprDescr) or.getDescrs().get(0);
    assertEquals(">", expr.getOperator());
    BindingDescr leftBind = (BindingDescr) expr.getLeft();
    BindingDescr rightBind = (BindingDescr) expr.getRight();
    assertEquals("$a", leftBind.getVariable());
    assertEquals("a", leftBind.getExpression());
    assertEquals("$b", rightBind.getVariable());
    assertEquals("b[10].prop", rightBind.getExpression());
    expr = (RelationalExprDescr) or.getDescrs().get(1);
    assertEquals("!=", expr.getOperator());
    AtomicExprDescr leftExpr = (AtomicExprDescr) expr.getLeft();
    AtomicExprDescr rightExpr = (AtomicExprDescr) expr.getRight();
    assertEquals("10", leftExpr.getExpression());
    assertEquals("20", rightExpr.getExpression());
    expr = (RelationalExprDescr) result.getDescrs().get(1);
    assertEquals("==", expr.getOperator());
    leftBind = (BindingDescr) expr.getLeft();
    rightExpr = (AtomicExprDescr) expr.getRight();
    assertEquals("$x", leftBind.getVariable());
    assertEquals("someMethod(10)", leftBind.getExpression());
    assertEquals("20", rightExpr.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 40 with BindingDescr

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

the class MVELDumperTest method testDumpBindings2.

@Test
public void testDumpBindings2() throws Exception {
    String input = "( $a : a > $b : b[10].prop || 10 != 20 ) && $x : someMethod(10) == 20";
    String expected = "( a > b[10].prop || 10 != 20 ) && someMethod(10) == 20";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(3, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$a", bind.getVariable());
    assertEquals("a", bind.getExpression());
    bind = ctx.getBindings().get(1);
    assertEquals("$b", bind.getVariable());
    assertEquals("b[10].prop", bind.getExpression());
    bind = ctx.getBindings().get(2);
    assertEquals("$x", bind.getVariable());
    assertEquals("someMethod(10)", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) MVELDumperContext(org.drools.compiler.lang.MVELDumper.MVELDumperContext) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Aggregations

BindingDescr (org.drools.compiler.lang.descr.BindingDescr)41 ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)17 Test (org.junit.Test)17 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)12 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)11 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)11 AtomicExprDescr (org.drools.compiler.lang.descr.AtomicExprDescr)10 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)9 Cheese (org.drools.compiler.Cheese)8 AndDescr (org.drools.compiler.lang.descr.AndDescr)8 AnnotatedBaseDescr (org.drools.compiler.lang.descr.AnnotatedBaseDescr)8 RelationalExprDescr (org.drools.compiler.lang.descr.RelationalExprDescr)8 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)7 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)6 MVELDumperContext (org.drools.compiler.lang.MVELDumper.MVELDumperContext)5 ClassObjectType (org.drools.core.base.ClassObjectType)5 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)5 Declaration (org.drools.core.rule.Declaration)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)5 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4