Community
Participate
Working Groups
The 'exchange left and right operands for infix expression' incorrectly removes parentheses that can be necessary for the statement to evaluate correctly if it contains logical operators. e.g., private boolean isEnabled(byte[] masterBits) { return (0 == (masterBits[ENABLE_INDEX] & ENABLE_MASK)); } Applying the 'exchange left and right' operator, Eclipse removes the parantheses on the right and side and _incorrectly_ turns the method into: private boolean isEnabled(byte[] masterBits) { return (masterBits[ENABLE_INDEX] & ENABLE_MASK == 0); } This yields the Java compile error: 'The operator & is undefined for the argument type(s) byte, boolean' It should have refactored to: private boolean isEnabled(byte[] masterBits) { return ((masterBits[ENABLE_INDEX] & ENABLE_MASK) == 0); }
Move to JDT/UI
The same is true for boolean operators; in the following, exchanging the operands of && drops the parentheses around the ||. import java.util.Set; public class TestInfixSwap { public boolean test (Set s, int i) { return (i == 0 || i == 1) && s.size () > 0; } }
This also happens with arithmetic operators: int n = 4 * (2 + 3); becomes int n = 2 + 3 * 4;
*** Bug 312474 has been marked as a duplicate of this bug. ***
Created attachment 182948 [details] fix + tests
Fixed in HEAD.