javaeclipseformattermethod-declaration

Eclipse Formatter: How to avoid indentation of method declaration after annotation?


I have a method declaration with an annotation that is formatted by Eclipse Mars as follows:

@Override
        void addLoadShiftingConstraints() throws NoSuchDataException {
    //method body
}

I would like to not indent the method declaration:

@Override
void addLoadShiftingConstraints() throws NoSuchDataException {
    //method body
}

Currently I have following formatter setting for the method declaration:

enter image description here Right click on Project =>Properties=>Java Code Style=>Formatter =>Edit active profile => LineWrapping => Method Declaration => Declaration => Wrap where necessary

If I would choose the option Do not wrap instead, the unwanted indent would vanish. However, I would like to keep the wrapping for long declarations.

Is this an Eclipse bug or is there an additional setting for the Annotations that I would have to change in order to avoid the indent?


Solution

  • This is indeed a bug (related). The workaround is to set the setting to "Do not wrap" as you describe or to add an access modifier like private.