原创作者: macrochen   阅读:900次   评论:0条   更新时间:2011-06-01    

在eclipse3.3中,JavaFileEditorInput这个internal类已经被干掉了,所以导致在插件中使用了JavaFileEditorInput之后导致编译不通过,为了做到与eclipse3.3以前版本兼容(至少是3.2),需要进行一下变通
通过google,我们发现,虽然eclipse3.3干掉了JavaFileEditorInput类,但是添加了FileStoreEditorInput来处理打开位于workspace之外的文件.
所以解决办法出来了,首先要判断一下当前的eclipse版本:

java 代码
  1. private static boolean inEclipse33;   
  2.   
  3. static {   
  4.  String version = System.getProperty("osgi.framework.version"); //$NON-NLS-1$   
  5.  if (version != null && version.startsWith("3.3")) //$NON-NLS-1$   
  6.  {   
  7.   inEclipse33 = true;   
  8.  }   
  9. }   
  10.   

然后我们在使用到JavaFileEditorInput的地方这样改写:

java 代码
  1. // 为了兼容3.3和3.2   
  2. String clazzName = element.getClass().getName();   
  3. if (inEclipse33) {   
  4.  if (clazzName.equals("org.eclipse.ui.ide.FileStoreEditorInput")) {   
  5.   IURIEditorInput uri = (IURIEditorInput) element;   
  6.   return getOperation(document, new Path(uri.getURI().getPath()));   
  7.  }   
  8. }else {   
  9.  if (clazzName.equals("org.eclipse.ui.internal.editors.text.JavaFileEditorInput")) {   
  10.   IPathEditorInput pei = (IPathEditorInput) element;   
  11.   return getOperation(document, pei.getPath());   
  12.  }   
  13. }  
评论 共 0 条 请登录后发表评论

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics