2007-11-24

eclipse3.3关于JavaFileEditorInput兼容性问题的解决

关键字: Eclipse 兼容 JavaFileEditorInput

在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. }  
评论
wzfj2002 2008-05-31
看到一则这样的东西:“刚刚遇到同样的问题,更新jsEclipse 1.5.5就ok了,相信你已经解决了,1.5.3版本是有这样的问题,呵呵!”相信能解决了
wzfj2002 2008-05-31
晕了,在哪里改写嵌入以上代码,能否说的更清楚些,继续关注中。。
发表评论

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