IntelliJ不会格式化空行。

huangapple go评论62阅读模式
英文:

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 FileSettingsEditorCode StyleJavaBlank 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

huangapple
  • 本文由 发表于 2020年10月10日 20:41:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/64293542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定