java - Eclipse插件: create a treeview that displays all the deprecated methods

标签 java eclipse treeview

我是 Eclipse 插件开发新手,我正在尝试实现一个 TreeView ,显示当前/选定项目中使用的所有已弃用的方法。

它应该看起来像这样:

-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 有一个非常好的功能,通过删除方法告诉您正在使用的 API 已被弃用。

有没有办法获得所有已弃用方法的完整列表?我确信考虑到 Eclipse 的功能,这可能是一个。

任何有关 Eclipse 如何引用代码进行删除线的解释也值得赞赏。

最佳答案

我是这样解决的:

       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);
                    }
                }
            }
        }

HashMap 存储我访问 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);
                    }

                }
            }

这成功地给了我我需要的树。

关于java - Eclipse插件: create a treeview that displays all the deprecated methods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27052623/

相关文章:

python - 如何计算最小长度的矩形数?

c# - 选择后更改 TreeViewItem 的前景

c - GDB 和 Yosemite 的问题

java - JUnit 测试对 @transactional @Async 方法的调用导致超出锁等待超时

java - 如何清除内存以防止java.lang.OutOfMemoryError

java - 如何以编程方式到达/触发 JEditorPane/JTextPane 内超链接的目标

java - WebSphere Application Server for Liberty 找不到上下文根

telerik - 从 Telerik 到 Kendo Treeview ItemDataBound

delphi - 如何使 TTreeView 在禁用时不突出显示所有节点?

java - Spring 形式 :select tag 选项中的附加属性