ASTRewrite replace and operator precedence [message #248226] |
Thu, 27 September 2007 16:26 |
Eclipse User |
|
|
|
Does anyone know if there's a way to use the ASTRewrite.replace method to
replace one expression with another expression, without inadvertently
changing operator precedence?
For example, suppose I have the expression "f()" that I want to replace
with the expression "a = t" (and both expressions have the same type).
This replacement is only valid some of the time; for example, it generates
invalid code for this case:
if (f() != null)
gets changed to:
if (a = t != null)
which can cause a type error. The problem is that "t" becomes the
left-hand side of the != operator, instead of "a = t". However, my
intension is to replace only the "f()" expression, and not change the
expressions above it in the AST.
Naturally, I could fix this problem by wrapping all expressions in
parentheses. I'm just hoping there's a way to insert the parenthesis only
when they are necessary. Is there a good way to do this?
Thanks,
-Macneil
|
|
|
Powered by
FUDForum. Page generated in 0.03408 seconds