Intellij code formatting, Java annotations on new lines

JavaFormattingIntellij Idea

Java Problem Overview


I'm using IntelliJ 12 and It's putting my member variable annotations on the same line, which i hate! How do I setup the code formatter to keep annotations on separate lines?

thanks!

Java Solutions


Solution 1 - Java

Navigate to Preferences → Editor → Code Style → Java → Wrapping and Braces tab, then locate the section Field annotations and check the option Do not wrap after single annotation.

In IntelliJ v14:

eIntelliJ v14 Java style preferences

Solution 2 - Java

In IntelliJ 12 You can find it in setup here (bottom right):

enter image description here

Solution 3 - Java

I think all the above answers are correct but here is step by step for Mac users:

  1. Click on "IntelliJ IDEA"
  2. Click on "Preferences"
  3. Go "Code Style" on the left navigation window and you will see "Java" listed below it and Click on it !
  4. Look for the header tab "Wrapping and Braces" on the right side of Preferences window.
  5. At this point you want to look for the item called "Do not wrap after single annotation" under "Field annotations". click "ok" and you are done !

enter image description here

Solution 4 - Java

Nothing seemed to work for me with version 2.3.3 or Android Studio. I gave up and checked Line breaks under Keep when reformatting. I just have to be very careful when I add line breaks.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncatraptureView Question on Stackoverflow
Solution 1 - JavaDaniel WilliamsView Answer on Stackoverflow
Solution 2 - JavaGusView Answer on Stackoverflow
Solution 3 - JavagrepitView Answer on Stackoverflow
Solution 4 - JavaSteve GelmanView Answer on Stackoverflow