Reputation: 3364
I'm new to Eclipse plugin development and I'm trying to implement a treeview that displays all the deprecated methods used in the current/selected project.
It should look like this:
-jdom
--- method1
-------file1 that uses this method
-------file2 that uses this method
--- method2
-------file1 that uses this method
--- method3
-------file1 that uses this method
-log4j
----method1
-------file1 that uses this method
--- method2
--- method3
Eclipse has this very good feature that tells you the API that you are using has been deprecated by striking through the method.
Is there a way I can get a full list of all the deprecated methods? I'm sure this can be one given what Eclipse can do.
Any explanation on how Eclipse does the strikethrough with reference to the code is also appreciated.
Upvotes: 1
Views: 336
Reputation: 3364
I worked it out in this way:
for (Map.Entry<String, Map<String, Set<String>>> entry : treeMap
.entrySet()) {
if (!entry.getValue().isEmpty()) {
LibraryModel libraryModel = new LibraryModel(entry.getKey());
root.addLibrary(libraryModel);
for (Map.Entry<String, Set<String>> methodToFileEntry : entry
.getValue().entrySet()) {
MethodModel methodModel = new MethodModel(
methodToFileEntry.getKey());
libraryModel.addMethod(methodModel);
for (String fileName : methodToFileEntry.getValue()) {
FileModel fileModel = new FileModel(fileName, fileName);
methodModel.addFile(fileModel);
}
}
}
}
The HashMap stores the information I get from visiting AST
for (MethodInvocation method : visitor.getMethods()) {
if (method.resolveMethodBinding().isDeprecated()) {
for (IAnnotationBinding iab: method.resolveMethodBinding()
.getAnnotations()) {
for (IMemberValuePairBinding ivab: iab.getAllMemberValuePairs()) {
System.out.println(ivab.getKey());
System.out.println(ivab.getValue());
}
}
String deprecatedMethod = method.getName().toString();
String fileName = parse.getJavaElement().getResource()
.getName();
String packageName = method.resolveMethodBinding()
.getDeclaringClass().getQualifiedName();
String library = findLibrary(packageName);
if (treeMap.get(library).isEmpty()
|| treeMap.get(library).get(deprecatedMethod)
.isEmpty()) {
Map<String, Set<String>> innerMap = new HashMap<String, Set<String>>();
Set<String> fileNames = new HashSet<String>();
fileNames.add(fileName);
innerMap.put(deprecatedMethod, fileNames);
treeMap.put(library, innerMap);
} else {
Map<String, Set<String>> innerMap = treeMap
.get(library);
innerMap.get(deprecatedMethod).add(fileName);
}
}
}
This successfully gave me the tree I needed.
Upvotes: 2
Reputation: 2578
This may help you
To get all deprecated method : here I'm using java.util.Date class
Method[] methods = java.util.Date.class.getMethods();
for (int i = 0; i < methods.length; i++) {
java.lang.annotation.Annotation annotations[] = methods[i]
.getAnnotations();
for (int j = 0; j < annotations.length; j++) {
if (annotations[j] instanceof Deprecated) {
System.out.println("Deprecated method Name : "
+ methods[i].getName());
}
}
}
Upvotes: 0