Bug 435772 - [refactoring] Extract constant / local variable / method doesn't work with certain whitespace selections
Summary: [refactoring] Extract constant / local variable / method doesn't work with ce...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-26 08:35 EDT by Markus Keller CLA
Modified: 2020-04-05 15:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2014-05-26 08:35:50 EDT
Extract constant / local variable / method refactorings don't work with certain selections that contain whitespace.

Example:

class Test {
	{
		 foo( "bla" ) ;
	}
	static int foo(String s) {
		return s.length();
	}
}

If whitespace before and/or after "bla" is selected, all Extract... refactorings still show up and work fine.

If whitespace after foo( "bla" ) is selected, then the Extract... refactorings work fine, but if whitespace before foo( "bla" ) is selected, they don't show up.

The problem is that SelectionAnalyzer only skips whitespace that belongs to the directly enclosing node (the ExpressionStatement in this case), but the whitespace in front of foo belongs to the enclosing Block.
Comment 1 Timo Kinnunen CLA 2014-05-30 16:47:48 EDT
See also bug 428139: [extract local] Extract local variable should be possible without selection

This works for me from all caret positions on the the foo( "bla" ) ; line, but under the condition that no text has been selected. 

An explicitly selected text range is another thing. Should we respect the user's choice when the text range is invalid for the particular action or try to interpret it as something else? I thought I knew the answer but apparently the answer is something else, because I see a Quick Assist called "Assign statement to a new local variable" which shows up for this snippet even if the line comment is the only thing selected:

class Test {
	{
		foo("bla")

		// select this comment and assign me to a variable

		;
	}

	static int foo(String s) {
		return s.length();
	}
}
Comment 2 Eclipse Genie CLA 2020-04-05 15:32:57 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.