Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-02-09 22:43:36 +0000
committerLars Vogel2019-02-12 07:17:58 +0000
commit4ffc136c9a8d8157575a5940a0878030215fa76e (patch)
tree3c3c7ae6c009f64660d7836467dbe2a6ab9cea76 /org.eclipse.ui.editors.tests/src
parent502ba4f4b36e6df1fbceacad1f0c42b4cd32ed76 (diff)
downloadeclipse.platform.text-4ffc136c9a8d8157575a5940a0878030215fa76e.tar.gz
eclipse.platform.text-4ffc136c9a8d8157575a5940a0878030215fa76e.tar.xz
eclipse.platform.text-4ffc136c9a8d8157575a5940a0878030215fa76e.zip
Bug 544315 - DocumentProviderRegistry: also try IPath to get extension
Make getDocumentProvider(IEditorInput) try a little harder by trying to figure out an IPath from the editor input and use the extension of that path, if one can be determined. Change-Id: I6426e0e9fa09b71bd472d5ca545d1333c17323ce Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.ui.editors.tests/src')
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java84
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java1
2 files changed, 85 insertions, 0 deletions
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java
new file mode 100644
index 000000000..58f6157e1
--- /dev/null
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.ui.editors.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+
+import org.eclipse.core.filebuffers.tests.ResourceHelper;
+
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.ide.FileStoreEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+import org.eclipse.ui.texteditor.DocumentProviderRegistry;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+import org.eclipse.ui.editors.text.TextFileDocumentProvider;
+
+public class DocumentProviderRegistryTest {
+
+ @Rule
+ public TemporaryFolder tmp = new TemporaryFolder();
+
+ private IFile file;
+
+ @After
+ public void tearDown() throws Exception {
+ if (file != null) {
+ ResourceHelper.delete(file.getProject());
+ }
+ TestUtil.cleanUp();
+ }
+
+ @Test
+ public void testFindByExtensionInWorkspace() throws Exception {
+ IFolder folder = ResourceHelper.createFolder("DocumentProviderRegistryTestProject/test");
+ file = ResourceHelper.createFile(folder, "file.testfile", "");
+ assertTrue("File should exist: " + file.toString(), file.exists());
+ IEditorInput editorInput = new FileEditorInput(file);
+ IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput);
+ assertEquals("Unexpected document provider found : " + provider.getClass().getName(),
+ TestDocumentProvider.class, provider.getClass());
+ }
+
+ @Test
+ public void testFindByExtensionNonWorkspace() throws Exception {
+ File external = tmp.newFile("external.testfile");
+ IFileStore store = EFS.getLocalFileSystem().getStore(new Path(external.getCanonicalPath()));
+ IEditorInput editorInput = new FileStoreEditorInput(store);
+ IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput);
+ assertEquals("Unexpected document provider found : " + provider.getClass().getName(),
+ TestDocumentProvider.class, provider.getClass());
+ }
+
+ public static class TestDocumentProvider extends TextFileDocumentProvider {
+
+ // Nothing; class registered in plugin.xml so that we can test that we
+ // found the right one.
+
+ }
+}
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java
index f5e3dc91f..98f791711 100644
--- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java
@@ -26,6 +26,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ChainedPreferenceStoreTest.class,
+ DocumentProviderRegistryTest.class,
EncodingChangeTests.class,
GotoLineTest.class,
SegmentedModeTest.class,

Back to the top