Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 116078 - Reformat blank lines rules are not working 100%
Reformat blank lines rules are not working 100%
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Editor
6.x
All All
: P3 with 2 votes (vote)
: 7.4
Assigned To: Dusan Balek
issues@java
formatting
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-09-20 02:27 UTC by mcumings
Modified: 2013-04-08 17:01 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mcumings 2007-09-20 02:27:19 UTC
It appears that some of the situations which are supposed to be handled with the
Java code formatting in the "Blank Lines" category are not working.  After
setting every "Blank Lines" option to '1', reformatting the class:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
package foo;
public class FormatTarget {
    public void method1() {
    }
    
    // Foo
    
    public void method2() {
    }
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

results in:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
package foo;

public class FormatTarget {

    public void method1() {
    }
    // Foo

    public void method2() {
    }
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note the following:
1) There is no blank line above "package"
2) There is no blank line after the end of the class
3) There is no blank line after method1()

There are a few other cases like #3 involving comments not
resulting in the application of blank lines but since I have
a feeling that this is may be intentionally systemic (i.e.,
Javadoc if considered a comment may be separated from the method
it documents by a blank line.)
Comment 1 janicki 2007-11-06 17:52:47 UTC
[Using 6.0 beta 2 on Mac]
Additionally, when I set "Before Method = 2, and After Method =0" (or any combination like that really), then any methods with Javadoc will have that 
javadoc block floating between two methods, for example:

/**
 * Some javadoc...
 */

public void myMethod()
{
}

/**
 * Some javadoc...
 */

public void myMethod2()
{
}


What I expect is to see the javadoc right above the method it describes, with no space.  And my preference for 2 spaces after methods should still be used.  
For example:

/**
 * Some javadoc...
 */
public void myMethod2()
{
}


/**
 * Some javadoc...
 */
public void myMethod2()
{
}


If the current implementation is actually the intention, then I would appreciate a new option to control the spacing around javadoc.
Comment 2 janicki 2007-11-06 17:56:28 UTC
Another thing... there seems to be no way to ensure blank lines before the last brace.  Maybe this can be fixed somewhat when "After Method" gets fixed.  But 
ideally, I'd like to set extra lines before the last brace that ends the class.  (It's a visual space to start adding new methods.)

Comment 3 loukur 2007-11-10 21:29:05 UTC
I am having the same problem. I tried to change:
"Blank Lines", "Before Method" to 0 and 
"Blank Lines", "After Method" to 1 and the below code does not change after [Shift]+[Alt]+[F]:
    /**
     * Sets the value of <code>sSecno</code>.
     * @param sSecno A String containing the value for <code>sSecno</code>.
     */

    public void set_sSecno(String sSecno) {
        this.sSecno = sSecno;
    }
    /**
     * Sets the value of <code>sPassword</code>.
     * @param sPassword A String containing the value for <code>sPassword</code>.
     */

    public void set_sPassword(String sPassword) {
        this.sPassword = sPassword;
    }
    /**
     * Sets the value of <code>sOptionalID</code>.
     * @param sOptionalID A String containing the value for <code>sOptionalID</code>.
     */

My expectation is the code would now look like this:
    /**
     * Sets the value of <code>sSecno</code>.
     * @param sSecno A String containing the value for <code>sSecno</code>.
     */
    public void set_sSecno(String sSecno) {
        this.sSecno = sSecno;
    }

    /**
     * Sets the value of <code>sPassword</code>.
     * @param sPassword A String containing the value for <code>sPassword</code>.
     */
    public void set_sPassword(String sPassword) {
        this.sPassword = sPassword;
    }

    /**
     * Sets the value of <code>sOptionalID</code>.
     * @param sOptionalID A String containing the value for <code>sOptionalID</code>.
     */
Comment 4 sean 2007-11-12 06:48:03 UTC
Similar issues.  NB 6.0 beta 2 on an Intel Mac.  Below is code quickly typed into the editor:
vvvvvvvvvvv
/**
 *
 * @author sean
 */
public class TestClass {
    /**
     * foo comment
     */
public int foo;
/**
 * bar comment
 */
public int bar;
/**
 * foobar comment
 */
public String foobar;
/**
 * barfoo comment
 */
 public int barfoo;
 /**
  * barfood comment
  */
 public int barfood;
}
^^^^^^^^^^
After doing a Format, this is the result:
vvvvvvvvvvvv
/**
 *
 * @author sean
 */
public class TestClass {
    /**
     * foo comment
     */

    public int foo;
    /**
 * bar comment
 */
    public int bar;
    /**
 * foobar comment
 */
    public String foobar;
    /**
 * barfoo comment
 */
    public int barfoo;
    /**
  * barfood comment
  */
    public int barfood;
}
^^^^^^^^^^^
What went right:
- Code was properly indented after reformatting
- First line of javadoc comment was properly indented afetr formatting
What went wrong:
- Space appeared between javadoc comment and field it referred to
- Subsequent lines of javadoc were not realigned with first line

Settings in Options/Java Code/Formatting/Blank Lines:
Before Package: 0
After Package: 1
Before Imports: 1
After Imports: 1
Before Class: 1
After Class: 0
After Class Header: 1
Before Field: 0
After Field: 0
Before Method: 1
After Method: 0

After changing "After Class Header" to 0, the blank line after the comment and immediately preceding the first field went away.  In other words, the Format 
process seems to be treating the comment after the class header as part of the class header rather than as part of the field, and places the space between 
the comment and the field rather than the comment and the class header.
Comment 5 Jiri Prox 2008-04-11 00:51:28 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 6 kilibob 2008-05-22 21:08:51 UTC
Under 6.1 RC2, with only "1 blank line before methods" set, I consistently get two if the method end brace has a 
comment on the line.

Example:

^^^^^^^^^^^^^^^^^^^^^^^^^^
public void foo(boolean val) {
  doStuff();
} //+foo(boolean):void

public void bar() {
  doMoreStuff();
} //+bar():void
^^^^^^^^^^^^^^^^^^^^^^^^^^

Becomes, after formatting:

^^^^^^^^^^^^^^^^^^^^^^^^^^
public void foo(boolean val) {
  doStuff();
} //+foo(boolean):void


public void bar() {
  doMoreStuff();
}
^^^^^^^^^^^^^^^^^^^^^^^^^^

But if I remove the //+foo(boolean):void comment from the end brace of the first method, it properly inserts only the 
requested single blank line.  Is this intentional, and if so, could we get a bit o'doc indicating so (and maybe even 
why), so users won't get freaked out trying to figure out why "1 blank line" really equates to "2 blank lines, 
sometimes"?
Comment 7 Jiri Prox 2008-05-23 08:55:38 UTC
kilibob your problem will be fixed in patch 1
Comment 8 Jan Becicka 2008-08-05 15:38:34 UTC
*** Issue 106815 has been marked as a duplicate of this issue. ***
Comment 9 mclaassen 2011-05-27 18:17:26 UTC
For a long time now I have been putting // alone on lines I want to be blank so they don't disappear when reformatting.  This is not a good solution.  Please address this issue.
Comment 10 MackSix 2013-03-25 14:40:17 UTC
Some of these issues are fixed, but some still exist in 7.3. If we start with no blank lines in the following and then format, this is the result: 

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

package newpackage;

public class NewClass1 {

    public void doStuff() {
    }
    // Foo

    public void doMoreStuff() {
    }

    public void foo(boolean val) {
        doStuff();
    } //+foo(boolean):void

    public void bar() {
        doMoreStuff();
    } //+bar():void
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There is now a blank line above package, but the other deficiencies are still valid.

I would add that it does not insert a blank line after the class although it is set to insert a blank line. If I set it to zero and there is blank lines after the class, it does not remove them. The preview of this is broken too, it shows blank line added before the closing class brass when the after class setting is set to 1 or more.

I have not checked for other deficiencies.

Product Version: NetBeans IDE 7.3 (Build 201302132200)
Java: 1.7.0_17; Java HotSpot(TM) 64-Bit Server VM 23.7-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_17-b02
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 11 MackSix 2013-03-25 15:10:20 UTC
Ignore the comments in Comment 10 about the preview not working correctly as it works correctly since the last member is an interface. It just does not add or remove blank lines after the outer class.

Also the result in Commment 10 is with all blank line settings set to 1.

I don't see anything wrong with the results except for if their is a 1 line comment next to the closing brace on the last comment, no blank line is inserted after the method like it should. Remove the comment and it works.
Comment 12 MackSix 2013-03-25 15:18:25 UTC
Results for Comment 4 is this on NetBeans 7.3 on Windows 7 works right now.

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
package newpackage;

import java.util.Arrays;
import java.util.ArrayList;

/**
 *
 * @author sean
 */
public class NewClass1 {

    /**
     * foo comment
     */
    public int foo;
    /**
     * bar comment
     */
    public int bar;
    /**
     * foobar comment
     */
    public String foobar;
    /**
     * barfoo comment
     */
    public int barfoo;
    /**
     * barfood comment
     */
    public int barfood;

}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Comment 13 MackSix 2013-03-25 15:35:09 UTC
Problem in Comment 3 is working in NetBeans 7.3 on Windows 7. There is a new problem though, the next to the last line in the Java Doc is moved up to the previous line. See below.

    /**
     * Sets the value of
     * <code>sSecno</code>.
     *
     * @param sSecno A String containing the value for <code>sSecno</code>.
     */
    public void set_sSecno(String sSecno) {
        this.sSecno = sSecno;
    }
    /**
     * Sets the value of
     * <code>sPassword</code>.
     *
     * @param sPassword A String containing the value * *      * for <code>sPassword</code>.
     */
    public void set_sPassword(String sPassword) {
        this.sPassword = sPassword;
    }

    /**
     * Sets the value of
     * <code>sOptionalID</code>.
     *
     * @param sOptionalID A String containing the value * *      * for <code>sOptionalID</code>.
     */
Comment 14 MackSix 2013-03-25 15:43:54 UTC
In summary, I would say there are only 2 legitimate bugs left in all of these comments.

1. No blank line after a method if there is a one line comment on the same line as the closing brace - from Comment 6.

2. Second to the last line in the JavaDoc is being moved and appended to the next line up in the JavaDoc - from Comment 13. I am opening a separate issue up  for this.
Comment 15 MackSix 2013-03-26 04:21:17 UTC
I created 2 new issues for the valid remaining issues in this report. One issue was already reported.

issue 225221

issue 227928

issue 227929

Feel free to file any other issues separately. If someone thinks this should be closed, please close it.
Comment 16 Dusan Balek 2013-04-08 17:01:59 UTC
Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/3ba8f7ba2409


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo