Annotations on the same line

Is it possible to change the formatting options putting the annotations on the same line of the field?

As an example, here's how IDEA format my code each time I press enter:

@MyAnnotation
MyClass MyField;

I would like to have

@MyAnnotation MyClass MyField;

This is especially useful in Seam and it will be almost mandatory in Java EE 6.

Thank you very much.

2
7 comments

Hi Luca,

You can set the following option 'Project Settings -> Code Style -> Wrapping -> Field annotations' to 'Do not wrap'.

That instructs IDEA to avoid inserting line break between field annotation and definition.

Regards, Denis

3

volothamp wrote:

Thanks a lot :)

Welcome

One note - it may be even more convenient for you to use 'Wrap if long' instead of 'Do not wrap'.

0

Just one more thing. It appears that using code completition still wraps the text.

Would you please check this?

Thank you again.

0

Please provide exact steps to reproduce problem scenario.

I just tried the following and no wrap is performed:

  1. Type '@MyAnnotation' inside class body;
  2. Type white space;
  3. Type 'pr';
  4. Press 'Ctrl + Space' and select 'private';
  5. Type white space;
  6. Type 'O';
  7. Press 'Ctrl + Space' and select 'Object;
  8. Type white space;
  9. Press 'Ctrl + Space' and select any suggested name ('object' in my case);
  10. Type semicolon;

We have complete field declaration now that is located on a single line. Checked with IDEA 9.0.2.

0

I managed to reproduce, it's not with code completition, but with import suggest:

1. Write

@MyAnnotation List myList;

- Import suggest for "java.util.list"?

2. Press ALT+ENTER

- Voilà: two lines.

IDEA 9.0.2 for me too.

Thanks for your understanding

0

Hi Luca,

No wrap is performed for me in that case (still IDEA 9.0.2)

0

Please sign in to leave a comment.