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

Bug 334876

Summary: [quick assist] Invert conditions generates incorrect code
Product: [Eclipse Project] JDT Reporter: Viliam Durina <viliam>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad
Version: 3.7   
Target Milestone: 3.7 M5   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
fix+test none

Description Viliam Durina CLA 2011-01-20 07:11:56 EST
Build Identifier: 20100917-0705

Let a and b be of Object type, the following expression:

  a == null ^ b == null

is inverted incorrectly to:

  !a == null ^ b == null

which does not compile (The operator ! is undefined for the argument type(s) Object). The correct result should be:

  a != null ^ b == null

It seems, that left-hand side argument is simply prefixed with !, but it should be recursively inverted as a separate expression.

Reproducible: Always
Comment 1 Deepak Azad CLA 2011-01-20 07:26:56 EST
-------------------------------------------------------
	void foo(Object a, Object b) {
		 if(a == null ^ b == null ){
			 
		 }
	}
-------------------------------------------------------

Invert conditions quick assist results in the following => Parentheses are missing
-------------------------------------------------------
	void foo(Object a, Object b) {
		 if(!a == null ^ b == null ){
			 
		 }
	}
-------------------------------------------------------
Comment 2 Deepak Azad CLA 2011-01-20 09:03:45 EST
I will take a look.

Fix will go in AdvancedQuickAssistProcessor.getInversedExpression(ASTRewrite, Expression, SimpleNameRenameProvider) line 533. In the fall back case we should first create a ParenthesizedExpression and then invert it.
Comment 3 Deepak Azad CLA 2011-01-22 01:50:49 EST
Created attachment 187354 [details]
fix+test
Comment 4 Deepak Azad CLA 2011-01-22 01:51:32 EST
Fixed in HEAD.