我需要替换项目中的旧记录器声明语句,它们类似于
private final static Logger logger = LogManager.getLogger();
以类名作为参数,用于每个相应的封闭类,例如
private final static Logger logger = LogManager.getLogger(EnclosingClass.class);
我查看了实时模板,但它不会取代现有的语句。有什么办法吗?
谢谢
您可以使用Edit | Find | Replace Structurally
来执行此操作。使用如下模板:
<replaceConfiguration name="Unnamed" text="private final static Logger $logger$ = LogManager.getLogger(); " recursive="false" type="JAVA" pattern_context="member" search_injected="false" reformatAccordingToStyle="false" shortenFQN="false" replacement="private final static Logger $logger$ = LogManager.getLogger($class$); " case_sensitive="true">
<constraint name="__context__" within="" contains="" />
<constraint name="logger" within="" contains="" />
<variableDefinition name="class" script=""logger.containingClass.qualifiedName + ".class""" />
</replaceConfiguration>
您可以复制此模板并在对话框右上角的工具按钮下调用Import Template from Clipboard
。