Intellij 代码格式化,新行上的 Java 注释

我用的是 IntelliJ12 它把我的成员变量注释放在同一行,我讨厌这样!如何设置代码格式化程序使注释保持在单独的行上?

谢谢!

37856 次浏览

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

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

enter image description here

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

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