【问题标题】:Automatically generated Kotlin code (from Java code) loses all blank lines, making the code uglier自动生成的 Kotlin 代码(来自 Java 代码)丢失所有空行,使代码更丑陋
【发布时间】:2022-01-18 10:08:38
【问题描述】:

使用 IntelliJ IDEA 的自动 Java -> Kotlin 转换器时,空行会丢失,导致代码不那么可读。有没有办法避免这种情况或恢复空白行?

例如,

line1;
line2;

line3;
line4;

可以转换成中间没有空行的东西。

【问题讨论】:

  • IDEA 中目前没有自定义此行为的设置

标签: java kotlin intellij-idea jetbrains-ide


【解决方案1】:

作为一种解决方法,您可以执行以下操作:

  1. 用一些注释替换所有空行。您可以通过替换来做到这一点
<Ctrl+Shift+Enter>
\s*
<Ctrl+Shift+Enter>

<Ctrl+Shift+Enter>
//newLine
<Ctrl+Shift+Enter>

(别忘了开启正则表达式的使用):

  1. 从 Java 转换文件->Kotlin
  2. 删除评论(用空字符串替换)

【讨论】:

  • 智能解决方法,谢谢!
猜你喜欢
  • 1970-01-01
  • 2012-05-30
  • 1970-01-01
  • 2010-10-04
  • 2010-12-29
  • 1970-01-01
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
相关资源
最近更新 更多