Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » ASTRewrite replace and operator precedence
ASTRewrite replace and operator precedence [message #248226] Thu, 27 September 2007 16:26
Eclipse UserFriend
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
Previous Topic:Question on Marker use (APT vs. JavaModel)
Next Topic:Java compare tool/API run thru command line
Goto Forum:
  


Current Time: Fri May 02 01:25:50 EDT 2025

Powered by FUDForum. Page generated in 0.03408 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top