如何获取引用的项目或库的名称?

时间:2012-05-28 02:51:50

标签: java eclipse eclipse-plugin

我目前正在为Eclipse开发一个插件,用于分析Workspace中Java和插件项目的依赖关系和引用。

但是,我无法找到一种方法来获取在类路径条目中找到的引用项目或库的名称。

这就是我所拥有的(摘自更长的方法):

IJavaProject j= JavaCore.create(project);          //project is an IProject
try {
    IClasspathEntry[] classpath= j.getRawClasspath();

    // Get required Libraries and Projects
    for (IClasspathEntry entry : classpath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY: {
            //Retrieve name of the Library
            break;              
            }
        case IClasspathEntry.CPE_PROJECT: {
            //Retrieve name of the Project
            break;
        }
    }
} catch [...]

有没有人知道如何在标记位置获取名称,或者更好的方法来检索它们?

1 个答案:

答案 0 :(得分:2)

在与其他人协商后,我终于找到了解决方案:

switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY: {
        String name = entry.getPath().segment(0);
        /* Further processing for a Library
        *...
        */
        break;              
        }
    case IClasspathEntry.CPE_PROJECT: {
        String name = entry.getPath().segment(0);
        /* Further processing for a Project
        *...
        */
        break;
    }
相关问题