在eclipse3.3中,JavaFileEditorInput這個internal類已經被干掉了,所以導致在插件中使用了JavaFileEditorInput之后導致編譯不通過,為了做到與eclipse3.3以前版本兼容(至少是3.2),需要進行一下變通
通過google,我們發現,雖然eclipse3.3干掉了JavaFileEditorInput類,但是添加了FileStoreEditorInput來處理打開位于workspace之外的文件.
所以解決辦法出來了,首先要判斷一下當前的eclipse版本:
java 代碼
- private static boolean inEclipse33;
- static {
- String version = System.getProperty("osgi.framework.version"); //$NON-NLS-1$
- if (version != null && version.startsWith("3.3")) //$NON-NLS-1$
- {
- inEclipse33 = true;
- }
- }
然后我們在使用到JavaFileEditorInput的地方這樣改寫:
java 代碼
- // 為了兼容3.3和3.2
- String clazzName = element.getClass().getName();
- if (inEclipse33) {
- if (clazzName.equals("org.eclipse.ui.ide.FileStoreEditorInput")) {
- IURIEditorInput uri = (IURIEditorInput) element;
- return getOperation(document, new Path(uri.getURI().getPath()));
- }
- }else {
- if (clazzName.equals("org.eclipse.ui.internal.editors.text.JavaFileEditorInput")) {
- IPathEditorInput pei = (IPathEditorInput) element;
- return getOperation(document, pei.getPath());
- }
安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢】