您的位置:首页 > 编程语言 > Java开发

eclipse plugin popupMenu 如何获得选中java文件的包名

2007-12-08 14:53 447 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: