在eclipse3.3中,JavaFileEditorInput這個(gè)internal類已經(jīng)被干掉了,所以導(dǎo)致在插件中使用了JavaFileEditorInput之后導(dǎo)致編譯不通過,為了做到與eclipse3.3以前版本兼容(至少是3.2),需要進(jìn)行一下變通
通過google,我們發(fā)現(xiàn),雖然eclipse3.3干掉了JavaFileEditorInput類,但是添加了FileStoreEditorInput來處理打開位于workspace之外的文件.
所以解決辦法出來了,首先要判斷一下當(dāng)前的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;
- }
- }
然后我們?cè)谑褂玫絁avaFileEditorInput的地方這樣改寫:
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());
- }
安徽新華電腦學(xué)校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢】