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

Bug 41302

Summary: [quick assist] [extract method] Calling extract method from a selection
Product: [Eclipse Project] JDT Reporter: Pascal Rapicault <pascal>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, dirk_baeumer, frederic_fusier, markus.kell.r, reprogrammer
Version: 3.0   
Target Milestone: 3.8 M5   
Hardware: PC   
OS: Windows 2000   
See Also: https://git.eclipse.org/r/41302
Whiteboard:
Bug Depends on: 81784    
Bug Blocks:    

Description Pascal Rapicault CLA 2003-08-07 17:56:04 EDT
In 3.0M2
If you select the following code (up to the very last character) and ask 
for "extract method" you'll get an error dialog indication "Selection ends 
inside a comment" 

foo();//a comment
Comment 1 Dirk Baeumer CLA 2004-12-22 06:28:47 EST
The problem is that the scanner contains the newline characters (/n/r ....) in
the length of the line comment.

Moving to JDT/Core to comment on the rational to contain newline characters in
line comments.
Comment 2 Frederic Fusier CLA 2004-12-22 08:56:02 EST
In fact, new line is not in comment... this is current way to check it which is
not correct.
Scanner current position (got with #getCurrentScannerEndPosition()) after having
parsed a line comment is set after new line characters. But, comment stored
position does not include them (ie. ends at first line character '\r').
So, the only issue here is that you're missing a way to get this correct line
comment end...

Note that this happens also in 2.1.3
Comment 3 Frederic Fusier CLA 2004-12-22 09:02:24 EST
Back to JDT/UI.
I will open a new bug against JDT/Core component and put this bug as dependent.
Then, you'll have a track to modify CommentAnanlyser as soon as new API will be
available...
Comment 4 Dirk Baeumer CLA 2004-12-22 09:52:59 EST
Thanks Frederic.
Comment 5 Frederic Fusier CLA 2007-06-21 07:54:31 EDT
I cannot reproduce using 3.3 RC4...
Do you know how this issue was fixed without the new API on IScanner (see bug 81784)?
Comment 6 Deepak Azad CLA 2011-12-01 01:27:29 EST
(In reply to comment #0)
> In 3.0M2
> If you select the following code (up to the very last character) and ask 
> for "extract method" you'll get an error dialog indication "Selection ends 
> inside a comment" 
> 
> foo();//a comment

'Refactor > Extract method' works with 3.8 M3. However, 'Extract to method' proposal is not offered with Ctrl+1.

Fix to go in QuickAssistProcessor.getExtractMethodProposal(...). The "if (coveringNode instanceof Block)" statement looks wrong, it might be better to just create the refactoring and let it handle all the cases.

I will investigate.
Comment 7 Deepak Azad CLA 2011-12-23 05:37:50 EST
(In reply to comment #6)
> Fix to go in QuickAssistProcessor.getExtractMethodProposal(...). The "if
> (coveringNode instanceof Block)" statement looks wrong, it might be better to
> just create the refactoring and let it handle all the cases.

The 'Extract to Method' quick assist was not offered most of the times when more than one statement was selected! Small bug in getIndex(..) method used by the if statement which I have fixed. The if statement by itself is a cheap test before we create the refactoring, hence I have left it as is. I have also added a few basic tests for the quick assist, there were none previously.

Fixed in master - 1271a2793e6915e1202f090c69cab99b5943a19d