Package org.drools.compiler.lang.descr

Examples of org.drools.compiler.lang.descr.RuleDescr


    @Test
    public void testFromWithTernaryFollowedByQuery() throws Exception {
        // the 'from' expression requires a ";" to disambiguate the "?"
        // prefix for queries from the ternary operator "? :"
        final String text = "rule X when Cheese() from (isFull ? $cheesery : $market) ?person( \"Mark\", 42; ) then end";
        RuleDescr rule = (RuleDescr) parse( "rule",
                                             text );
        assertFalse( parser.getErrors().toString(),
                     parser.hasErrors() );

        PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Cheese",
                      pattern.getObjectType() );
        assertEquals( "from (isFull ? $cheesery : $market)",
                      pattern.getSource().getText() );
        assertFalse( pattern.isQuery() );

        pattern = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "person",
                      pattern.getObjectType() );
        assertTrue( pattern.isQuery() );

    }
View Full Code Here


    @Test
    public void testMultiValueAnnotationsBackwardCompatibility() throws Exception {
        // multiple values with no keys are parsed as a single value
        final String text = "rule X @ann1( val1, val2 ) @ann2( \"val1\", \"val2\" ) when then end";
        RuleDescr rule = (RuleDescr) parse( "rule",
                                             text );

        AnnotationDescr ann = rule.getAnnotation( "ann1" );
        assertNotNull( ann );
        assertEquals( "val1, val2",
                      ann.getValue() );

        ann = rule.getAnnotation( "ann2" );
        assertNotNull( ann );
        assertEquals( "\"val1\", \"val2\"",
                      ann.getValue() );
    }
View Full Code Here

        assertEquals( "org.drools",
                      pkg.getName() );
        assertEquals( 1,
                      pkg.getRules().size() );

        RuleDescr rd = pkg.getRules().get(0);

        assertEquals( "X",
                      rd.getName() );
        assertEquals( 1,
                      rd.getLhs().getDescrs().size() );

        PatternDescr pd = (PatternDescr) rd.getLhs().getDescrs().get(0);
        assertNotNull( pd );
        assertEquals( "StockTick",
                      pd.getObjectType() );
        assertEquals( "Y",
                      pd.getSource().getText() );
View Full Code Here

     * This will add the rule for compiling later on.
     * It will not actually call the compiler
     */
    public void addRule(final RuleBuildContext context) {
        final RuleImpl rule = context.getRule();
        final RuleDescr ruleDescr = context.getRuleDescr();

        RuleClassBuilder classBuilder = context.getDialect().getRuleClassBuilder();

        String ruleClass = classBuilder.buildRule( context );
        // return if there is no ruleclass name;
        if ( ruleClass == null ) {
            return;
        }

        // The compilation result is for the entire rule, so difficult to associate with any descr
        addClassCompileTask( this.pkg.getName() + "." + ruleDescr.getClassName(),
                             ruleDescr,
                             ruleClass,
                             this.src,
                             new RuleErrorHandler( ruleDescr,
                                                   rule,
                                                   "Rule Compilation error" ) );

        JavaDialectRuntimeData data = (JavaDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData( ID );

        for ( Map.Entry<String, String> invokers : context.getInvokers().entrySet() ) {
            final String className = invokers.getKey();

            // Check if an invoker - returnvalue, predicate, eval or consequence has been associated
            // If so we add it to the PackageCompilationData as it will get wired up on compilation
            final Object invoker = context.getInvokerLookups().get( className );
            if ( invoker != null ) {
                data.putInvoker( className,
                                 invoker );
            }
            final String text = invokers.getValue();

            final BaseDescr descr = (BaseDescr) context.getDescrLookups().get( className );
            addClassCompileTask( className,
                                 descr,
                                 text,
                                 this.src,
                                 new RuleInvokerErrorHandler( descr,
                                                              rule,
                                                              "Unable to generate rule invoker." ) );

        }

        // setup the line mappins for this rule
        final String name = this.pkg.getName() + "." + StringUtils.ucFirst( ruleDescr.getClassName() );
        final LineMappings mapping = new LineMappings( name );
        mapping.setStartLine( ruleDescr.getConsequenceLine() );
        mapping.setOffset( ruleDescr.getConsequenceOffset() );

        this.pkg.getDialectRuntimeRegistry().getLineMappings().put( name,
                                                                    mapping );

    }
View Full Code Here

         assertEquals( 1,
                       desc.getRules().size() );
         assertEquals( 1,
                       packageAttrs.size() );

         RuleDescr rule = (RuleDescr) desc.getRules().get( 0 );
         Map<String, AttributeDescr> ruleAttrs = rule.getAttributes();
         assertEquals( 1,
                       ruleAttrs.size() );

         assertEquals( "mvel",
                       ((AttributeDescr) ruleAttrs.get( "dialect" )).getValue() );
View Full Code Here

                                                          "globals.drl" );

        assertEquals( 1,
                      pack.getRules().size() );

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

        assertEquals( 1,
                      pack.getImports().size() );
        assertEquals( 2,
                      pack.getGlobals().size() );
View Full Code Here

                                                 source );

        assertFalse( parser.getErrorMessages().toString(),
                     parser.hasErrors() );

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( "Invalid customer id",
                      rule.getName() );

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

        NotDescr not = (NotDescr) rule.getLhs().getDescrs().get( 1 );
        PatternDescr customer = (PatternDescr) not.getDescrs().get( 0 );

        assertEquals( "Customer",
                      customer.getObjectType() );
        assertEquals( "customerService.getCustomer(o.getCustomerId())",
View Full Code Here

        PackageDescr pkg = (PackageDescr) parse( "compilationUnit",
                                                 source );
        assertFalse( parser.getErrors().toString(),
                     parser.hasErrors() );

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( "XYZ",
                      rule.getName() );

        PatternDescr number = (PatternDescr) ((NotDescr) rule.getLhs().getDescrs().get( 1 )).getDescrs().get( 0 );
        assertEquals( "[1, 2, 3]",
                      ((FromDescr) number.getSource()).getDataSource().toString() );

    }
View Full Code Here

        PackageDescr pkg = (PackageDescr) parse( "compilationUnit",
                                                 source );
        assertFalse( parser.getErrors().toString(),
                     parser.hasErrors() );

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( "XYZ",
                      rule.getName() );

        assertFalse( parser.hasErrors() );
        PatternDescr number = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "[1, 2, 3].sublist(1, 2)",
                      ((FromDescr) number.getSource()).getDataSource().toString() );

    }
View Full Code Here

        PackageDescr pkg = (PackageDescr) parse( "compilationUnit",
                                                 source );
        assertFalse( parser.getErrors().toString(),
                     parser.hasErrors() );

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( "XYZ",
                      rule.getName() );

        assertFalse( parser.hasErrors() );
        PatternDescr number = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "[1, 2, 3][1]",
                      ((FromDescr) number.getSource()).getDataSource().toString() );
    }
View Full Code Here

TOP

Related Classes of org.drools.compiler.lang.descr.RuleDescr

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.