简体   繁体   English

在IntelliJ Idea中用静态导入替换常量的导入

[英]Replace import of constant by static import in IntelliJ Idea

I have a code with some constants in format ClassName.CONSTANT_NAME. 我有一个带有一些常量的代码,格式为ClassName.CONSTANT_NAME。 I want to quickly replace this by CONSTANT_NAME. 我想用CONSTANT_NAME迅速替换它。 But I have not found any efficient way of doing that. 但是我还没有找到任何有效的方法。 Every time I want to static import something I have to: 每次我想静态导入某些东西时,我都必须:

alt + enter
Add on demand static import for ....

for each class. 每堂课 But there is ~1000 classes 但是有大约1000个班级

Is there any quick way of converting import to static import for many classes? 是否有任何将许多类的导入转换为静态导入的快速方法?

It looks like Structural Search & Replace is a good way to do this. 看起来“结构化搜索和替换”是执行此操作的好方法。

Search template: ClassName.CONSTANT_NAME 搜索模板: ClassName.CONSTANT_NAME
Replace template: ClassName.CONSTANT_NAME 替换模板: ClassName.CONSTANT_NAME

And make sure you have selected the checkbox Use static import . 并确保已选中“ Use static import ”复选框。 This will add the static import for you. 这将为您添加静态导入。

IntelliJ IDEA 2018.3中的``结构替换''对话框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM