Matt G
Matt G

Reputation: 1681

Eclipse formatter: New line after annotations/public?

IntelliJ has some such facilities and options. For example, I want it to format like:

@Override public
void foo()
{  ...  }

Better yet would be the ability to indent the annotations and visibility like so

    @Override public
void foo()
{ ... }

but I don't want to be greedy.

Do such formatting options exist in Eclipse?

Upvotes: 5

Views: 5682

Answers (4)

Amar Magar
Amar Magar

Reputation: 881

Go to settings-> Editor-> Code Style -> Java

Choose your code formatter and choose tab Wrapping and Braces (Try to find tab Wrapping if using different Intellij Version).

Look for option Class Annotation and Method Annotation and select option "Wrap Always"

enter image description here

Upvotes: 2

alfonx
alfonx

Reputation: 7216

In case you still have Annotation formatting problems in Eclipse 2018 (Oxygen.3a, 4.7.3a) try this:

In Preferences go to: Java -> Code Style -> Formatter -> Edit --> New Lines --> Annotations:

eclipse oxygen Annotation formatting

You have to select Annotations and then set "line wrapping policy" to a "Wrap ..." setting. Without this setting any complex set of Annotations was formatted to very long lines in Eclipse

Upvotes: 3

Michael Wiles
Michael Wiles

Reputation: 21186

Java -> Code Style -> Formatter -> Edit --> New Lines --> Annotation:

Unclick Insert new line after annotations on methods

Don't think you can do your second option.

Upvotes: 4

Tonny Madsen
Tonny Madsen

Reputation: 12718

Open the preferences dialog. Go to "Java" -> "Code Style" -> "Formatter".

Check the many options :-)

Upvotes: -3

Related Questions