检查Java中是否使用了类或方法。

huangapple go评论86阅读模式
英文:

Check if class or method is used in Java

问题

我想检查一个JAR文件中是否使用了某个类或方法,以便删除未使用的那些。我不知道如何着手处理这个问题。

英文:

I want to check if a class or method is used in a jar file to delete the ones that are not used. I don't know how to approach it.

答案1

得分: 2

你可以使用集成开发环境(IDE)来完成你想要的操作(Netbeans IDE或IntelliJ Jetbrains)

这个过程很简单,导入jar文件,然后查找特定类的定义/声明。

英文:

You can use an IDE to do what you are looking for (Netbeans IDE or IntelliJ Jetbrains)

The process is simple, import the jar file, and check for the definition/declaration of a particular class.

答案2

得分: 0

用于确定方法是否被使用的最常见方法是构建调用图。如果一个方法没有被调用,那么它可以被移除。然而,调用图并不总是准确的,因为会涉及到反射、不安全操作和多态性的用法。因此,如果你想要移除一个方法,你必须确保这个方法既不会被反射调用,也不会受到其他不准确用法的影响。

为了移除类,你不仅需要确保方法没有被使用,还需要考虑类的字段。因此,你需要识别可能引用字段的所有方法。

所有描述的分析都可以使用工具Soot、WALA、Javassist或OPAL来实现。

英文:

The most used way to identify if a method is used is by building a call graph. If a method is not called, then it can be removed. However, call graphs are not always sound because of the usages of reflection, unsafe, and polymorphism. So if you want to remove a method, you have to be sure that this method is not used by reflection or the other categories of unsoundness.

In order to remove classes, you have not only to ensure that the methods are not used but also the fields of the classes. Therefore, you need to identify all methods that might reference a field.

All the described analyses you can approach using the tools Soot, WALA, Javassist, or OPAL.

答案3

得分: 0

在 Eclipse 中:

  1. 打开类。
  2. 高亮类名。
  3. 按 Ctrl+Shift+G

您应该在“搜索”选项卡下看到指向该类的引用数量。

任何属性或方法都可以按照相同的步骤进行操作。

英文:

On eclipse simply:

  1. Open the class.
  2. Highlight the class name.
  3. Ctrl+Shift+G

You should see under the Search tab the amount of references pointing to that class.

The same procedure can be followed with any property or method.

huangapple
  • 本文由 发表于 2020年3月16日 05:16:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/60697735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定