-
Bug
-
Resolution: Done
-
Major
-
5.0.0.CR1
DrlDumper does wrong dumps, when lhs contains complex conditions with And.
When there is ConditionalElementDescr in other ConditionalElementDescr, DrlDumper prints condition without round brackets. But should, because formed text can not be parsed with DrlParser into the same tree structure.
Example 1.
rule in file "Test1.drl":
rule "continued_rule"
no-loop true
when
($a : Action1() || $b : Action2())
&&
($c : Action3() || $d : Action4())
then
System.out.println("Fired.");
end
And method:
public void test1() throws DroolsParserException
{
DrlParser parser = new DrlParser();
final InputStream drl = getClass().getResourceAsStream(
"Test1.drl");
final PackageDescr packageDescr = parser.parse(drl);
if (parser.hasErrors())
final String dump = new DrlDumper().dump(packageDescr);
System.out.println(dump);
}
Output is:
rule "continued_rule"
no-loop true
when
$a : Action1( ) || $b : Action2( ) && $c : Action3( ) || $d : Action4( )
then
System.out.println("Fired.");
end
According to operation priority in this case will be
$a : Action1( ) || ($b : Action2( ) && $c : Action3( )) || $d : Action4( )
and it is quite another operation.
DrlDumper should support brackets to save operation grouping.
Example 2.
Rule
rule "continued_rule2"
no-loop true
when
($a : Action1() && $b : Action2())
($c : Action3() && $d : Action4())
then
System.out.println("Fired.");
end
Out after performing test1() from Example 1:
rule "continued_rule"
no-loop true
when
$a : Action1( ) || $c : Action3( )
then
System.out.println("Fired.");
end
DrlDumper lost $b : Action2() and $d : Action4()! It happened because processOrDescrList in DrlDumper.
In string
if ( descrString.endsWith( DrlDumper.eol ) )
we lose all subconditions except first line. It should be
if ( descrString.endsWith( DrlDumper.eol ) )
.