2

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?

Stefan
  • 10,010
  • 7
  • 61
  • 117

2 Answers2

2

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.

aha
  • 3,702
  • 3
  • 38
  • 47
1

(Can't comment due to insufficient reputation, but found this answer through search and it applies to a second situation.)

I faced a similar problem with indentation of local variables, which only took affect when a comment was placed after an annotation. @Stefan's answer worked for this also.

 @SuppressWarnings("JavaReflectionMemberAccess") // implicit method Enum#valueOf(String)
 Method method = class_.getMethod("valueOf", String.class);

was being reformatted to

@SuppressWarnings("JavaReflectionMemberAccess") // implicit method Enum#valueOf(String)
        Method method = class_.getMethod("valueOf", String.class);

but was fixed with the addition of a final modifier:

@SuppressWarnings("JavaReflectionMemberAccess") // implicit method Enum#valueOf(String)
final Method method = class_.getMethod("valueOf", String.class);