【问题标题】:Automatically add curly braces to single line if/for/while etc statements in IntelliJ for java在 IntelliJ for java 中自动将花括号添加到单行 if/for/while 等语句
【发布时间】:2020-01-11 00:55:51
【问题描述】:

我想在 IntelliJ 中将花括号添加到单行语句中。 假设我有:

if(x)
  print(y)

我希望 IntelliJ 自动将其格式化为:

if(x){
  print(y)
}

【问题讨论】:

    标签: java intellij-idea formatting format


    【解决方案1】:

    File -> Settings -> Editor -> Code style -> Java -> Wrapping and braces -> if/while/for() statement -> Force braces -> Always

    【讨论】:

      【解决方案2】:

      在“'if()' statement”下的“Wrapping and Braces”选项卡上的“文件”>“设置”>“编辑器”>“代码样式”>“Java”下,将“强制大括号”设置为“始终”。 “'for()' 语句”、“'while()' 语句”和“'do ... while' 语句”也是如此。

      当您重新格式化 (Ctrl+Alt+L) 或使用 Ctrl+Shift+Enter,IntelliJ会为你添加大括号。

      【讨论】:

      • 我试过了,当我按 command + option + L 时,它说代码已经格式化了
      • 可能是我项目中的一些其他配置。我会看一下。谢谢你的建议
      猜你喜欢
      • 2015-02-10
      • 2021-03-15
      • 2012-09-06
      • 1970-01-01
      • 2012-02-02
      • 2014-11-24
      • 1970-01-01
      相关资源
      最近更新 更多