有没有一种方法可以检测整个项目中是否有重复超过 x 次的硬编码字符串?
比方说,我有一个包含多个文件夹和类的项目,并且我有一个名为Constants
的单独的类,我在其中存储了所有项目常量。由于项目越来越大,因此有可能检测到项目中的重复字符串会很好。当然,它也可以手动完成,但可能已经存在于IntelliJ或其他地方。
示例:
代替:
class A {
String dog = "dog";
String cat = "cat";
String animals = dog + cat;
}
class B {
String dog = "dog";
String horse = "horse";
String animals = dog + horse;
}
我正在努力做到:
class A {
String cat = "cat";
String animals = DOG + cat;
}
class B {
String horse = "horse";
String animals = DOG + horse;
}
class Constant {
static final String DOG = "dog";
}
这太过简单了,但我希望这一点很清楚。
答案 0 :(得分:3)
搜索部分可以通过四种方式完成。
但是,只有第二部分可以自动提取新常量。
将出现一个新的弹出窗口,并带有选项替换所有事件
使用指定的快捷方式(例如Ctrl+Alt+C
或Enter
,将出现另一个对话框,您将可以看到事件计数。
Analyze > Run inspection by name
运行它。将出现一个新对话框,使您可以自定义搜索条件