Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Eclipse from splitting annotations into new lines

Tags:

java

eclipse

@Setter
@Getter
private String query;

I get something like this after formatting, how to prevent it and keep my annotations in one line? I didn't find any usable setting inside Formater configuration.

@Setter @Getter @sthElse @oneMore @etc
private String query;

This is how I would like it to be

like image 481
dantuch Avatar asked Mar 26 '12 16:03

dantuch


3 Answers

IMHO the closest you can get is:

@Setter @Getter @sthElse @oneMore @etc private String query;

(via Formatter->New Lines->Insert new lines after annotations on Method

like image 151
maximdim Avatar answered Oct 23 '22 21:10

maximdim


One hack that allows you to force a newline whenever you want is to add a in-line comment (//) to the end of the line. For example, when I have annotations on parameters, I want them to line up like this:

public ModelView finish(//
        @PathParam("stampId")//
        long stampId, //

Instead of like this:

public ModelView finish(@PathParam("stampId") long stampId,

My use of // gives me more fine grained control over this. So if you change the "insert new lines after annotations" setting you should be able to get:

@Setter @Getter @sthElse @oneMore @etc //
private String query;

I'm sure if I took a look at the Eclipse formatting code I could add it there but I don't have the time for that. :-)

like image 21
Gray Avatar answered Oct 23 '22 19:10

Gray


When you're editing your formatting profile, select the 'New Lines' tab. There's a grouping labelled 'Annotations' on that preference page. You should be able to deselect the preferences to "Insert new line after annotations on members/parameters/local variables"

like image 2
Mike Bockus Avatar answered Oct 23 '22 19:10

Mike Bockus