Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 470506

Summary: formatter option "align field in columns" changed in Mars
Product: [Eclipse Project] JDT Reporter: zzzz <nzanaga>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ezanaga, jarthana, luke_bastendorff, manoj.palat, markus.kell.r, mateusz.matela, mohanaraosv, titou10.titou10, tobibobi, ymene7
Version: 4.5Flags: manoj.palat: review+
Target Milestone: 4.5.1   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/53108
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=9db26c7bea8b081f74e04400ef73e415034114ae
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R4_5_maintenance&id=17a84d4eab07595592188d8d0f5bdd5566f79b61
https://bugs.eclipse.org/bugs/show_bug.cgi?id=479109
Whiteboard:

Description zzzz CLA 2015-06-18 11:44:12 EDT
working with Mars 4.5 RC3, formatting this class, the result is:

public class TestZ {
    public int a = 10;

    public int testAlignment = 10;
}


formatting this class, for example, with Eclipse 3.7.2, the result is:

public class TestZ {
    public int a             = 10;

    public int testAlignment = 10;
}

with Mars 4.5 RC3, the variables will be aligned only without spaces :

public class TestZ {
    public int a             = 10;
    public int testAlignment = 10;
}
Comment 1 zzzz CLA 2015-06-18 11:51:54 EDT
note: previous version of Eclipse Mars 4.5 , for example M1, works as Eclipse 3.7.2
Comment 2 Mateusz Matela CLA 2015-06-28 17:23:12 EDT
This was done on purpose to make aligning more flexible. You can now have several separated groups of fields and align them independently.

If you want fields separated by an empty line to be considered the same group, you can increase setting for Blank lines -> Before field declarations to 1.
Comment 3 zzzz CLA 2015-06-30 11:57:37 EDT
I don't think the "Blank lines -> Before field declarations to " is the correct option.  For example if you set to 5, you get:

before:

public class TestZ {
    public int a = 10;

    public int testAlignment = 10;
}

after:

public class TestZ {
    public int a             = 10;





    public int testAlignment = 10;
}

I don't find any option about how many blank lines to use for considering field declarations in same group
Comment 4 Mateusz Matela CLA 2015-07-01 17:28:41 EDT
This is what you wanted, right? You increased the "Before field declarations" and now all the fields are aligned as one group.

There's no separate option for this. Field aligner will consider two neighboring fields to be in separate groups if the number of empty lines between them is greater than the "Before field declarations" setting. This is only possible if the "Number of empty lines to preserve" is greater too.
Comment 5 Tobias Nielsen CLA 2015-07-02 03:50:21 EDT
It should also be noted that this doesnt work well together with comments as you would typically seperate commented lines with new lines (see a typical example below). I think it would be better to allow the old behavior (by configuration) so people relying on this behaviour in their code standards can still use this.

// intended look
public final class SW_ETools_Event_Types
{
    /** Transmitted in the case that a timer tick is being fired. */
    public static final String EVENT_TIME                = "time";

    /** Transmitted in the case that the state machine change. */
    public static final String EVENT_STATEMACHINE_CHANGE = "state";

    /** Transmitted in the case that the state machine change. */
    public static final String EVENT_STATEWISH_CHANGE    = "wish";

    /** Transmitted in the case that the display state change. */
    public static final String EVENT_TOOLDISP_CHANGE     = "dispst";

    /** Transmitted in the case that the group/safety state change. */
    public static final String EVENT_TOOLGRP_CHANGE      = "grsfst";

    /** Transmitted in the case that the detector state change. */
    public static final String EVENT_TOOLDET_CHANGE      = "detst";

    /** Transmitted in the case that the I/O state change. */
    public static final String EVENT_TOOLIO_CHANGE       = "iost";

    /** Transmitted in the case that the ITC state change. */
    public static final String EVENT_TOOLITC_CHANGE      = "itcst";
}

----------------------

// formatted look on mars - looks ugly and is not clearly readable.
public final class SW_ETools_Event_Types
{
    /** Transmitted in the case that a timer tick is being fired. */
    public static final String EVENT_TIME = "time";

    /** Transmitted in the case that the state machine change. */
    public static final String EVENT_STATEMACHINE_CHANGE = "state";

    /** Transmitted in the case that the state machine change. */
    public static final String EVENT_STATEWISH_CHANGE = "wish";

    /** Transmitted in the case that the display state change. */
    public static final String EVENT_TOOLDISP_CHANGE = "dispst";

    /** Transmitted in the case that the group/safety state change. */
    public static final String EVENT_TOOLGRP_CHANGE = "grsfst";

    /** Transmitted in the case that the detector state change. */
    public static final String EVENT_TOOLDET_CHANGE = "detst";

    /** Transmitted in the case that the I/O state change. */
    public static final String EVENT_TOOLIO_CHANGE = "iost";

    /** Transmitted in the case that the ITC state change. */
    public static final String EVENT_TOOLITC_CHANGE = "itcst";
}
Comment 6 zzzz CLA 2015-07-02 04:17:02 EDT
I try to explain with a better example.
Using "Before Field Declaration" = 0 and "Number of empty line to preserve" = 1

if you try to format this:

public class TestZ {
    public int a = 10;
    public int testAlignment = 10;

    public int z  = 10;
    public int testAlignmentAdder = 10;
}

with Eclipse pre 4.5RC you get this:

public class TestZ {
    public int a                  = 10;
    public int testAlignment      = 10;

    public int z                  = 10;
    public int testAlignmentAdder = 10;
}

I don't find any option to get the same thing with Eclipse 4.5RC3 because:
Using "Before Field Declaration" = 0 and "Number of empty line to preserve" = 1:

public class TestZ {
    public int a             = 10;
    public int testAlignment = 10;

    public int z                  = 10;
    public int testAlignmentAdder = 10;
}

Using "Before Field Declaration" = 1 and "Number of empty line to preserve" >=1:

public class TestZ {
    public int a                  = 10;

    public int testAlignment      = 10;

    public int z                  = 10;

    public int testAlignmentAdder = 10;
}

I mean, there is not way to keep all fields aligned and preserve blank lines as wanted.
Comment 7 Mateusz Matela CLA 2015-07-08 14:25:19 EDT
Well, I was so happy with this behavior that I failed to consider that it may get in someone's way :(

Markus, would you agree to add a setting for this feature? The "Align fields in column" option looks quite lonely in its group and there's room for a new setting like "Group fields by additional empty lines".

Otherwise I guess I'll just restore the old behavior.
Comment 8 Denis Forveille CLA 2015-07-14 08:41:54 EDT
(In reply to Mateusz Matela from comment #2)
> This was done on purpose to make aligning more flexible. You can now have
> several separated groups of fields and align them independently.
> 
> If you want fields separated by an empty line to be considered the same
> group, you can increase setting for Blank lines -> Before field declarations
> to 1.

IMHO this is clearly a regression from previous versions

This "feature" is very annoying as every developer automatically performs a source "format" on save and all the variable declarations now appears as "changed" when we compare the source with previous version from SVN repo

The priority of this bug should be raised as this is really really annoying for dayt-to-day development and there is no workaround

This "feature" should have been implemented with a new formatting option, with the default setting keeping the result formatted source code as in previous versions
Comment 9 Eclipse Genie CLA 2015-08-03 19:02:05 EDT
New Gerrit change created: https://git.eclipse.org/r/53108
Comment 10 Mateusz Matela CLA 2015-08-03 19:19:16 EDT
For now I removed the "feature". I tried to create a setting for it, but that would require changes in API, which would not be good to backport to 4.5.1.
Comment 11 Mohana Rao S V CLA 2015-08-04 11:49:22 EDT
Even i'm facing the issue, could you please share when the fix will be available.
Comment 12 Jay Arthanareeswaran CLA 2015-08-05 01:09:35 EDT
(In reply to Mohana Rao S V from comment #11)
> Even i'm facing the issue, could you please share when the fix will be
> available.

As of now, the bug is tagged for 4.6 M2, which means this will be available by end of September. Also note that this will not be back ported to 4.5.1.
Comment 13 Mateusz Matela CLA 2015-08-05 03:12:30 EDT
(In reply to Jay Arthanareeswaran from comment #12)
> Also note that this will not be back ported to 4.5.1.

May I ask why? This is a regression from the users' point of view. If we don't consider it a regression, we might as well leave it in (or add a configuration). Otherwise some users will get used to the new behavior and will be annoyed again when we switch back in 4.6.
Comment 14 Jay Arthanareeswaran CLA 2015-08-05 05:17:42 EDT
(In reply to Mateusz Matela from comment #13)
> May I ask why? This is a regression from the users' point of view. If we
> don't consider it a regression, we might as well leave it in (or add a
> configuration). Otherwise some users will get used to the new behavior and
> will be annoyed again when we switch back in 4.6.

Okay, makes sense. First we need to push it to master as we don't have much time left for 4.5.1.
Comment 15 Denis Forveille CLA 2015-08-05 07:38:37 EDT
+1

(In reply to Jay Arthanareeswaran from comment #14)
> (In reply to Mateusz Matela from comment #13)
> > May I ask why? This is a regression from the users' point of view. If we
> > don't consider it a regression, we might as well leave it in (or add a
> > configuration). Otherwise some users will get used to the new behavior and
> > will be annoyed again when we switch back in 4.6.
> 
> Okay, makes sense. First we need to push it to master as we don't have much
> time left for 4.5.1.
Comment 16 Markus Keller CLA 2015-08-05 08:13:38 EDT
+1 for restoring the 4.4 behavior in 4.6 M2 and 4.5.1.

For import groups, we have a separate setting blank_lines_between_import_groups. If there's a demand for field groups, then we'd need an enhancement request and a separate setting for that. To enable field grouping, the user would then have to set the new option to a number greater than blank_lines_before_field.
Comment 18 Jay Arthanareeswaran CLA 2015-08-13 06:46:23 EDT
+1 for 4.5.1
Comment 19 Luke Bastendorff CLA 2015-08-14 09:31:51 EDT
Also +1 for 4.5.1
Comment 21 Jay Arthanareeswaran CLA 2015-08-21 07:45:13 EDT
Verified for 4.6 M2 with build I20150818-0800

and 

Verified for 4.5.1 with build M20150819-1000
Comment 22 Marcus Storre CLA 2015-10-06 09:41:59 EDT
I would really appreciate, if in future there is a possibility to change between these two modes. I really loved the changes implemented from Mateusz Matela.

Just updated to the latest eclipse version and already missing this feature (aka "bug" :).
Comment 23 Mateusz Matela CLA 2015-10-07 16:15:07 EDT
(In reply to Marcus Storre from comment #22)
> I would really appreciate, if in future there is a possibility to change
> between these two modes.

See bug 479109 for this.