Examples of BoundIdentifiers


Examples of org.drools.compiler.BoundIdentifiers

        setupTest( "", new HashMap<String, Object>() );
        try {
            ruleDescr.setConsequence( consequence );
            JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
            JavaAnalysisResult analysis = (JavaAnalysisResult) analyzer.analyzeBlock( (String) ruleDescr.getConsequence(),
                                                                                      new BoundIdentifiers( new HashMap<String, Class<?>>(), new HashMap<String, Class<?>>() ) );

            String fixed = builder.fixBlockDescr( context,
                                                  (String) ruleDescr.getConsequence(),                                                 
                                                  analysis.getBlockDescrs().getJavaBlockDescrs(),                                                 
                                                  new BoundIdentifiers( new HashMap(), new HashMap() ),
                                                  new HashMap<String,Declaration>() );

            String expected = " System.out.println(\"this is a test\");\n " +
                              " drools.getEntryPoint(\"foo\").insert( new Cheese() );\n " +
                              " System.out.println(\"we are done with entryPoints\");\n ";
View Full Code Here

Examples of org.drools.compiler.BoundIdentifiers

        JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
        Map<String, Class<?>> declrCls = new HashMap<String, Class<?>>();
        declrCls.put( "$cheese", Cheese.class );
       
        JavaAnalysisResult analysis = (JavaAnalysisResult) analyzer.analyzeBlock( (String) ruleDescr.getConsequence(),
                                                                                  new BoundIdentifiers(declrCls, new HashMap<String, Class<?>>() ) );
       
        BoundIdentifiers bindings = new BoundIdentifiers( new HashMap(), new HashMap() );
        bindings.getDeclrClasses().put( "$cheese", Cheese.class );
        bindings.getDeclrClasses().put( "age", int.class );
       
        // Set the inputs for each container, this is needed for modifes when the target context is the result of an expression
        List<JavaBlockDescr> descrs = new ArrayList<JavaBlockDescr>();
        builder.setContainerBlockInputs(context,
                                        descrs,
View Full Code Here

Examples of org.drools.compiler.BoundIdentifiers

        JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
        Map<String, Class<?>> declrCls = new HashMap<String, Class<?>>();
        declrCls.put( "$cheese", Cheese.class );
       
        JavaAnalysisResult analysis = (JavaAnalysisResult) analyzer.analyzeBlock( (String) ruleDescr.getConsequence(),
                                                                                  new BoundIdentifiers(declrCls, new HashMap<String, Class<?>>() ) );
       
        BoundIdentifiers bindings = new BoundIdentifiers( new HashMap(), new HashMap() );
        bindings.getDeclrClasses().put( "$cheese", Cheese.class );
        bindings.getDeclrClasses().put( "age", int.class );
       
        // Set the inputs for each container, this is needed for modifes when the target context is the result of an expression
        List<JavaBlockDescr> descrs = new ArrayList<JavaBlockDescr>();
        builder.setContainerBlockInputs(context,
                                        descrs,
View Full Code Here

Examples of org.drools.compiler.BoundIdentifiers

        JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
        Map<String, Class<?>> declrCls = new HashMap<String, Class<?>>();
        declrCls.put( "$cheese", Cheese.class );
       
        JavaAnalysisResult analysis = (JavaAnalysisResult) analyzer.analyzeBlock( (String) ruleDescr.getConsequence(),
                                                                                  new BoundIdentifiers(declrCls, new HashMap<String, Class<?>>() ) );
       
        BoundIdentifiers bindings = new BoundIdentifiers( new HashMap(), new HashMap() );
        bindings.getDeclrClasses().put( "$cheese", Cheese.class );
        bindings.getDeclrClasses().put( "age", int.class );
       
        // Set the inputs for each container, this is needed for modifes when the target context is the result of an expression
        List<JavaBlockDescr> descrs = new ArrayList<JavaBlockDescr>();
        builder.setContainerBlockInputs(context,
                                        descrs,
View Full Code Here

Examples of org.drools.compiler.compiler.BoundIdentifiers

        Map<String, Class< ? >> globals = context.getPackageBuilder().getGlobals();
        AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                returnValueRestrictionDescr,
                returnValueRestrictionDescr.getContent(),
                new BoundIdentifiers( declarationsMap,
                        globals,
                        null,
                        thisClass ) );
        if ( analysis == null ) {
            // something bad happened
            return null;
        }
        final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();

        final List<Declaration> tupleDeclarations = new ArrayList<Declaration>();
        final List<Declaration> factDeclarations = new ArrayList<Declaration>();
        for ( String id : usedIdentifiers.getDeclrClasses().keySet() ) {
            final Declaration decl = context.getDeclarationResolver().getDeclaration( context.getRule(), id );
            if ( decl.getPattern() == pattern ) {
                factDeclarations.add( decl );
            } else {
                tupleDeclarations.add( decl );
            }
        }
        createImplicitBindings( context,
                pattern,
                analysis.getNotBoundedIdentifiers(),
                usedIdentifiers,
                factDeclarations );

        final Declaration[] previousDeclarations = tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
        final Declaration[] localDeclarations = factDeclarations.toArray( new Declaration[factDeclarations.size()] );

        Arrays.sort( previousDeclarations,
                SortDeclarations.instance );
        Arrays.sort( localDeclarations,
                SortDeclarations.instance );

        final String[] requiredGlobals = usedIdentifiers.getGlobals().keySet().toArray( new String[usedIdentifiers.getGlobals().size()] );

        Declaration[] requiredDeclarations = new Declaration[previousDeclarations.length + localDeclarations.length];
        System.arraycopy( previousDeclarations,
                0,
                requiredDeclarations,
View Full Code Here

Examples of org.drools.compiler.compiler.BoundIdentifiers

        Declaration[][] usedDeclarations = getUsedDeclarations(context, pattern, analysis);
        Declaration[] previousDeclarations = usedDeclarations[0];
        Declaration[] localDeclarations = usedDeclarations[1];

        BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
        String[] requiredGlobals = usedIdentifiers.getGlobals().keySet().toArray( new String[usedIdentifiers.getGlobals().size()] );
        String[] requiredOperators = usedIdentifiers.getOperators().keySet().toArray( new String[usedIdentifiers.getOperators().size()] );

        Arrays.sort( previousDeclarations,
                     SortDeclarations.instance );
        Arrays.sort( localDeclarations,
                     SortDeclarations.instance );
View Full Code Here

Examples of org.drools.compiler.compiler.BoundIdentifiers

            pattern.addConstraint( constraint );
        }
    }

    public static Declaration[][] getUsedDeclarations(RuleBuildContext context, Pattern pattern, AnalysisResult analysis) {
        BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
        final List<Declaration> tupleDeclarations = new ArrayList<Declaration>();
        final List<Declaration> factDeclarations = new ArrayList<Declaration>();

        for ( String id : usedIdentifiers.getDeclrClasses().keySet() ) {
            final Declaration decl = context.getDeclarationResolver().getDeclaration( context.getRule(), id );
            if ( decl.getPattern() == pattern ) {
                factDeclarations.add( decl );
            } else {
                tupleDeclarations.add( decl );
View Full Code Here

Examples of org.drools.compiler.compiler.BoundIdentifiers

        }

        return context.getDialect().analyzeExpression( context,
                                                        predicateDescr,
                                                        predicateDescr.getContent(),
                                                        new BoundIdentifiers( declarations,
                                                                              globals,
                                                                              operators,
                                                                              thisClass ) );
    }
View Full Code Here

Examples of org.drools.compiler.compiler.BoundIdentifiers

                                                                           false );

                final AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                                                                                        descr,
                                                                                        fieldName,
                                                                                        new BoundIdentifiers( declarations,
                                                                                                              globals,
                                                                                                              null,
                                                                                                              ((ClassObjectType) objectType).getClassType() ) );

                if ( analysis == null ) {
                    // something bad happened
                    if ( reportError ) {
                        context.addError(new DescrBuildError(context.getParentDescr(),
                                descr,
                                null,
                                "Unable to analyze expression '" + fieldName + "'"));
                    }
                    return null;
                }

                final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();

                if ( !usedIdentifiers.getDeclrClasses().isEmpty() ) {
                    if ( reportError && descr instanceof BindingDescr ) {
                        context.addError(new DescrBuildError(context.getParentDescr(),
                                descr,
                                null,
                                "Variables can not be used inside bindings. Variable " + usedIdentifiers.getDeclrClasses().keySet() + " is being used in binding '" + fieldName + "'"));
                    }
                    return null;
                }

                reader = context.getPkg().getClassFieldAccessorStore().getMVELReader( context.getPkg().getName(),
View Full Code Here

Examples of org.drools.compiler.compiler.BoundIdentifiers

        Map<String, Class< ? >> globals = context.getKnowledgeBuilder().getGlobals();
        AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                returnValueRestrictionDescr,
                returnValueRestrictionDescr.getContent(),
                new BoundIdentifiers( declarationsMap,
                        globals,
                        null,
                        thisClass ) );
        if ( analysis == null ) {
            // something bad happened
            return null;
        }
        final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();

        final List<Declaration> tupleDeclarations = new ArrayList<Declaration>();
        final List<Declaration> factDeclarations = new ArrayList<Declaration>();
        for ( String id : usedIdentifiers.getDeclrClasses().keySet() ) {
            final Declaration decl = context.getDeclarationResolver().getDeclaration( context.getRule(), id );
            if ( decl.getPattern() == pattern ) {
                factDeclarations.add( decl );
            } else {
                tupleDeclarations.add( decl );
            }
        }
        createImplicitBindings( context,
                pattern,
                analysis.getNotBoundedIdentifiers(),
                usedIdentifiers,
                factDeclarations );

        final Declaration[] previousDeclarations = tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
        final Declaration[] localDeclarations = factDeclarations.toArray( new Declaration[factDeclarations.size()] );

        Arrays.sort( previousDeclarations,
                SortDeclarations.instance );
        Arrays.sort( localDeclarations,
                SortDeclarations.instance );

        final String[] requiredGlobals = usedIdentifiers.getGlobals().keySet().toArray( new String[usedIdentifiers.getGlobals().size()] );

        Declaration[] requiredDeclarations = new Declaration[previousDeclarations.length + localDeclarations.length];
        System.arraycopy( previousDeclarations,
                0,
                requiredDeclarations,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.