简体   繁体   English

如何从Eclipse插件获取包资源管理器中选定节点的完整路径?

[英]How to get full path of the selected node in the package explorer from an Eclipse plugin?

I am attempting to get full path of a selected node in the package explorer which is a folder or package not a file in my Eclipse Ganymede plug-in. 我试图在包浏览器中获取选定节点的完整路径,这是我的Eclipse Ganymede插件中的文件夹或包而不是文件。 I tried the way that is mentioned at How to get the selected node in the package explorer from an Eclipse plugin page, but whenever i use the following line in my code, 我尝试了如何从Eclipse插件页面获取包资源管理器中的选定节点中提到的方法,但是每当我在代码中使用以下行时,

IFile file = (IFile) structured.getFirstElement(); IFile文件=(IFile)结构.getFirstElement(); (This one) IPath path = file.getLocation(); (这一点)IPath路径= file.getLocation();

plugin does not work and does not respond also it gives no exception warning. 插件不起作用,也没有响应,也不会发出异常警告。 When i changed IFile declaration to Object declaration it is fine. 当我将IFile声明更改为Object声明时就可以了。 But i need to get file or folder to get full path for my operations. 但是我需要获取文件或文件夹以获取操作的完整路径。

Any help will be appreciated... 任何帮助将不胜感激...

May be you should debug your code and check what is the actual type of the selection's first element. 可能是您应该调试代码并检查选择的第一个元素的实际类型是什么。

You should also launch your second eclipse instance when testing with the -consolelog option in order to have error log redirected to the console. 使用-consolelog选项进行测试时,还应该启动第二个Eclipse实例,以便将错误日志重定向到控制台。 (for information about error log, if your are running your app from an SDK eclipse using Eclipse launch configuration, you have to check the error log of the second instance to see errors and not the one of the first eclipse instance ... I am used to see people confusing this ) (有关错误日志的信息,如果您正在使用Eclipse启动配置从SDK eclipse运行您的应用程序,则必须检查第二个实例的错误日志以查看错误,而不是第一个eclipse实例。曾经看到人们对此感到困惑)

I figured out this issue. 我发现了这个问题。 I used IJavaElement instead of using IFile. 我使用IJavaElement而不是IFile。 I get IJavaElement with using IPackageFragmentRoot a=(IPackageFragmentRoot) b.getParent(); 我使用IPackageFragmentRoot a =(IPackageFragmentRoot)b.getParent();获得了IJavaElement。 IJavaElement[] c=a.getChildren(); IJavaElement [] c = a.getChildren();

. Before these, I added imported packages of org.eclipse.jdt.core.dom to dependecies of plugin. 在此之前,我将导入的org.eclipse.jdt.core.dom软件包添加到了插件的依赖项中。 Now I can take full path of each IJavaElement whether it is a file or folder. 现在,我可以获取每个IJavaElement的完整路径,无论是文件还是文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM