This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Product Version = NetBeans IDE 7.2 (Build 201207171143) Operating System = Linux version 3.2.0-29-generic running on amd64 Java; VM; Vendor = 1.6.0_32 Runtime = Java HotSpot(TM) 64-Bit Server VM 20.7-b02 When extracting a new location variable from existing code, the placement of the new line of code with the new variable is not very smart. For example, extracting a variable from a line of code which is immediately preceeded by a comment line. The new line of code is placed above the comment, after the previous real code statement. It would be more logical to place the new line of code immediately before the line being refactored. Screen shot examples coming shortly.
Created attachment 123548 [details] Example - before refactoring
Created attachment 123549 [details] Example - after refactoring
(In reply to comment #2) > Created attachment 123549 [details] > Example - after refactoring To me this looks correct, but maybe I'm missing something because of the small code snippet. Let's look at the following code sample: public static void main(String[] args) { double pi = 3.14159; // Variable pi will never be 0, so no need to check for DivideByZeroException double diameter = 123456 / pi; } Using Introduce Variable on 123456 should be placed above the comment, as the comment is saying something (or should) about the whole statement. Right?
In your example, I would want the new variable to go below the comment, immediately above the statement it is refactored from.
What about adding an option for this type of refactoring that allows the user to choose whether the new code goes before the comments or after? In my case the new code should go after the comment 90% of the time, because my comments tend to apply to blocks of code, not individual lines.
I don't think it's a typical case that the above-comment applies just to a part of expression (= the extracted part should land after the comment). In your case, it would be probably more effective to move around the lines after the refactoring is applied than interacting with a dialog (or something similar) popping up. A pre-set option will not solve the problem as each of the extraction may need a different treatment.
I'm not sure you've understood what I meant. I typically use comments to refer to a block (several lines) of code, not just part of an expression. In that case, it makes sense (to me) for the refactored code to be placed after the comment block. I can see why you don't think my usage is "typical", but it is certainly typical for me. I doubt that I am the only person who codes or thinks that way. I wasn't thinking of an option on a per-use basis, but a global option that would apply to all such refactorings. That way each user could set the option the way that applies to them most of the time and move the lines around as you suggested when there is an exception.