Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331195 - [quick assist] 'Introduce new local with cast type' should be available at more locations
Summary: [quick assist] 'Introduce new local with cast type' should be available at mo...
Status: VERIFIED 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 M4   Edit
Assignee: Deepak Azad CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 104395 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-11-26 06:32 EST by Deepak Azad CLA
Modified: 2011-05-03 09:51 EDT (History)
4 users (show)

See Also:
markus.kell.r: review+


Attachments
fix + tests (11.53 KB, patch)
2010-11-28 03:26 EST, Deepak Azad CLA
no flags Details | Diff
final fix + tests (13.02 KB, patch)
2010-11-29 12:51 EST, Deepak Azad CLA
no flags Details | Diff
additional fix + tests (4.66 KB, patch)
2010-12-07 23:07 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 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.