如何自动删除Java类中的私有字段和方法
我有一个代码生成器,它生成带有大量私有代码的类,例如:
class A {
private void meth1() { ... }
private int var1;
private class SubA { private void meth2() {...} }
}
我正在寻找一种工具,可以在无需人工干预的情况下删除所有未使用的私有字段/方法和内部类。我还希望它能够处理源代码而不是字节代码,以便能够对生成的源代码进行度量。更改代码生成器是可能的,但我正在寻找更简单的东西。
I have a code generator which generates classes with a lot of private code like:
class A {
private void meth1() { ... }
private int var1;
private class SubA { private void meth2() {...} }
}
I'm looking for a tool which would remove all unused private fields/methods and inner classes without human intervention. I would also like it to work on source code instead of byte code to be able to conduct metrics on the generated source code. Changing the code generator would be possible but I'm looking for something simpler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Eclipse 是一个很棒的主意,内置了此功能。它会自动让您知道具有以下属性的私有方法/成员:没有在类中使用过。
Eclipse is a fantastic idea that has this feature built in. It will automatically let you know private methods/members that have not been used within a class.
ProGuard 在对象级别上做得非常好。它可以为您提供一份报告,您可以使用该报告来追踪源中未使用的方法。我不知道有什么工具可以自动删除未使用方法的源。
ProGuard does a pretty good job with this at the object level. It can give you a report that you can use to track down the unused methods in the source. I don't know of a tool that automatically strips the source of unused methods.