Community
Participate
Working Groups
I20071029-0010 Fup of bug 207332 Given: package test1; public class E1 { protected String foo(String string) { return ("" + string + "") + (""); } } Several test cases: a) 1. Run clean up with option 'remove extra parenthesis' Is: return ("" + string + "") + ""; Should: return "" + string + "" + ""; b) 1. Select '("" + string + "")' 2. Ctrl-1 3. Remove extra parenthesis Is: return ("" + string + "") + (""); Should: return "" + string + "" + (""); c) 1. Set caret at + between the two parenthesized expressions 2. Ctrl-1 3. Exchange left and right operant Is: return ("" + "" + string + ""; Should: return ("") + ("" + string + ""); I've verified my code. In test case b I call (with pExpr=("" + string + "")) ASTNode moveTarget= rewrite.createMoveTarget(pExpr.getExpression()); rewrite.replace(pExpr, moveTarget, null); This results in following text edit: [{MultiTextEdit} [85,16] {MoveTargetEdit} [85,0] {DeleteEdit} [85,16] {MoveSourceEdit} [85,16]] But I guess MoveSourceEdit should be [86,14] ?
Created attachment 81436 [details] test case for a)
Looks like a AST problem: The ParentheziedExpression's range does not include the parenthesis
I'll take a look.
Reproduced. I am investigating.
Created attachment 81468 [details] Proposed fix
Created attachment 81469 [details] Regression test
Frederic, Please review.
Created attachment 81740 [details] Proposed patch I would prefer to add new constructor on BinaryExpression and CombinedBinaryExpression to avoid missing the duplication of this important information (sourceStart, sourceEnd, bits) anywhere this pattern is encountered. This does not add extra time cost and, IMO, make the code safer. What do you think?
+1. Patch look good.
Released for 3.4M4 in HEAD stream.
Verified for 3.4 M4 using build I20071211-0010
Will this bug be fixed in an update to Eclipse 3.3? Or do I have to upgrade to 3.4?