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 240785 - "Introduce Constant" refactor does not respect formatting
Summary: "Introduce Constant" refactor does not respect formatting
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3.1
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-21 16:32 UTC by ivan.vergiliev
Modified: 2016-07-07 07:17 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
For the records - partial fix; needs to be improved (9.12 KB, patch)
2014-02-11 10:30 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ivan.vergiliev 2014-01-21 16:32:28 UTC
Product Version = NetBeans IDE 7.3.1 (Build 201306052037)
Operating System = Mac OS X version 10.9.1 running on x86_64
Java; VM; Vendor = 1.7.0_45
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.45-b08

When I introduce a constant, the result looks like this:

class TestClass {
  // NOTE: no empty line here
  public static final int CONSTANT_NAME = 0;
  ...

However, when I do Source -> Format, the result looks like this:

class TestClass {

  // empty line before
  public static final int CONSTANT_NAME = 0;
  ...
Comment 1 Svata Dedic 2014-02-07 16:53:12 UTC
Please see Tools - Options / Editor / Formatting / Java - Blank lines.

By default 'After class header' blank line is set to 1 - causes one empty line to be inserted between the 1st member and the class header. The // comment is considered to belong to the CONSTANT_NAME member, so it is moved as well.
Comment 2 ivan.vergiliev 2014-02-08 09:28:50 UTC
I'm sorry that was unclear - the // comments are not part of the code I'm testing with - I added them to emphasize the behaviour.

The real examples are:

class TestClass {
  public static final int CONSTANT_NAME = 0;

after the refactor, and then:

class TestClass {

  public static final int CONSTANT_NAME = 0;

after formatting.

So the problem is exactly that the 1 line is not inserted between the class header and the 1st member when I do the refactor. It only appears after explicitly formatting the code.
Comment 3 Svata Dedic 2014-02-08 10:00:16 UTC
OK, misunderstood - thanks for clarification.
Comment 4 Svata Dedic 2014-02-11 10:27:13 UTC
I need to postpone this defect because of time/defect # with bigger impact, sorry. 
So far I've found out that the diff/printer that prints in the new member does not insert blank lines after class header according to the coding style - this was easy to fix. But when a member is inserted before/after another member, the content in between is copied without counting / detecting potential blank lines - it is a considerably harder to fix especially when counting trailing blank lines + blanks preceding the next (untouched) member.

The goal should be that Max(a,b) blank lines should be between two members/places that have blank lines number.

Attaching diff developed so far.
Comment 5 Svata Dedic 2014-02-11 10:30:18 UTC
Created attachment 145024 [details]
For the records - partial fix; needs to be improved
Comment 6 Martin Balin 2016-07-07 07:17:07 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss