intellij-将空参数记录器替换为包含相应类名的参数

w8biq8rn  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(366)

我需要替换项目中的旧记录器声明语句,如下所示

private final static Logger logger = LogManager.getLogger();

以类名作为参数,用于每个相应的封闭类,例如。

private final static Logger logger = LogManager.getLogger(EnclosingClass.class);

我查看了live模板,但它不会替换现有的语句。有什么办法吗?
非常感谢。

pexxcrt2

pexxcrt21#

你可以用 Edit | Find | Replace Structurally 这样做。使用如下所示的模板:

<replaceConfiguration name="Unnamed" text="private final static Logger $logger$ = LogManager.getLogger();&#10;" recursive="false" type="JAVA" pattern_context="member" search_injected="false" reformatAccordingToStyle="false" shortenFQN="false" replacement="private final static Logger $logger$ = LogManager.getLogger($class$);&#10;" case_sensitive="true">
  <constraint name="__context__" within="" contains="" />
  <constraint name="logger" within="" contains="" />
  <variableDefinition name="class" script="&quot;logger.containingClass.qualifiedName + &quot;.class&quot;&quot;" />
</replaceConfiguration>

您可以复制此模板并调用 Import Template from Clipboard 在对话框右上角的工具按钮下。

相关问题