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. 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 Ganymede插件中的文件。我尝试了如何从Eclipse插件页面获取包浏览器中所选节点的方法,但每当我在代码中使用以下行时,
IFile file = (IFile) structured.getFirstElement(); (This one) IPath path = file.getLocation();
IFile file =(IFile)structured.getFirstElement(); (这一个)IPath path = 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. But i need to get file or folder to get full path for my operations.
插件不起作用,也没有响应也没有异常警告。当我将IFile声明更改为Object声明时,它很好。但我需要获取文件或文件夹来获取我的操作的完整路径。
Any help will be appreciated...
任何帮助将不胜感激...
2 个解决方案
#1
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. (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 )
您还应该在使用-consolelog选项进行测试时启动第二个eclipse实例,以便将错误日志重定向到控制台。 (有关错误日志的信息,如果您使用Eclipse启动配置从SDK eclipse运行您的应用程序,您必须检查第二个实例的错误日志以查看错误而不是第一个eclipse实例之一...我是以前看到人们混淆了这个)
#2
I figured out this issue. I used IJavaElement instead of using IFile. I get IJavaElement with using IPackageFragmentRoot a=(IPackageFragmentRoot) b.getParent(); IJavaElement[] c=a.getChildren();
我想出了这个问题。我使用IJavaElement而不是使用IFile。我使用IPackageFragmentRoot获得IJavaElement a =(IPackageFragmentRoot)b.getParent(); IJavaElement [] c = a.getChildren();
. Before these, I added imported packages of org.eclipse.jdt.core.dom to dependecies of plugin. Now I can take full path of each IJavaElement whether it is a file or folder.
。在此之前,我将org.eclipse.jdt.core.dom的导入包添加到插件的依赖项中。现在我可以获取每个IJavaElement的完整路径,无论它是文件还是文件夹。
#1
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. (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 )
您还应该在使用-consolelog选项进行测试时启动第二个eclipse实例,以便将错误日志重定向到控制台。 (有关错误日志的信息,如果您使用Eclipse启动配置从SDK eclipse运行您的应用程序,您必须检查第二个实例的错误日志以查看错误而不是第一个eclipse实例之一...我是以前看到人们混淆了这个)
#2
I figured out this issue. I used IJavaElement instead of using IFile. I get IJavaElement with using IPackageFragmentRoot a=(IPackageFragmentRoot) b.getParent(); IJavaElement[] c=a.getChildren();
我想出了这个问题。我使用IJavaElement而不是使用IFile。我使用IPackageFragmentRoot获得IJavaElement a =(IPackageFragmentRoot)b.getParent(); IJavaElement [] c = a.getChildren();
. Before these, I added imported packages of org.eclipse.jdt.core.dom to dependecies of plugin. Now I can take full path of each IJavaElement whether it is a file or folder.
。在此之前,我将org.eclipse.jdt.core.dom的导入包添加到插件的依赖项中。现在我可以获取每个IJavaElement的完整路径,无论它是文件还是文件夹。