英文:
IntelliJ do not format blank lines
问题
我想在我的代码中处理空行,但每次我按下<kbd>ctrl</kbd> + <kbd>alt</kbd> + <kbd>L</kbd>(格式化文档)时,IntelliJ会根据需要插入和删除空行。
例如,我想要这样做:
package example;
import something1;
import something2;
import java.util.*;
class Example
{
private void method1() {}
private void method2() {}
private void method3() {}
private void method4() {}
}
基本上,我希望在各个导入之间没有多余的空行,并且我希望将方法分成组。然而,IntelliJ将上面的代码格式化如下:
package example;
import something1;
import something2;
import java.util.*;
class Example
{
private void method1() {}
private void method2() {}
private void method3() {}
private void method4() {}
}
我尝试在 文件 → 设置 → 编辑器 → 代码样式 → Java → 空行 中更改值,然而我没有看到停止 IntelliJ 管理空行的选项。
我还希望 Android Studio 也能够类似地进行操作,因为它是基于 IntelliJ 平台的。
英文:
I would like to manage blank lines in my code but everytime I hit <kbd>ctrl</kbd> + <kbd>alt</kbd> + <kbd>L</kbd> (format document), IntelliJ inserts and deletes blank lines however it sees fit.
For example, I would like to do this:
package example;
import something1;
import something2;
import java.util.*;
class Example
{
private void method1() {}
private void method2() {}
private void method3() {}
private void method4() {}
}
Basically I want no extra blank lines between individual imports and I want to split methods into groups. However IntelliJ formats code above as such:
package example;
import something1;
import something2;
import java.util.*;
class Example
{
private void method1() {}
private void method2() {}
private void method3() {}
private void method4() {}
}
I tried changing values in File → Settings → Editor → Code Style → Java → Blank Lines, however I don't see an option to stop IntelliJ from managing blank lines at all.
I also hope that similar can be done for Android Studio because it is based on the IntelliJ platform.
答案1
得分: 1
以下是翻译好的内容:
要获得上述显示的行为(在 IDEA 2020.3 EAP 版本中,可能适用于其他版本):
编辑器,代码风格,Java,导入,导入布局:在表格中删除空行。
编辑器,代码风格,Java,空行:保留最大空行数,在声明中:1。
编辑器,代码风格,Java,空行:最小空行数,在方法周围:0。
英文:
To get the behaviour shown above (with IDEA 2020.3 EAP, probably works with other versions):
Editor, Code Style, Java, Imports, Import Layout: remove the blank lines in the table.
Editor, Code Style, Java, Blank Lines: Keep maximum, In declarations: 1
Editor, Code Style, Java, Blank Lines: Minimum blank lines, Around method: 0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论