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.

Bug 239334 - "Introduce Constant" refactoring places new constant incorrectly
Summary: "Introduce Constant" refactoring places new constant incorrectly
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Linux
: P3 normal with 2 votes (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-10 18:52 UTC by mclaborn
Modified: 2014-03-25 17:24 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mclaborn 2013-12-10 18:52:16 UTC
Product Version = NetBeans IDE 7.4 (Build 201310111528)
Operating System = Linux version 3.2.0-57-generic running on amd64
Java; VM; Vendor = 1.7.0_45
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.45-b08

"Introduce Constant" places the new constant immediately following the method from which it was extracted. 7.3 placed it at the top of the class.  If it is supposed to follow the ordereing set in Tools -> Options -> Editor -> Formatting -> Java -> Ordering  that is not working, as "Static Fields" is the first thing in that list for me.

Example - Before Refactoring
  private void createModelServers() {
    modelServers = new JSONListTableModel();
    
    modelServers.addColumn("hostname", "Server", 0.10, String.class);
    modelServers.addColumn("rolename", "Role", 0.10, String.class);
    
    tableServers.setColumnsVersion(3);
    tableServers.setModel(modelServers);
  }

After Refactoring
  private void createModelServers() {
    modelServers = new JSONListTableModel();
    
    modelServers.addColumn("hostname", "Server", 0.10, String.class);
    modelServers.addColumn(COL_ROLENAME, "Role", 0.10, String.class);
    
    tableServers.setColumnsVersion(3);
    tableServers.setModel(modelServers);
  }
  private static final String COL_ROLENAME = "rolename";
Comment 1 mclaborn 2013-12-10 19:35:05 UTC
Also appears to be broken for "Introduce field"
Comment 2 mclaborn 2013-12-10 21:00:56 UTC
The "Insertion Point" setting at Tools -> Options -> Editor -> Formatting -> Java -> Ordering also appears to have no effect on the placement of the new constant.
Comment 3 Svata Dedic 2014-01-30 11:56:17 UTC
Please configure the 'Insertion point' in Tools | Options - Formatting/Java category "Ordering". It is set to 'insertion point' by default, which causes the introduced field/constant to be generated after the selected range (after the enclosing method). Set it to first/last in category to make the code generator to obey code ordering rules.
Comment 4 mclaborn 2014-01-30 16:46:23 UTC
As noted above, the setting of "Insertion Point" appears to be ignored in both 7.4 and 8.0 Beta.

In 8.0 Beta, when I change the Insertion Point to "First in Category" then click "Apply", it changes back to "Last in Category". Same when using the "OK" button.  "Caret Location" seems to stick as it should, but this is not the seting I want.

Same behvaior observed in 7.4.
Comment 5 mclaborn 2014-03-25 17:24:36 UTC
This appears to be fixed in 8.0.  The options dialog is holding the "Caret location" value and the refactoring honors that setting.