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

Bug 69450

Summary: [extract local] Refactor -> Extract local variable doesn't ignore whitespace in selection [refactoring]
Product: [Eclipse Project] JDT Reporter: Alex Blewitt <alex.blewitt>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: bugzilla, daniel_megert
Version: 3.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Refactoring works with selected semicolon
none
Refactoring does not work without selected semicolon none

Description Alex Blewitt CLA 2004-07-07 05:59:50 EDT
I used Refactor -> Extract local variable on the following piece of code:

[ getPattern().matcher(line).matches();]
^^ note space in beginning of selection

I was told that in order to use the Extract Local, I had to select an expression.

Getting rid of the space that I'd highlighted, it worked fine:
[getPattern().matcher(line).matches();]

Matcher matcher = getPattern().matcher(line);
matcher.matches();

It seems that ignoring whitespace would be trivial and that it wouldn't need to prevent such extractions 
from happening.

Mac OS X.3.4 (though suspect platform agnostic) on Eclipse 3.0 final.
Comment 1 Olivier Thomann CLA 2004-07-07 10:48:56 EDT
Move to JDT/UI
Comment 2 Dirk Baeumer CLA 2004-07-08 06:17:32 EDT
We should indeed try to me a little bit smarter here.
Comment 3 Andre Weinand CLA 2005-03-24 07:48:18 EST
[does not seem to be Mac specific. Setting Hardware & OS to "All"]
Comment 4 Martin Aeschlimann CLA 2006-08-03 11:42:21 EDT
no plans for this at the moment.
Comment 5 Denis Roy CLA 2009-08-30 02:20:21 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.
Comment 6 Nils Hartmann CLA 2013-01-09 05:07:19 EST
Any plans to fix this issue? 

BTW: in some cases "Extract local variable" works even with selecteded the leading whitespace:

[ getPattern()] works (even though Eclipse correctly reports a compile error on that line due to the missing ';')
[ getPattern();] selecting everything including the ';' work
[ getPattern();] selecting everything but not the ';' does NOT work


(Tested with Eclipse 4.2.0)
Comment 7 Dani Megert CLA 2013-01-09 06:54:47 EST
(In reply to comment #6)
> Any plans to fix this issue? 
> 
> BTW: in some cases "Extract local variable" works even with selecteded the
> leading whitespace:
> 
> [ getPattern()] works (even though Eclipse correctly reports a compile error
> on that line due to the missing ';')
> [ getPattern();] selecting everything including the ';' work
> [ getPattern();] selecting everything but not the ';' does NOT work
> 
> 
> (Tested with Eclipse 4.2.0)

I think you got it wrong. If the ';' is also selected then the refactoring is not available which is expected. The whitespace bug got fixed a while go.
Comment 8 Nils Hartmann CLA 2013-01-09 09:57:02 EST
Created attachment 225384 [details]
Refactoring works with selected semicolon
Comment 9 Nils Hartmann CLA 2013-01-09 09:57:41 EST
Created attachment 225385 [details]
Refactoring does not work without selected semicolon
Comment 10 Nils Hartmann CLA 2013-01-09 09:58:37 EST
Please see the two screenshot that shows the behaviour in my Java editor (Eclipse 4.2.0)
Comment 11 Dani Megert CLA 2013-01-09 10:59:57 EST
(In reply to comment #10)
> Please see the two screenshot that shows the behaviour in my Java editor
> (Eclipse 4.2.0)

I see. But still, the white psace itself is no longer a problem.