javaeclipsecode-formattingeclipse-formatter

Eclipse formatter align fields in columns


I'm trying to use the Eclipse formatter (but not Eclipse), and I'm trying to use "align fields in columns". This has side effects I don't like:

class Thing {
    int    x       = 0;                       // comment is pushed aside
    double trouble = Double.POSITIVE_INFINITY;
}

If trouble had been an anonymous class or a 2d array, it would have been even worse. Can the comment being pushed aside be stopped somehow?


Solution

  • You have a valid point, and I couldn't find a way to prevent Eclipse aligning the comments when using "Align fields in columns".

    Even if you set "Preserve white space between code and line comments" on the Comments tab the line comments still get aligned.

    I raised a bug with Eclipse for this:

    Bug 532970 - Eclipse formatter formatting single line comment incorrectly

    Hopefully they will see it as a bug rather than a feature.