我正在创建一个实用程序来检测代码库中未使用的方法。通过使用下面的代码,我能够成功找到未使用的方法(没有引用)。但我还需要删除这些未使用的方法。请让我知道是否可以通过 JDT。
// Get all the type declaration of the class.
IType [] typeDeclarationList = unit.getTypes();
for (IType typeDeclaration : typeDeclarationList) {
// Get methods under each type declaration.
IMethod [] methodList = typeDeclaration.getMethods();
for (IMethod method : methodList) {
final List<String> referenceList = new ArrayList<String>();
// loop through the methods and check for each method.
String methodName = method.getElementName();
if (!method.isConstructor()) {
// Finds the references of the method and returns the references of the method.
JDTSearchProvider.searchMethodReference(referenceList, method, scope, iJavaProject);
}
if (referenceList.isEmpty()) {
// delete method
}
}
}