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 186026 - Formatting collapses all my newlines
Summary: Formatting collapses all my newlines
Status: VERIFIED FIXED
Alias: None
Product: javafx
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: PC Mac OS X
: P2 normal (vote)
Assignee: Anton Chechel
URL:
Keywords:
Depends on:
Blocks: 173487
  Show dependency tree
 
Reported: 2010-05-12 15:37 UTC by Torbjorn Norbye
Modified: 2010-05-27 10:35 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 Torbjorn Norbye 2010-05-12 15:37:32 UTC
I tried formatting some of my source files, and all my "breather" lines (extra newlines inserted between variables, before return statements, and around blocks like if statements) were removed!

Here's an example -- take the following class:

class Foo {
    public var foo;

    public var bar;

    function bar(): Void {
        println("baz");

        if (false) {
            true
        }

        true
    }

}


If I reformat this, I end up with:

class Foo {
    public var foo;
    public var bar;

    function bar(): Void {
        println("baz");
        if (false) {
            true
        }
        true
    }

}

I realize that there may be options which says exactly how many newlines to separate members by, and that's why the properties were moved together; but certainly inside a method I don't think newlines should be removed (collapsed from >1 to 1 is fine, but going from 1 to 0 is not).

I think other formatters (maybe even the NetBeans Java one) generally takes the approach that it's okay to -add- newlines according to the options, and it's okay to reduce the number of newlines according to the options (so if you have 3 newlines between two functions, it gets changed to 2), but that you generally always leave at least one newline IF the user had added it.
Comment 1 Torbjorn Norbye 2010-05-12 15:55:30 UTC
By the way: I've formatted a number of complex files today and looked at the diffs, and this is the last blocker before I can start using the formatter. There are some other minor things here and there which I'll file but none of them are a big deal, e.g. they are infrequent scenarios where I can easily undo the change myself etc.
Comment 2 Petr Suchomel 2010-05-13 13:11:36 UTC
Tor,
This is exactly same behavior as for Java. I see this can be problem, but I am not sure it is P2 level issue. Please reevaluate.
Comment 3 Torbjorn Norbye 2010-05-13 16:00:08 UTC
> "This is exactly same behavior as for Java"

That's not true.

Here's the equivalent sample code in Java:

public class Foo {
   public int foo;

   public int bar;

   void bar() {
       System.out.println("baz");

       if (false) {
           return;
       }

       return;
   }

}

When I reformat this, with a brand new userdir (so no modified formatting settings), it makes only one formatting change: it inserts a new line right inside the class body.  It does NOT remove my extra newlines. If I remove the newlines myself, it does not insert them (e.g. this is not a case of my sample having corresponded exactly to where it wants newlines). It's definitely preserving extra newlines when reformatting, so it leaves the code nice and "airy". With the FX formatter all the code gets condensed.
Comment 4 Anton Chechel 2010-05-20 16:46:11 UTC
fixed
http://hg.netbeans.org/javafx/rev/2cc411b51dc3

Tor, we decided to provide desired by you behavior only for block expressions: function bodies, conditional expressions, loops, etc. - all except class members. This how it is done in Java. It is not difficult for me to do it for class members as well but it will differs from java formatter. Please test it. What do you think?
Comment 5 Anton Chechel 2010-05-20 16:53:16 UTC
*** Bug 186023 has been marked as a duplicate of this bug. ***
Comment 6 Torbjorn Norbye 2010-05-20 17:08:10 UTC
YAY!  I'll rebuild and test right away!
Comment 7 Torbjorn Norbye 2010-05-20 18:05:27 UTC
Thank you! It's much better!

It looks like it's collapsing not just class members but sequence members as well. Here's a code snippet:

def actions = [
            if (canCopy) {
                Action {
                    displayName: "Copy"
                    action: function() {
                        selection.copy();
                    }
                }
            } else {
                null
            },

            Action {
                displayName: "Delete"
                action: function() {
                    selection.<<delete>>();
                }
            }

            // etc
        ]

Here there are if blocks etc inside of a sequence. When formatted, these get collapsed. Was that intentional?
Comment 8 Anton Chechel 2010-05-20 19:10:30 UTC
No, it was not intentional.
I just commited fix: http://hg.netbeans.org/javafx/rev/9f90359f8d24
Rebuild it and please test again. :)

PS: I also don't like the fact it removes blank space right after imports. Tomorrow will take a look on it.
Comment 9 Torbjorn Norbye 2010-05-20 19:24:44 UTC
Yesssssss!!!! Works beautifully now!    I have added newlines in many places to "group" related sets of attributes, and it's removing those, but you are correct -- the Java formatter does that to my fields too.  I think I'll just have to learn to have them all right next to each other.  That's not a big deal. 

I'm really happy! Thank you! And thank you for getting this into 6.9, I was afraid it wasn't going to make it :)
Comment 10 Alexandr Scherbatiy 2010-05-21 13:17:51 UTC
verified in netbeans-trunk-nightly-201005210001-javafx-windows.exe
Comment 11 Lukas Hasik 2010-05-24 12:15:39 UTC
Integrated into release69 http://hg.netbeans.org/javafx/changeset/d5e2235b4f4f - Anton
Comment 12 Alexandr Scherbatiy 2010-05-27 10:35:04 UTC
Verified in NB 6.9 RC1