Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
Consider the following hand created AST and UnparseVisitor:
ExpressionStatement es = new Java.ExpressionStatement(
new Java.Assignment( null,
new Java.AmbiguousName( null, new String[] { "x" }),
"=",
new Java.BinaryOperation(null,
new Java.Literal(null, Integer.valueOf(1)),
"*",
new Java.BinaryOperation(null,
new Java.Literal(null, Integer.valueOf(2)),
"+",
new Java.Literal(null, Integer.valueOf(3)),
)
)
)
);
StringWriter sw = new StringWriter();
UnparseVisitor uv = new UnparseVisitor(sw);
uv.visitExpressionStatement(es);
sw will contain "x = 1 * 2 + 3;" it should contain something more like "x = 1 * (2 + 3);" to handle the precedence difference in '+' and '*'.
This is even worse for Unary '!' and "instanceof", because the generated code won't compile without the parentheses.
I am part way through an implementation of this. But I wanted to get the bug written down in case I get pulled of the problem.