Package org.drools.compiler

Examples of org.drools.compiler.AnalysisResult


            // This builder is re-usable in other dialects, so specify by name           
            MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );
           
            Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());

            AnalysisResult analysis = dialect.analyzeExpression( context,
                                                                 context.getRuleDescr(),
                                                                 (String) context.getRuleDescr().getSalience(),
                                                                 new BoundIdentifiers(context.getDeclarationResolver().getDeclarationClasses( decls ),
                                                                                      context.getPackageBuilder().getGlobals() ) );

            final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
            int i = usedIdentifiers.getDeclarations().keySet().size();
            Declaration[] previousDeclarations = new Declaration[i];
            i = 0;
            for ( String id :  usedIdentifiers.getDeclarations().keySet() ) {
                previousDeclarations[i++] = decls.get( id );
View Full Code Here


            otherVars.put( "rule",
                           org.drools.rule.Rule.class );

            Map<String, Declaration> declrs = context.getDeclarationResolver().getDeclarations( context.getRule() );

            AnalysisResult analysis = dialect.analyzeExpression( context,
                                                                 context.getRuleDescr(),
                                                                 (String) context.getRuleDescr().getEnabled(),
                                                                 new BoundIdentifiers( context.getDeclarationResolver().getDeclarationClasses( declrs ),
                                                                                       context.getPackageBuilder().getGlobals() ),
                                                                 otherVars );

            final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
            int i = usedIdentifiers.getDeclarations().keySet().size();
            Declaration[] previousDeclarations = new Declaration[i];
            i = 0;
            for ( String id :  usedIdentifiers.getDeclarations().keySet() ) {
                previousDeclarations[i++] = declrs.get( id );
View Full Code Here

            text = processMacros( text );
           
            Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
           
            AnalysisResult analysis = dialect.analyzeBlock( context,
                                                            context.getRuleDescr(),
                                                            dialect.getInterceptors(),
                                                            text,
                                                            new BoundIdentifiers(context.getDeclarationResolver().getDeclarationClasses( decls ),
                                                                                 context.getPackageBuilder().getGlobals(),
                                                                                 null,
                                                                                 KnowledgeHelper.class),
                                                            null,
                                                            "drools",
                                                            KnowledgeHelper.class );
           
            if ( analysis == null ) {
                // something bad happened, issue already logged in errors
                return;
            }
           
            final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
           
            final Declaration[] declarations =  new Declaration[usedIdentifiers.getDeclarations().size()];
            String[] declrStr = new String[declarations.length];
            int j = 0;
            for (String str : usedIdentifiers.getDeclarations().keySet() ) {
View Full Code Here

                                                                  null,
                                                                  "Unknown accumulate function: '"+func.getFunction()+"' on rule '"+context.getRuleDescr().getName()+"'. All accumulate functions must be registered before building a resource." ) );
                    return null;
                }

                final AnalysisResult analysis = dialect.analyzeExpression( context,
                                                                           accumDescr,
                                                                           func.getParams()[0],
                                                                           boundIds );

               
                MVELCompilationUnit unit = dialect.getMVELCompilationUnit( func.getParams()[0],
                                                                           analysis,
                                                                           getUsedDeclarations( decls, analysis ),
                                                                           getUsedDeclarations( sourceOuterDeclr, analysis ),
                                                                           null,
                                                                           context,
                                                                           "drools",
                                                                           KnowledgeHelper.class );

                accumulator = new MVELAccumulatorFunctionExecutor( unit,
                                                                   function );
            } else {
                // it is a custom accumulate
                final MVELAnalysisResult initCodeAnalysis = (MVELAnalysisResult) dialect.analyzeBlock( context,
                                                                                                       accumDescr,
                                                                                                       accumDescr.getInitCode(),
                                                                                                       boundIds);


                // need to copy boundIds, as this as a "this" object.
                final MVELAnalysisResult actionCodeAnalysis = (MVELAnalysisResult) dialect.analyzeBlock( context,
                                                                                                         accumDescr,
                                                                                                         null,
                                                                                                         accumDescr.getActionCode(),
                                                                                                         boundIds,
                                                                                                         initCodeAnalysis.getMvelVariables(),
                                                                                                         "drools",
                                                                                                         KnowledgeHelper.class );
               
                final MVELAnalysisResult resultCodeAnalysis = (MVELAnalysisResult) dialect.analyzeExpression( context,
                                                                                                              accumDescr,
                                                                                                              accumDescr.getResultCode(),
                                                                                                              boundIds,
                                                                                                              initCodeAnalysis.getMvelVariables() );

                AnalysisResult reverseCodeAnalysis = null;
                if ( accumDescr.getReverseCode() != null ) {
                    reverseCodeAnalysis = dialect.analyzeBlock( context,
                                                                accumDescr,
                                                                null,
                                                                accumDescr.getActionCode(),
                                                                boundIds,
                                                                initCodeAnalysis.getMvelVariables(),
                                                                "drools",
                                                                KnowledgeHelper.class );
                }

               
                MVELCompilationUnit initUnit = dialect.getMVELCompilationUnit( (String) accumDescr.getInitCode(),
                                                                               initCodeAnalysis,
                                                                               getUsedDeclarations( decls, initCodeAnalysis ),
                                                                               getUsedDeclarations( sourceOuterDeclr, initCodeAnalysis ),
                                                                               initCodeAnalysis.getMvelVariables(),
                                                                               context,
                                                                               "drools",
                                                                               KnowledgeHelper.class );

                MVELCompilationUnit actionUnit = dialect.getMVELCompilationUnit( (String) accumDescr.getActionCode(),
                                                                                 actionCodeAnalysis,
                                                                                 getUsedDeclarations( decls, actionCodeAnalysis ),
                                                                                 getUsedDeclarations( sourceOuterDeclr, actionCodeAnalysis ),
                                                                                 initCodeAnalysis.getMvelVariables(),
                                                                                 context,
                                                                                 "drools",
                                                                                 KnowledgeHelper.class );

                MVELCompilationUnit reverseUnit = null;
                if ( accumDescr.getReverseCode() != null ) {
                    reverseUnit = dialect.getMVELCompilationUnit( (String) accumDescr.getReverseCode(),
                                                                  reverseCodeAnalysis,
                                                                  getUsedDeclarations( decls, reverseCodeAnalysis ),
                                                                  getUsedDeclarations( sourceOuterDeclr, reverseCodeAnalysis ),
                                                                  initCodeAnalysis.getMvelVariables(),
                                                                  context,
                                                                  "drools",
                                                                  KnowledgeHelper.class );
                }

                MVELCompilationUnit resultUnit = dialect.getMVELCompilationUnit( (String) accumDescr.getResultCode(),
                                                                                 resultCodeAnalysis,
                                                                                 getUsedDeclarations( decls, resultCodeAnalysis ),
                                                                                 getUsedDeclarations( sourceOuterDeclr, resultCodeAnalysis ),
                                                                                 initCodeAnalysis.getMvelVariables(),
                                                                                 context,
                                                                                 "drools",
                                                                                 KnowledgeHelper.class );

                if ( reverseUnit != null ) {
                    Set<String> shadow = new HashSet<String>( source.getOuterDeclarations().keySet() );
                    shadow.retainAll( reverseCodeAnalysis.getNotBoundedIdentifiers() );
                    shadow.addAll( reverseCodeAnalysis.getBoundIdentifiers().getDeclarations().keySet() );

                    String[] shadowVars = (String[]) shadow.toArray( new String[shadow.size()] );
                   
                    actionUnit.setShadowIdentifiers( shadowVars );
                    reverseUnit.setShadowIdentifiers( shadowVars );
View Full Code Here

            MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );
           
            Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());

            String text = (String) expr.getText();
            AnalysisResult analysis = dialect.analyzeExpression( context,
                                                                 descr,
                                                                 text,
                                                                 new BoundIdentifiers(context.getDeclarationResolver().getDeclarationClasses( decls ),
                                                                                      context.getPackageBuilder().getGlobals() ) );
            if ( analysis == null ) {
                // something bad happened
                return null;
            }
           
            final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();           
            final Declaration[] declarations =  new Declaration[usedIdentifiers.getDeclarations().size()];
            String[] declrStr = new String[declarations.length];
            int j = 0;
            for (String str : usedIdentifiers.getDeclarations().keySet() ) {
                declrStr[j] = str;
View Full Code Here

        try {
            MVELDialect dialect = (MVELDialect) context.getDialect( context.getDialect().getId() );

            Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
           
            AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                                                                              evalDescr,
                                                                              evalDescr.getContent(),
                                                                              new BoundIdentifiers(context.getDeclarationResolver().getDeclarationClasses( decls ),
                                                                                                   context.getPackageBuilder().getGlobals() ) );

            final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
            int i = usedIdentifiers.getDeclarations().keySet().size();
            Declaration[] previousDeclarations = new Declaration[i];
            i = 0;
            for ( String id :  usedIdentifiers.getDeclarations().keySet() ) {
                previousDeclarations[i++] = decls.get( id );
View Full Code Here

                                                    final BaseDescr descr,
                                                    final Object content,
                                                    final BoundIdentifiers availableIdentifiers,
                                                    final Map<String, Class<?>> localTypes) {

        AnalysisResult result = null;
        try {
            result = analyzer.analyzeExpression( context,
                                                 (String) content,
                                                 availableIdentifiers,
                                                 localTypes,
View Full Code Here

                                               final BoundIdentifiers availableIdentifiers,
                                               final Map<String, Class<?>> localTypes,
                                               String contextIndeifier,
                                               Class kcontextClass) {

        AnalysisResult result = null;
        result = analyzer.analyzeExpression( context,
                                             text,
                                             availableIdentifiers,
                                             localTypes,
                                             contextIndeifier,
View Full Code Here

            final JavaAnalysisResult initCodeAnalysis = (JavaAnalysisResult) context.getDialect().analyzeBlock( context,
                                                                                                                accumDescr,
                                                                                                                accumDescr.getInitCode(),
                                                                                                                available );
            final AnalysisResult actionCodeAnalysis = context.getDialect().analyzeBlock( context,
                                                                                         accumDescr,
                                                                                         accumDescr.getActionCode(),
                                                                                         available );
           
            final AnalysisResult resultCodeAnalysis = context.getDialect().analyzeExpression( context,
                                                                                                      accumDescr,
                                                                                                      accumDescr.getResultCode(),
                                                                                                      available );

            final Set<String> requiredDeclarations = new HashSet<String>( initCodeAnalysis.getBoundIdentifiers().getDeclarations().keySet() );
            requiredDeclarations.addAll( actionCodeAnalysis.getBoundIdentifiers().getDeclarations().keySet() );
            requiredDeclarations.addAll( resultCodeAnalysis.getBoundIdentifiers().getDeclarations().keySet() );

            final Map<String, Class<?>> requiredGlobals = new HashMap<String, Class<?>>( initCodeAnalysis.getBoundIdentifiers().getGlobals() );
            requiredGlobals.putAll( actionCodeAnalysis.getBoundIdentifiers().getGlobals() );
            requiredGlobals.putAll( resultCodeAnalysis.getBoundIdentifiers().getGlobals() );

            if ( accumDescr.getReverseCode() != null ) {
                final AnalysisResult reverseCodeAnalysis = context.getDialect().analyzeBlock( context,
                                                                                                      accumDescr,
                                                                                                      accumDescr.getActionCode(),
                                                                                                      available );
                requiredDeclarations.addAll( reverseCodeAnalysis.getBoundIdentifiers().getDeclarations().keySet() );
                requiredGlobals.putAll( reverseCodeAnalysis.getBoundIdentifiers().getGlobals() );
            }

           
           
            final Declaration[] declarations = new Declaration[requiredDeclarations.size()];
View Full Code Here

        Class< ? > thisClass = null;
        if ( pattern.getObjectType() instanceof ClassObjectType ) {
            thisClass = ((ClassObjectType) pattern.getObjectType()).getClassType();
        }

        final AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                                                                                predicateDescr,
                                                                                predicateDescr.getContent(),
                                                                                new BoundIdentifiers( declarations,
                                                                                                      globals,
                                                                                                      operators,
                                                                                                      thisClass ) );

        if ( analysis == null ) {
            // something bad happened
            return;
        }

        final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();

        final List tupleDeclarations = new ArrayList();
        final List factDeclarations = new ArrayList();
        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 );
            }
        }
        this.createImplicitBindings( context,
                                     pattern,
                                     analysis.getNotBoundedIdentifiers(),
                                     analysis.getBoundIdentifiers(),
                                     factDeclarations );

        final Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
        final Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
        final String[] requiredGlobals = usedIdentifiers.getGlobals().keySet().toArray( new String[usedIdentifiers.getGlobals().size()] );
View Full Code Here

TOP

Related Classes of org.drools.compiler.AnalysisResult

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.