|
From: <jbo...@li...> - 2006-06-29 22:01:00
|
Author: mar...@jb...
Date: 2006-06-29 18:00:55 -0400 (Thu, 29 Jun 2006)
New Revision: 4874
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
Log:
JBRULES-308 Binding to an existing declartion should throw an error
-Throws an error for rebinding on fields, but not column.
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java 2006-06-29 19:29:37 UTC (rev 4873)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java 2006-06-29 22:00:55 UTC (rev 4874)
@@ -430,11 +430,11 @@
final FieldBindingDescr fieldBindingDescr) {
Declaration declaration = (Declaration) this.declarations.get( fieldBindingDescr.getIdentifier() );
if ( declaration != null ) {
- // This declaration already exists, so make it a bound variable declaration instead
- build( column,
- new BoundVariableDescr( fieldBindingDescr.getFieldName(),
- "==",
- fieldBindingDescr.getIdentifier() ) );
+ // This declaration already exists, so throw an Exception
+ this.errors.add( new RuleError( this.rule,
+ fieldBindingDescr,
+ null,
+ "Duplicate declaration for variable '" + fieldBindingDescr.getIdentifier() + "' in the rule '" + this.rule.getName() + "'" ) );
return;
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2006-06-29 19:29:37 UTC (rev 4873)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2006-06-29 22:00:55 UTC (rev 4874)
@@ -52,6 +52,7 @@
import org.drools.lang.descr.RuleDescr;
import org.drools.reteoo.ReteooRuleBase;
import org.drools.rule.And;
+import org.drools.rule.BoundVariableConstraint;
import org.drools.rule.Column;
import org.drools.rule.Declaration;
import org.drools.rule.EvalCondition;
@@ -818,7 +819,14 @@
builder.addPackage( packageDescr );
And and = builder.getPackage().getRule( "rule-1" ).getLhs();
- and.getChildren().get( 0 );
+ Column c1 = (Column) and.getChildren().get( 0 );
+ assertEquals( Declaration.class, c1.getConstraints().get( 0 ).getClass() );
+ assertEquals( LiteralConstraint.class, c1.getConstraints().get( 1 ).getClass() );
+
+ Column c2 = (Column) and.getChildren().get( 1 );
+ assertEquals( BoundVariableConstraint.class, c1.getConstraints().get( 0 ).getClass() );
+// c1.getConstraints().get( 0 )
+// Column c2 = (Column) and.getChildren().get( 1 );
assertLength( 0,
builder.getErrors() );
|