1

给定名称ch/mollusca/sample/snippet.xml,当它作为源文件或 JAR 位于项目类路径中时,是否有一种简单的方法可以在 JDT 代码中获取该文件?

该文件也可能位于另一个项目中,该项目由该项目引用,我试图在该项目中获取名称后面的实际文件。

这是特定于 Java 项目的,因此如果有帮助,可以获取 IJavaProject。

4

2 回答 2

1

这可能不是你想要的答案,但这是我能做的最好的(因为你的问题已经有 2 天了,我可能会把这个扔给你):

Eclipse 角文章:抽象语法树

Eclipse JDT - 抽象语法树 (AST) 和 Java 模型 - 教程

这两篇很棒的文章将为您指明正确的方向。

于 2010-12-22T22:00:43.407 回答
0

这个怎么样:

IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if ( activeEditor != null ) {
    IResource activeEditorResource = (IResource)activeEditor.getEditorInput().getAdapter( IResource.class );
    if ( activeEditorResource != null && activeEditorResource.getFullPath() != null ) {
        String activeFileName = activeEditorResource.getFullPath().toOSString();
        //...do something with the active file
    }
}
于 2010-12-20T18:03:44.380 回答