无法在eclipse插件中检索选定的java文件名/路径 [英] cannot retrieve the selected java filename/path in eclipse plugin
问题描述
我正在开发一个插件,需要
检索java文件的路径/文件名。
I am developing a plugin that requires retrieval of path/filename of java files.
我编写的代码,成功检索文件名/ xml或清单文件的路径,
但无法检索包中Java文件的路径。
The code that i have written, successfully retrieves the filenames/path of the xml or manifest files, but is unable to retrieve the path of the Java files in the packages.
我使用的代码是: -
the code I have used is :-
if(IStructuredSelection的选择实例)
if (selection instanceof IStructuredSelection)
{
Object o = ((IStructuredSelection) selection).getFirstElement();
if (o instanceof IFile)
{
IPath loc = ((IFile) o).getLocation();
if (loc != null)
{
selectedFile = loc.toOSString();
}
else
selectedFile = "Error at loc";
}
else
selectedFile = "Error at O";
}
请尽快帮助我。
焦急地等待着。
谢谢你。
please help me in this, asap. anxiously waiting. thank you.
推荐答案
在你的帮助下,我找到了一个蠢货:
With your help I was able to figure out a sloution:
Object o = ((IStructuredSelection) selection).getFirstElement();
然后
IPath loc = ((ICompilationUnit) o).getPath();
然后
selectedFile = loc.toOSString();
这样,您就可以获得所选java文件的路径。而且,这显示了从项目名称开始的路径名。
With this, you will be able to get the path of the java file that you selected. and also, this shows the pathname starting from the project name.
这篇关于无法在eclipse插件中检索选定的java文件名/路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!