简体   繁体   English

如何找到(并消除)接口中声明的所有未引用字段?

[英]How can I find (and eliminate) all unreferenced fields declared in an interface?

After eliminating some specific nonsense pattern, I need to identify and possibly delete fields that are declared in some interface like this: 在消除了一些特定的无意义模式之后,我需要识别并可能删除在某个界面中声明的字段,如下所示:

public interface X
{
    String A = "xxx";
    String B = "zzz";
}

Sure I can use Eclipse's "find all references" for one identifier after another, but facing thousands of them lets that appear like a very dull fulltime job for days to come. 当然,我可以使用Eclipse的“查找所有引用”作为一个接一个的标识符,但面对成千上万的标记,让它在未来几天看起来像一个非常枯燥的全职工作。

I tried both Google CodePro and the warnings that the Java compiler can spit out on demand, but found only options for non-public fields in classes, not for public fields in interfaces. 我尝试了Google CodePro和Java编译器可以按需吐出的警告,但是只找到了类中非公共字段的选项,而不是接口中的公共字段。

My next try would be: Comment them all out, and go through the errorlist. 我的下一个尝试是:将它们全部注释掉,然后浏览错误列表。 All fields that are not in the error list can be safely (in my case!) removed. 错误列表中没有的所有字段都可以安全地(在我的情况下!)被删除。 That will be a dull day, too, because instead of a list of all fields that do have active references I am looking for a list of all fields that are not referenced anywhere. 这也将是一个沉闷的一天,因为我没有找到任何有活动参考的所有字段的列表,而是寻找在任何地方引用的所有字段的列表。

So how can I find all those now-unreferenced fields efficiently? 那么我怎样才能有效地找到所有那些现在没有参考的领域呢?

I mean: I see it is dangerous to look at those references for a given project because another project that my Eclipse workspace does not know about might have references. 我的意思是:我认为查看给定项目的那些引用是危险的,因为我的Eclipse工作区不知道的另一个项目可能有引用。 That might be the rationale behind not offering the warning/analysis option I look for in Eclipse or CodePro. 这可能是我不在Eclipse或CodePro中提供警告/分析选项的基本原理。

This is not the case here, though. 但事实并非如此。 If it's not references in my project, I want to eliminate it. 如果它不是我的项目中的引用,我想消除它。

我认为UCDetector就是你想要的: http ://www.ucdetector.org/

如果IntelliJ IDEA是您的选择,即使是免费社区版也会在现场突出显示未使用的界面方法

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

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