eclipse plugin popupMenu 如何获得选中java文件的包名
2007-12-08 14:53
543 查看
Bundle bundle = Platform.getBundle(YourPlugin.getPluginId());
URL url = bundle.getEntry("/");
String targetPath = null;
try
{
targetPath = (new Path((new File(FileLocator.toFileURL(url).getPath()))
.getAbsolutePath())).toString()
}catch(Exception e)
{
e.printStackTrace();
}
------------------------------------------------------------------------
public void run(IAction action)
{
if (selection instanceof IStructuredSelection)
{
Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof ICompilationUnit)
{
ICompilationUnit iFile = (ICompilationUnit) object;
// 获得java工程
IJavaProject jp = iFile.getJavaProject();
ipj = jp.getProject();
String jpName = jp.getElementName();
// 获得.java文件名
String claName = iFile.getElementName();
// 取得所选文件的包名
String path = iFile.getParent().getElementName();
}
}
}
URL url = bundle.getEntry("/");
String targetPath = null;
try
{
targetPath = (new Path((new File(FileLocator.toFileURL(url).getPath()))
.getAbsolutePath())).toString()
}catch(Exception e)
{
e.printStackTrace();
}
------------------------------------------------------------------------
public void run(IAction action)
{
if (selection instanceof IStructuredSelection)
{
Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof ICompilationUnit)
{
ICompilationUnit iFile = (ICompilationUnit) object;
// 获得java工程
IJavaProject jp = iFile.getJavaProject();
ipj = jp.getProject();
String jpName = jp.getElementName();
// 获得.java文件名
String claName = iFile.getElementName();
// 取得所选文件的包名
String path = iFile.getParent().getElementName();
}
}
}
相关文章推荐
- eclipse中如何获得feature与plugin的list
- java如何实现在系统资源管理器中选中指定文件/文件夹?
- 如何获得Java项目文件所在的相对路径
- 如何把使用命令行或者Eclipse将Java程序打包为jar文件
- 如何往eclipse中导入单个java文件
- JAVA中如何将工程文件导入到eclipse中呢??
- eclipse中如何获得feature与plugin的list
- Java如何获得文件编码格式
- Eclipse/myEclipse选中变量名,选择变量后该变量在当前文件中的使用都不变灰色了 标签: javaMyEclipseEclipse同步选中效果 2013-08-18 11:27 1760
- 如何用eclipse打开并运行一个已经写好的java文件?
- 如何把JAVA工程生成一个.JAR文件,而不是一堆JAR(ECLIPSE生成JAR)
- Java如何获得文件编码格式
- Java如何获得文件编码格式
- 如何从在JAVA项目中获得配置文件的路径
- 如何往eclipse项目中导入单个java文件
- Eclipse 如何调整java和xml文件字体大小
- 介绍Java如何获得文件编码格式
- Eclipse中java文件选中变量名,相同变量都变色显示
- 用eclipse如何将java程序生成一个.exe可运行文件?
- Eclipse Java反编译插件Jd-Eclipse plugin,帮你查看.class文件