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

Bug 331195

Summary: [quick assist] 'Introduce new local with cast type' should be available at more locations
Product: [Eclipse Project] JDT Reporter: Deepak Azad <deepakazad>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akiezun, daniel_megert, markus.kell.r, raksha.vasisht
Version: 3.7Flags: markus.kell.r: review+
Target Milestone: 3.7 M4   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
fix + tests
none
final fix + tests
none
additional fix + tests none

Description Deepak Azad CLA 2010-11-26 06:32:24 EST
The quick assist is available only on 'instanceof' keyword, which is a bit irritating.

Object obj = s;
if(obj instanceof String){
     |                   //I typically want the quick assist on this line
}

The quick assist can be made available
- Inside the if/while blocks, if the block is empty and the condition is an InstanceofExpression
- anywhere in the if/while statement's expression

Fix will go in AdvancedQuickAssistProcessor#getCastAndAssignIfStatementProposals(..)
Comment 1 Deepak Azad CLA 2010-11-28 03:26:53 EST
Created attachment 183993 [details]
fix + tests
Comment 2 Markus Keller CLA 2010-11-29 07:08:19 EST
Cool, thanks. Please release.

We could even go one step further and also enable it if the caret is before the first statement in the block (bug 104395 comment 2).
Comment 3 Markus Keller CLA 2010-11-29 07:08:40 EST
*** Bug 104395 has been marked as a duplicate of this bug. ***
Comment 4 Deepak Azad CLA 2010-11-29 12:51:58 EST
Created attachment 184059 [details]
final fix + tests

(In reply to comment #2)
> We could even go one step further and also enable it if the caret is before the
> first statement in the block (bug 104395 comment 2).
Done this as well.
Comment 5 Deepak Azad CLA 2010-11-29 12:52:18 EST
Fixed in HEAD.
Comment 6 Raksha Vasisht CLA 2010-12-07 10:14:26 EST
The quick assist should also work for a non-block if-statement just as it works when ctrl+1 is invoked on 'instanceof' keyword. It creates the new local var and surrounds it with curly braces. 

Ex:
if(obj instanceof String)
   |                   // show quick assist here
Comment 7 Deepak Azad CLA 2010-12-07 23:07:36 EST
Created attachment 184770 [details]
additional fix + tests

(In reply to comment #6)
> The quick assist should also work for a non-block if-statement just as it works
> when ctrl+1 is invoked on 'instanceof' keyword. It creates the new local var
> and surrounds it with curly braces. 
> 
> Ex:
> if(obj instanceof String)
>    |                   // show quick assist here

Fair enough. Fixed in this case
	void bar(Object obj) {		
		if(obj instanceof String)
		     |	          //invoke quick assist here
                     return;
	}

Note that it will still not work in the following case
	void bar(Object obj) {		
		if(obj instanceof String)
		     |	          //invoke quick assist here
	}
This case is a bit tricky as in this case the if statement is not complete and the AST tells that the quick assist is invoked on the method declaration block.
Comment 8 Deepak Azad CLA 2010-12-07 23:09:30 EST
(In reply to comment #7)
> Created an attachment (id=184770) [details] [diff]
> additional fix + tests
Fixed in HEAD.
Comment 9 Dani Megert CLA 2011-05-03 09:51:08 EDT
Verified in 3.7 M7.