Intellij idea 在IntelliJ中将单行方法重新格式化为单行文本

Intellij idea 在IntelliJ中将单行方法重新格式化为单行文本,intellij-idea,Intellij Idea,我希望IntelliJ 2019.x更改单行方法,例如: public String getFileName ( ) { return this.fileName; } …作为一行文本,如下所示: public String getFileName ( ) { return this.fileName; } 我希望格式是永久的。是否有一些代码样式或其他设置 不,我不想临时“折叠”它,只想在我点击它时将它展开回四行。此折叠功能已被覆盖,并且已被删除 通过在/@formatter:off

我希望IntelliJ 2019.x更改单行方法,例如:

public String getFileName ( )
{
    return this.fileName;
}
…作为一行文本,如下所示:

public String getFileName ( ) { return this.fileName; }
我希望格式是永久的。是否有一些代码样式或其他设置


不,我不想临时“折叠”它,只想在我点击它时将它展开回四行。此折叠功能已被覆盖,并且已被删除

通过在
/@formatter:off
/@formatter:on
之间包装代码,可以禁用特定块的IDE默认格式设置


Ref:

您可以通过在
/@formatter:off
/@formatter:on
之间包装代码来禁用特定块的IDE默认格式设置


参考:

以下代码样式设置可用:
首选项|编辑器|代码风格| Java |包装和大括号|重新格式化时保留|一行简单方法

启用它以保持以所需样式格式化的任何方法的格式

不幸的是,没有代码样式设置来格式化单行正文的方法。但是,对于这种格式,有一种解决方法是使用以下模板使用结构化搜索和替换:

<replaceConfiguration name="constructors &amp; methods" text="$ReturnType$ $Method$($ParameterType$ $Parameter$) {&#10;    $st$;&#10;}" recursive="false" caseInsensitive="true" type="JAVA" pattern_context="member" reformatAccordingToStyle="true" shortenFQN="true" replacement="$ReturnType$ $Method$($ParameterType$ $Parameter$) { $st$; }">
  <constraint name="__context__" within="" contains="" />
  <constraint name="ReturnType" minCount="0" within="" contains="" />
  <constraint name="Method" within="" contains="" />
  <constraint name="ParameterType" within="" contains="" />
  <constraint name="Parameter" minCount="0" maxCount="2147483647" within="" contains="" />
  <constraint name="st" within="" contains="" />
</replaceConfiguration>

复制上面的模板并打开
编辑|查找|结构替换
。接下来通过调用
从剪贴板导入模板
(在cog菜单下)导入模板,然后单击查找


这将查找具有单行正文的所有方法,并将它们替换为在一行上格式化的相同方法。

以下代码样式设置可用:
首选项|编辑器|代码风格| Java |包装和大括号|重新格式化时保留|一行简单方法

启用它以保持以所需样式格式化的任何方法的格式

不幸的是,没有代码样式设置来格式化单行正文的方法。但是,对于这种格式,有一种解决方法是使用以下模板使用结构化搜索和替换:

<replaceConfiguration name="constructors &amp; methods" text="$ReturnType$ $Method$($ParameterType$ $Parameter$) {&#10;    $st$;&#10;}" recursive="false" caseInsensitive="true" type="JAVA" pattern_context="member" reformatAccordingToStyle="true" shortenFQN="true" replacement="$ReturnType$ $Method$($ParameterType$ $Parameter$) { $st$; }">
  <constraint name="__context__" within="" contains="" />
  <constraint name="ReturnType" minCount="0" within="" contains="" />
  <constraint name="Method" within="" contains="" />
  <constraint name="ParameterType" within="" contains="" />
  <constraint name="Parameter" minCount="0" maxCount="2147483647" within="" contains="" />
  <constraint name="st" within="" contains="" />
</replaceConfiguration>

复制上面的模板并打开
编辑|查找|结构替换
。接下来通过调用
从剪贴板导入模板
(在cog菜单下)导入模板,然后单击查找

这将查找具有单行正文的所有方法,并将它们替换为在一行上格式化的相同方法