Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 332019

Summary: [quick assist] Exchange operands must add parentheses sometimes
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.7   
Target Milestone: 3.7 M5   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
fix + tests none

Description Markus Keller CLA 2010-12-07 09:03:48 EST
I20101206-1800

Exchange operands quick assist must add parentheses sometimes, e.g. when invoked on the second != in these statements:

	static void foo(int a, long b) {
		System.out.println(b != 0 != (a == b));
		System.out.println(b != 0 != true);
	}
Comment 1 Deepak Azad CLA 2010-12-07 09:53:17 EST
This is not a new problem, it was always there for == operator

	static void foo(int a, long b) {
		System.out.println(b == 0 == (a == b));
		System.out.println(b == 0 == true);
	}
Comment 2 Deepak Azad CLA 2011-01-19 13:31:05 EST
Created attachment 187136 [details]
fix + tests

With the patch parenthesis will be added for both of the following statements. 

static void foo(int a, long b) {
    System.out.println(b != 0 != (a == b)); // Ctrl+1 on second !=
    System.out.println(b > 0 != (a == b));  // Ctrl+1 !=
}

I think it is better to add extra parenthesis in some cases, than produce code with errors.
Comment 3 Deepak Azad CLA 2011-01-19 13:35:47 EST
Fixed in HEAD.