[jboss-svn-commits] JBL Code SVN: r13267 - in labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect: mvel and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 9 14:22:34 EDT 2007


Author: tirelli
Date: 2007-07-09 14:22:34 -0400 (Mon, 09 Jul 2007)
New Revision: 13267

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java
Log:
Adding code analysis for reverse code block when available

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java	2007-07-09 18:22:18 UTC (rev 13266)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java	2007-07-09 18:22:34 UTC (rev 13267)
@@ -48,15 +48,15 @@
     AccumulateBuilder {
 
     public RuleConditionElement build(final RuleBuildContext context,
-                                    final BaseDescr descr) {
+                                      final BaseDescr descr) {
         return build( context,
                       descr,
                       null );
     }
 
     public RuleConditionElement build(final RuleBuildContext context,
-                                    final BaseDescr descr,
-                                    final Pattern prefixPattern) {
+                                      final BaseDescr descr,
+                                      final Pattern prefixPattern) {
 
         final AccumulateDescr accumDescr = (AccumulateDescr) descr;
 
@@ -119,24 +119,32 @@
             final String className = "Accumulate" + context.getNextId();
             accumDescr.setClassName( className );
 
-            final JavaAnalysisResult analysis1 = (JavaAnalysisResult) context.getDialect().analyzeBlock( context,
+            final JavaAnalysisResult initCodeAnalysis = (JavaAnalysisResult) context.getDialect().analyzeBlock( context,
                                                                                                          accumDescr,
                                                                                                          accumDescr.getInitCode() );
-            final Dialect.AnalysisResult analysis2 = context.getDialect().analyzeBlock( context,
+            final Dialect.AnalysisResult actionCodeAnalysis = context.getDialect().analyzeBlock( context,
                                                                                         accumDescr,
                                                                                         accumDescr.getActionCode() );
-            final Dialect.AnalysisResult analysis3 = context.getDialect().analyzeExpression( context,
+            final Dialect.AnalysisResult resultCodeAnalysis = context.getDialect().analyzeExpression( context,
                                                                                              accumDescr,
                                                                                              accumDescr.getResultCode() );
 
-            final List requiredDeclarations = new ArrayList( analysis1.getBoundIdentifiers()[0] );
-            requiredDeclarations.addAll( analysis2.getBoundIdentifiers()[0] );
-            requiredDeclarations.addAll( analysis3.getBoundIdentifiers()[0] );
+            final List requiredDeclarations = new ArrayList( initCodeAnalysis.getBoundIdentifiers()[0] );
+            requiredDeclarations.addAll( actionCodeAnalysis.getBoundIdentifiers()[0] );
+            requiredDeclarations.addAll( resultCodeAnalysis.getBoundIdentifiers()[0] );
 
-            final List requiredGlobals = new ArrayList( analysis1.getBoundIdentifiers()[1] );
-            requiredGlobals.addAll( analysis2.getBoundIdentifiers()[1] );
-            requiredGlobals.addAll( analysis3.getBoundIdentifiers()[1] );
+            final List requiredGlobals = new ArrayList( initCodeAnalysis.getBoundIdentifiers()[1] );
+            requiredGlobals.addAll( actionCodeAnalysis.getBoundIdentifiers()[1] );
+            requiredGlobals.addAll( resultCodeAnalysis.getBoundIdentifiers()[1] );
 
+            if ( accumDescr.getReverseCode() != null ) {
+                final Dialect.AnalysisResult reverseCodeAnalysis = context.getDialect().analyzeBlock( context,
+                                                                                                      accumDescr,
+                                                                                                      accumDescr.getActionCode() );
+                requiredDeclarations.addAll( reverseCodeAnalysis.getBoundIdentifiers()[0] );
+                requiredGlobals.addAll( reverseCodeAnalysis.getBoundIdentifiers()[1] );
+            }
+
             final Declaration[] declarations = new Declaration[requiredDeclarations.size()];
             for ( int i = 0, size = requiredDeclarations.size(); i < size; i++ ) {
                 declarations[i] = context.getDeclarationResolver().getDeclaration( (String) requiredDeclarations.get( i ) );
@@ -157,15 +165,15 @@
             map.put( "innerDeclarations",
                      sourceDeclArr );
 
-            final String initCode = this.fixInitCode( analysis1,
+            final String initCode = this.fixInitCode( initCodeAnalysis,
                                                       accumDescr.getInitCode() );
             final String actionCode = accumDescr.getActionCode();
             final String resultCode = accumDescr.getResultCode();
 
-            String[] attributesTypes = new String[analysis1.getLocalVariablesMap().size()];
-            String[] attributes = new String[analysis1.getLocalVariablesMap().size()];
+            String[] attributesTypes = new String[initCodeAnalysis.getLocalVariablesMap().size()];
+            String[] attributes = new String[initCodeAnalysis.getLocalVariablesMap().size()];
             int index = 0;
-            for ( Iterator it = analysis1.getLocalVariablesMap().entrySet().iterator(); it.hasNext(); ) {
+            for ( Iterator it = initCodeAnalysis.getLocalVariablesMap().entrySet().iterator(); it.hasNext(); ) {
                 Map.Entry entry = (Map.Entry) it.next();
                 attributes[index] = (String) entry.getKey();
                 attributesTypes[index] = ((JavaLocalDeclarationDescr) entry.getValue()).getType();

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java	2007-07-09 18:22:18 UTC (rev 13266)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java	2007-07-09 18:22:34 UTC (rev 13267)
@@ -104,27 +104,34 @@
                                                                function );
         } else {
             // it is a custom accumulate
-            final Dialect.AnalysisResult analysis1 = context.getDialect().analyzeBlock( context,
+            final Dialect.AnalysisResult initCodeAnalysis = context.getDialect().analyzeBlock( context,
                                                                                         accumDescr,
                                                                                         accumDescr.getInitCode() );
-            final Dialect.AnalysisResult analysis2 = context.getDialect().analyzeBlock( context,
+            final Dialect.AnalysisResult actionCodeAnalysis = context.getDialect().analyzeBlock( context,
                                                                                         accumDescr,
                                                                                         accumDescr.getActionCode() );
-            final Dialect.AnalysisResult analysis3 = context.getDialect().analyzeExpression( context,
+            final Dialect.AnalysisResult resultCodeAnalysis = context.getDialect().analyzeExpression( context,
                                                                                              accumDescr,
                                                                                              accumDescr.getResultCode() );
 
-            final List requiredDeclarations = new ArrayList( analysis1.getBoundIdentifiers()[0] );
-            requiredDeclarations.addAll( analysis2.getBoundIdentifiers()[0] );
-            requiredDeclarations.addAll( analysis3.getBoundIdentifiers()[0] );
+            final List requiredDeclarations = new ArrayList( initCodeAnalysis.getBoundIdentifiers()[0] );
+            requiredDeclarations.addAll( actionCodeAnalysis.getBoundIdentifiers()[0] );
+            requiredDeclarations.addAll( resultCodeAnalysis.getBoundIdentifiers()[0] );
 
+            if ( accumDescr.getReverseCode() != null ) {
+                final Dialect.AnalysisResult reverseCodeAnalysis = context.getDialect().analyzeBlock( context,
+                                                                                                      accumDescr,
+                                                                                                      accumDescr.getActionCode() );
+                requiredDeclarations.addAll( reverseCodeAnalysis.getBoundIdentifiers()[0] );
+            }
+
             declarations = new Declaration[requiredDeclarations.size()];
             for ( int i = 0, size = requiredDeclarations.size(); i < size; i++ ) {
                 declarations[i] = context.getDeclarationResolver().getDeclaration( (String) requiredDeclarations.get( i ) );
             }
             
-            final Serializable init = dialect.compile( (String) accumDescr.getInitCode(), analysis1, null, context );
-            final Serializable action = dialect.compile((String) accumDescr.getActionCode(), analysis2, null, context );
+            final Serializable init = dialect.compile( (String) accumDescr.getInitCode(), initCodeAnalysis, null, context );
+            final Serializable action = dialect.compile((String) accumDescr.getActionCode(), actionCodeAnalysis, null, context );
 
             
            
@@ -137,12 +144,12 @@
             if ( accumDescr.getReverseCode() != null ) {
 //                reverse = MVEL.compileExpression( (String) accumDescr.getReverseCode(),
 //                                                  ((MVELDialect) context.getDialect()).getClassImportResolverFactory().getImportedClasses() );
-                reverse = dialect.compile( (String) accumDescr.getReverseCode(), analysis3, null, context );
+                reverse = dialect.compile( (String) accumDescr.getReverseCode(), resultCodeAnalysis, null, context );
             }
 //            final Serializable result = MVEL.compileExpression( (String) accumDescr.getResultCode(),
 //                                                                ((MVELDialect) context.getDialect()).getClassImportResolverFactory().getImportedClasses() );
 
-            final Serializable result = dialect.compile((String) accumDescr.getResultCode(), analysis3, null, context );
+            final Serializable result = dialect.compile((String) accumDescr.getResultCode(), resultCodeAnalysis, null, context );
             
             accumulator = new MVELAccumulator( factory,
                                                init,




More information about the jboss-svn-commits mailing list