Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2018-07-29 11:57:09 +0000
committerAndrey Loskutov2018-07-29 12:32:54 +0000
commit8a8f207b17281900ff1efc0e184d082f4146196c (patch)
tree0d3ffab90c8f622cbd9c5af9bcda4de9575daea2
parentfc2bb296a5c1fd8ca54d85acad5877894bcdfd01 (diff)
downloadeclipse.platform.ui-8a8f207b17281900ff1efc0e184d082f4146196c.tar.gz
eclipse.platform.ui-8a8f207b17281900ff1efc0e184d082f4146196c.tar.xz
eclipse.platform.ui-8a8f207b17281900ff1efc0e184d082f4146196c.zip
Bug 537466 - ResourceUtil.getFile(IEditorInput) should check for more
adapters If we only ask for IFile adapter (because we need a *file*), but the adapter factory contributes to more generic IResource case (and *can* also adapt to files), ResourceUtil will not work as expected. Change-Id: Iba99a8e76f07e30579a2f844ce55a60c981b0003 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java
index 429eb829eba..fc5ad8b477a 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java
@@ -14,6 +14,7 @@ package org.eclipse.ui.ide;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.Adapters;
@@ -21,6 +22,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.part.FileEditorInput;
@@ -53,7 +55,25 @@ public final class ResourceUtil {
public static IFile getFile(IEditorInput editorInput) {
// Note: do not treat IFileEditorInput as a special case. Use the adapter mechanism instead.
// See Bug 87288 [IDE] [EditorMgmt] Should avoid explicit checks for [I]FileEditorInput
- return Adapters.adapt(editorInput, IFile.class);
+ IFile file = Adapters.adapt(editorInput, IFile.class);
+ if (file != null) {
+ return file;
+ }
+ IResource resource = Adapters.adapt(editorInput, IResource.class);
+ if (resource instanceof IFile) {
+ return (IFile) resource;
+ }
+ if (editorInput instanceof IStorageEditorInput) {
+ try {
+ IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
+ if (storage != null) {
+ file = Adapters.adapt(storage, IFile.class);
+ }
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ return file;
}
/**

Back to the top