Package org.drools.lang.descr

Examples of org.drools.lang.descr.AtomicExprDescr


                      or.getDescrs().size() );

        RelationalExprDescr expr = (RelationalExprDescr) or.getDescrs().get( 0 );
        assertEquals( ">",
                      expr.getOperator() );
        AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
        AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
        assertEquals( "a",
                      left.getExpression() );
        assertEquals( "b",
                      right.getExpression() );

        expr = (RelationalExprDescr) or.getDescrs().get( 1 );
        assertEquals( "!=",
                      expr.getOperator() );
        left = (AtomicExprDescr) expr.getLeft();
        right = (AtomicExprDescr) expr.getRight();
        assertEquals( "10",
                      left.getExpression() );
        assertEquals( "20",
                      right.getExpression() );

        expr = (RelationalExprDescr) result.getDescrs().get( 1 );
        assertEquals( "==",
                      expr.getOperator() );
        left = (AtomicExprDescr) expr.getLeft();
        right = (AtomicExprDescr) expr.getRight();
        assertEquals( "someMethod(10)",
                      left.getExpression() );
        assertEquals( "20",
                      right.getExpression() );

    }
View Full Code Here


        assertEquals( "$x",
                      bind.getVariable() );
        assertEquals( "property",
                      bind.getExpression() );

        AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
        assertEquals( "value",
                      right.getExpression() );
    }
View Full Code Here

        assertEquals( "$x",
                      bind.getVariable() );
        assertEquals( "property",
                      bind.getExpression() );

        AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
        assertEquals( "value",
                      right.getExpression() );
       
        rel = (RelationalExprDescr) result.getDescrs().get( 1 );
        assertEquals( "<",
                      rel.getOperator() );

        AtomicExprDescr left = (AtomicExprDescr) rel.getLeft();
        assertEquals( "property",
                      left.getExpression() );

        right = (AtomicExprDescr) rel.getRight();
        assertEquals( "20",
                      right.getExpression() );
    }
View Full Code Here

                      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() );

    }
View Full Code Here

    @Test
    public void testProcessInlineCast() throws Exception {
        String expr = "field1#Class.field2";
        String expectedInstanceof = "field1 instanceof Class";
        String expectedcasted = "((Class)field1).field2";
        AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
        ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr(  );
            ccd.addDescr( atomicExpr );
        String[] instanceofAndCastedExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null);
        assertEquals( 2, ccd.getDescrs().size() );
        assertEquals( expectedInstanceof, ccd.getDescrs().get( 0 ).toString() );
        assertEquals(expectedcasted, atomicExpr.getRewrittenExpression());

        expr = "field1#Class1.field2#Class2.field3";
        String expectedInstanceof1 = "field1 instanceof Class1";
        String expectedInstanceof2 = "((Class1)field1).field2 instanceof Class2";
        expectedcasted = "((Class2)((Class1)field1).field2).field3";
        atomicExpr = new AtomicExprDescr(expr);
        ccd = new ConstraintConnectiveDescr(  );
        instanceofAndCastedExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null);
        assertEquals( expectedInstanceof1, ccd.getDescrs().get( 0 ).toString() );
        assertEquals( expectedInstanceof2, ccd.getDescrs().get( 1 ).toString() );
        assertEquals(expectedcasted, instanceofAndCastedExpr[1]);
        assertEquals(expectedcasted, atomicExpr.getRewrittenExpression());
    }
View Full Code Here

    @Test
    public void testProcessNullSafeDereferencing() throws Exception {
        String expr = "field1!.field2";
        String expectedNullCheck = "field1 != null";
        String expectedExpr = "field1.field2";
        AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
        ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr(  );
        String[] nullCheckAndExpr = dumper.processImplicitConstraints( expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null );
        assertEquals( expectedNullCheck, ccd.getDescrs().get( 0 ).toString() );
        assertEquals(expectedExpr, nullCheckAndExpr[1]);
        assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());

        expr = "field1!.field2!.field3";
        String expectedNullCheck1 = "field1 != null";
        String expectedNullCheck2 = "field1.field2 != null";
        expectedExpr = "field1.field2.field3";
        atomicExpr = new AtomicExprDescr(expr);
        ccd = new ConstraintConnectiveDescr(  );
        nullCheckAndExpr = dumper.processImplicitConstraints( expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null );
        assertEquals( expectedNullCheck1, ccd.getDescrs().get( 0 ).toString() );
        assertEquals( expectedNullCheck2, ccd.getDescrs().get( 1 ).toString() );
        assertEquals(expectedExpr, nullCheckAndExpr[1]);
        assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
    }
View Full Code Here

    @Test
    public void testProcessImplicitConstraints() throws Exception {
        String expr = "field1#Class!.field2";
        String expectedConstraints = "field1 instanceof Class";
        String expectedExpr = "((Class)field1).field2";
        AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
        ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr(  );
        String[] constraintsAndExpr = dumper.processImplicitConstraints( expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null );
        assertEquals( expectedConstraints, ccd.getDescrs().get( 0 ).toString() );
        assertEquals(expectedExpr, constraintsAndExpr[1]);
        assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());

        expr = "field1!.field2#Class.field3";
        String expectedConstraints1 = "field1 != null";
        String expectedConstraints2 = "field1.field2 instanceof Class";
        expectedExpr = "((Class)field1.field2).field3";
        atomicExpr = new AtomicExprDescr(expr);
        ccd = new ConstraintConnectiveDescr(  );
        constraintsAndExpr = dumper.processImplicitConstraints( expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null );
        assertEquals( expectedConstraints1, ccd.getDescrs().get( 0 ).toString() );
        assertEquals( expectedConstraints2, ccd.getDescrs().get( 1 ).toString() );
        assertEquals(expectedExpr, constraintsAndExpr[1]);
        assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());

        expr = "field1#Class.field2!.field3";
        expectedConstraints1 = "field1 instanceof Class";
        expectedConstraints2 = "((Class)field1).field2 != null";
        expectedExpr = "((Class)field1).field2.field3";
        atomicExpr = new AtomicExprDescr(expr);
        ccd = new ConstraintConnectiveDescr(  );
        constraintsAndExpr = dumper.processImplicitConstraints( expr, atomicExpr, ccd, ccd.getDescrs().indexOf( atomicExpr ), null );
        assertEquals( expectedConstraints1, ccd.getDescrs().get( 0 ).toString() );
        assertEquals( expectedConstraints2, ccd.getDescrs().get( 1 ).toString() );
        assertEquals(expectedExpr, constraintsAndExpr[1]);
        assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
    }
View Full Code Here

                    state._fsp--;
                    if (state.failed) return result;
                    if ( state.backtracking==0 ) {
                       if( buildDescr  ) {
                                     result = new RelationalExprDescr( (op!=null?input.toString(op.start,op.stop):null), false, null, left, new AtomicExprDescr((right!=null?input.toString(right.start,right.stop):null)) );
                                 }
                              
                    }

                    }
View Full Code Here

            if (state.failed) return result;
            if ( state.backtracking==0 ) {
               if( buildDescr  ) { result = left; }
                    if( left instanceof BindingDescr ) {
                        binding = (BindingDescr)left;
                        leftDescr = new AtomicExprDescr( binding.getExpression() );
                    } else {
                        leftDescr = left;
                    }
                 
            }
View Full Code Here

               if( buildDescr  ) {
                        result = ( (left!=null?left.result:null) != null &&
                                    ( (!((left!=null?left.result:null) instanceof AtomicExprDescr)) ||
                                      ((left!=null?input.toString(left.start,left.stop):null).equals(((AtomicExprDescr)(left!=null?left.result:null)).getExpression())) )) ?
                                  (left!=null?left.result:null) :
                                  new AtomicExprDescr( (left!=null?input.toString(left.start,left.stop):null) ) ;
                        ((relationalExpression_scope)relationalExpression_stack.peek()).lsd = result;
                    }
                    helper.emit( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
                 
            }
View Full Code Here

TOP

Related Classes of org.drools.lang.descr.AtomicExprDescr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.