【问题标题】:How can I stop IntelliJ from putting parameters on their own line?如何阻止 IntelliJ 将参数放在自己的行上?
【发布时间】:2014-08-04 12:40:59
【问题描述】:

我刚刚写了这行:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(actualReader);

自动重新格式化给了我:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>
                (actualReader);

我认为这看起来非常奇怪,我想告诉 IntelliJ 永远不要将参数放在自己的行上。我愿意:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(
                actualReader);

或者更好:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = 
       new HDF5CompoundDSBridgeBuilder<>(actualReader);

我正在查看 Code Style > Java > Wrapping and Braces 下的项目设置,但我不确定应该更改哪个选项。我不想在 '(' 之后总是有一个新行,我只是想确保 IntelliJ 在中断多行语句时永远不会中断。我没有看到任何其他可以更改的选项。

这个可以吗?

编辑:如果有人想在他们自己的 IntelliJ 上进行测试,我将边距设置为 120 个字符,并且确切的行(具有正确数量的空白 - 8 个空格)是:

        HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(actualReader)

【问题讨论】:

  • 好问题,关注。

标签: java intellij-idea ide


【解决方案1】:

导致发生换行的设置是代码样式> Java > [换行和大括号] >“方法调用参数”。如果您不想包装,可以设置为“不包装”。对于换行,设置为“如果长就换行”或“如果长就切下来”。观看示例代码中的foo1 方法,了解wrap 和chop 的区别。

换行:

wrapped(
    0x0051, 0x0052, 0x0053,
    0x0054, 0x0055, 0x0056,
    0x0057);

印章:

chopped(
    0x0051, 
    0x0052,
    0x0053,
    0x0054, 
    0x0055, 
    0x0056,
    0x0057);

要获得您的第一个选择,使 '(' 与方法调用(或本例中的构造函数调用)一起保留,请设置“'(' 之后的新行”选项。这将为您提供:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(
        actualReader);

要获得第二个“或更好”的选项,请将 代码样式 > Java > [Wrapping and Braces] > "Assignment Statements" 设置为 "Wrap if long"、"Chop if long" 或“总是包装”。设置为“Wrap if long”你会得到:

HDF5CompoundDSBridgeBuilder<WritableDataPoint> actualBridgeBuilder = 
        new HDF5CompoundDSBridgeBuilder<>(actualReader);

【讨论】:

  • 我正在检查“方法声明参数”块下的选项,但我没有想到该块本身也是可配置的。这正是我一直在寻找的,并立即消除了我的头痛。谢谢!
【解决方案2】:

我认为这是可能的,因为我从未见过 IntelliJ 做你所描述的事情。

我的 IntelliJ 13.1.1 没有将参数放在新行上。当我查看方法调用参数下的 Code Style->Java 时,所有框都未选中。看看你的也一样。

【讨论】:

  • 我只勾选了“多行对齐”。取消选中它不会改变任何东西。
  • “常规”下的右边距设置为多少?我的是 120 个字符。
  • 120 个字符 - 查看我对文本的编辑,其中包含适当数量的空格,如果需要,您可以在 IntelliJ 上尝试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
  • 2020-02-02
  • 2017-04-11
  • 2021-06-23
  • 2022-01-20
  • 1970-01-01
  • 2021-12-30
相关资源
最近更新 更多