开发者

How to automatically remove private fields and methods in Java classes

I have a code generator which generates classes wit开发者_C百科h 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.


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜