Package org.drools.lang.descr

Examples of org.drools.lang.descr.PatternDescr


        parseResource( "soundslike_operator.drl" ).compilation_unit();
        assertFalse( this.parser.getErrorMessages().toString(),
                     this.parser.hasErrors() );

        RuleDescr rule = (RuleDescr) this.parser.getPackageDescr().getRules().get( 0 );
        PatternDescr pat = (PatternDescr) rule.getLhs().getDescrs().get( 0 );

        pat.getConstraint();
    }
View Full Code Here


    }

    public void testEndPosition() throws Exception {
        parseResource( "test_EndPosition.drl" ).compilation_unit();
        final RuleDescr rule = (RuleDescr) this.parser.getPackageDescr().getRules().get( 0 );
        final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( 6,
                      col.getLine() );

        assertEquals( 8,
                      col.getEndLine() );

    }
View Full Code Here

        assertFalse( this.parser.hasErrors() );

        final PackageDescr pkg = this.parser.getPackageDescr();
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );

        final PatternDescr p = (PatternDescr) rule.getLhs().getDescrs().get( 0 );

        assertEquals( "com.cheeseco.Cheese",
                      p.getObjectType() );
    }
View Full Code Here

                      pack.getRules().size() );
        final RuleDescr rule = (RuleDescr) pack.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
        assertEqualsIgnoreWhitespace( "int x = 0 ;",
                                      accum.getInitCode() );
        assertEqualsIgnoreWhitespace( "x++;",
                                      accum.getActionCode() );
        assertNull( accum.getReverseCode() );
        assertEqualsIgnoreWhitespace( "new Integer(x)",
                                      accum.getResultCode() );

        assertFalse( accum.isExternalFunction() );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Person",
                      pattern.getObjectType() );
    }
View Full Code Here

                      pack.getRules().size() );
        final RuleDescr rule = (RuleDescr) pack.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
        assertEqualsIgnoreWhitespace( "$counter",
                                      outPattern.getIdentifier() );
        assertEqualsIgnoreWhitespace( "int x = 0 ;",
                                      accum.getInitCode() );
        assertEqualsIgnoreWhitespace( "x++;",
                                      accum.getActionCode() );
        assertEqualsIgnoreWhitespace( "new Integer(x)",
                                      accum.getResultCode() );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Person",
                      pattern.getObjectType() );
    }
View Full Code Here

                      pack.getRules().size() );
        final RuleDescr rule = (RuleDescr) pack.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        final CollectDescr collect = (CollectDescr) outPattern.getSource();

        final PatternDescr pattern = (PatternDescr) collect.getInputPattern();
        assertEquals( "Person",
                      pattern.getObjectType() );
    }
View Full Code Here

                      rule.getName() );
        assertEquals( 2,
                      rule.getLhs().getDescrs().size() );

        //The first pattern, with 2 restrictions on a single field (plus a connective)
        PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Person",
                      pattern.getObjectType() );
        assertEquals( 1,
                      pattern.getConstraint().getDescrs().size() );

        AndDescr and = (AndDescr) pattern.getConstraint();
        FieldConstraintDescr fld = (FieldConstraintDescr) and.getDescrs().get( 0 );
        assertEquals( RestrictionConnectiveDescr.AND,
                      ((RestrictionConnectiveDescr) fld.getRestriction()).getConnective() );
        assertEquals( 2,
                      fld.getRestrictions().size() );
        assertEquals( "age",
                      fld.getFieldName() );

        LiteralRestrictionDescr lit = (LiteralRestrictionDescr) fld.getRestrictions().get( 0 );
        assertEquals( ">",
                      lit.getEvaluator() );
        assertEquals( "30",
                      lit.getText() );

        lit = (LiteralRestrictionDescr) fld.getRestrictions().get( 1 );
        assertEquals( "<",
                      lit.getEvaluator() );
        assertEquals( "40",
                      lit.getText() );

        //the second col, with 2 fields, the first with 2 restrictions, the second field with one
        pattern = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "Vehicle",
                      pattern.getObjectType() );
        assertEquals( 2,
                      pattern.getConstraint().getDescrs().size() );

        and = (AndDescr) pattern.getConstraint();
        fld = (FieldConstraintDescr) and.getDescrs().get( 0 );
        assertEquals( "type",
                      fld.getFieldName() );
        assertEquals( 1,
                      fld.getRestrictions().size() );
View Full Code Here

        assertEquals( 3,
                      lhs.getDescrs().size() );

        // Check first pattern
        final PatternDescr first = (PatternDescr) lhs.getDescrs().get( 0 );
        assertEquals( "foo3",
                      first.getIdentifier() );
        assertEquals( "Bar",
                      first.getObjectType() );
        assertEquals( 1,
                      first.getConstraint().getDescrs().size() );

        // Check second pattern
        final PatternDescr second = (PatternDescr) lhs.getDescrs().get( 1 );
        assertEquals( "foo4",
                      second.getIdentifier() );
        assertEquals( "Bar",
                      second.getObjectType() );

        final PatternDescr third = (PatternDescr) lhs.getDescrs().get( 2 );
        assertEquals( "Baz",
                      third.getObjectType() );

        assertEquals( 4,
                      first.getLine() );
        assertEquals( 5,
                      second.getLine() );
        assertEquals( 6,
                      third.getLine() );
        assertFalse( this.parser.hasErrors() );
    }
View Full Code Here

                      lhs.getDescrs().size() );

        //System.err.println( lhs.getDescrs() );

        // Check first pattern
        final PatternDescr first = (PatternDescr) lhs.getDescrs().get( 0 );
        assertEquals( "foo3",
                      first.getIdentifier() );
        assertEquals( "Bar",
                      first.getObjectType() );

        assertEquals( 1,
                      first.getConstraint().getDescrs().size() );

        //LiteralDescr constraint = (LiteralDescr) first.getDescrs().get( 0 );
        AndDescr and = (AndDescr) first.getConstraint();
        FieldConstraintDescr fld = (FieldConstraintDescr) and.getDescrs().get( 0 );
        LiteralRestrictionDescr constraint = (LiteralRestrictionDescr) fld.getRestrictions().get( 0 );

        assertNotNull( constraint );

        assertEquals( "a",
                      fld.getFieldName() );
        assertEquals( "==",
                      constraint.getEvaluator() );
        assertEquals( "3",
                      constraint.getText() );

        // Check second pattern
        final PatternDescr second = (PatternDescr) lhs.getDescrs().get( 1 );
        assertEquals( "foo4",
                      second.getIdentifier() );
        assertEquals( "Bar",
                      second.getObjectType() );

        and = (AndDescr) second.getConstraint();
        assertEquals( 2,
                      and.getDescrs().size() );

        //System.err.println( second.getDescrs() );

        final FieldBindingDescr fieldBindingDescr = (FieldBindingDescr) and.getDescrs().get( 0 );
        assertEquals( "a",
                      fieldBindingDescr.getFieldName() );
        assertEquals( "a4",
                      fieldBindingDescr.getIdentifier() );

        fld = (FieldConstraintDescr) and.getDescrs().get( 1 );

        constraint = (LiteralRestrictionDescr) fld.getRestrictions().get( 0 );

        assertNotNull( constraint );

        assertEquals( "a",
                      fld.getFieldName() );
        assertEquals( "==",
                      constraint.getEvaluator() );
        assertEquals( "4",
                      constraint.getText() );

        // Check third pattern
        final PatternDescr third = (PatternDescr) lhs.getDescrs().get( 2 );
        assertNull( third.getIdentifier() );
        assertEquals( "Baz",
                      third.getObjectType() );

        assertEqualsIgnoreWhitespace( "if ( a == b ) { " + "  assert( foo3 );" + "} else {" + "  retract( foo4 );" + "}" + "  System.out.println( a4 );",
                                      (String) rule.getConsequence() );

        assertFalse( this.parser.hasErrors() );
View Full Code Here

        assertEquals( 1,
                      lhs.getDescrs().size() );
        final NotDescr not = (NotDescr) lhs.getDescrs().get( 0 );
        assertEquals( 1,
                      not.getDescrs().size() );
        final PatternDescr pattern = (PatternDescr) not.getDescrs().get( 0 );

        assertEquals( "Cheese",
                      pattern.getObjectType() );
        assertEquals( 1,
                      pattern.getConstraint().getDescrs().size() );

        final AndDescr and = (AndDescr) pattern.getConstraint();
        final FieldConstraintDescr fld = (FieldConstraintDescr) and.getDescrs().get( 0 );
        final LiteralRestrictionDescr lit = (LiteralRestrictionDescr) fld.getRestrictions().get( 0 );

        assertEquals( "==",
                      lit.getEvaluator() );
View Full Code Here

TOP

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

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.