Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334876 - [quick assist] Invert conditions generates incorrect code
Summary: [quick assist] Invert conditions generates incorrect code
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Deepak Azad CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-20 07:11 EST by Viliam Durina CLA
Modified: 2011-01-22 01:51 EST (History)
1 user (show)

See Also:


Attachments
fix+test (5.34 KB, patch)
2011-01-22 01:50 EST, Deepak Azad CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.