英文:
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 中:
- 打开类。
- 高亮类名。
- 按 Ctrl+Shift+G
您应该在“搜索”选项卡下看到指向该类的引用数量。
任何属性或方法都可以按照相同的步骤进行操作。
英文:
On eclipse simply:
- Open the class.
- Highlight the class name.
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论