Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ReconcilerRegistry.java')
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ReconcilerRegistry.java46
1 files changed, 8 insertions, 38 deletions
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ReconcilerRegistry.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ReconcilerRegistry.java
index c942335a0dc..28d1f39f751 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ReconcilerRegistry.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ReconcilerRegistry.java
@@ -10,14 +10,13 @@
*******************************************************************************/
package org.eclipse.ui.internal.genericeditor;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
@@ -38,34 +37,7 @@ public class ReconcilerRegistry {
private static final String EXTENSION_POINT_ID = GenericEditorPlugin.BUNDLE_ID + ".reconcilers"; //$NON-NLS-1$
- /**
- * This class wraps and proxies an {@link IReconciler} provided through extensions
- * and loads it lazily when it can contribute to the editor, then delegates all operations to
- * actual reconcilier.
- */
- private static class ReconcilerExtension {
- private static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$
- private static final String CONTENT_TYPE_ATTRIBUTE = "contentType"; //$NON-NLS-1$
-
- private IConfigurationElement extension;
- private IContentType targetContentType;
-
- private ReconcilerExtension(IConfigurationElement element) throws Exception {
- this.extension = element;
- this.targetContentType = Platform.getContentTypeManager().getContentType(element.getAttribute(CONTENT_TYPE_ATTRIBUTE));
- }
-
- public IReconciler createDelegate() {
- try {
- return (IReconciler) extension.createExecutableExtension(CLASS_ATTRIBUTE);
- } catch (CoreException e) {
- GenericEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, e.getMessage(), e));
- }
- return null;
- }
-
- }
- private Map<IConfigurationElement, ReconcilerExtension> extensions = new HashMap<>();
+ private Map<IConfigurationElement, GenericContentTypeRelatedExtension<IReconciler>> extensions = new HashMap<>();
private boolean outOfSync = true;
/**
@@ -91,13 +63,11 @@ public class ReconcilerRegistry {
if (this.outOfSync) {
sync();
}
- List<IReconciler> res = new ArrayList<>();
- for (ReconcilerExtension ext : this.extensions.values()) {
- if (contentTypes.contains(ext.targetContentType)) {
- res.add(ext.createDelegate());
- }
- }
- return res;
+ return this.extensions.values().stream()
+ .filter(ext -> contentTypes.contains(ext.targetContentType))
+ .sorted(new ContentTypeSpecializationComparator<IReconciler>())
+ .map(GenericContentTypeRelatedExtension<IReconciler>::createDelegate)
+ .collect(Collectors.toList());
}
private void sync() {
@@ -106,7 +76,7 @@ public class ReconcilerRegistry {
toRemoveExtensions.remove(extension);
if (!this.extensions.containsKey(extension)) {
try {
- this.extensions.put(extension, new ReconcilerExtension(extension));
+ this.extensions.put(extension, new GenericContentTypeRelatedExtension<IReconciler>(extension));
} catch (Exception ex) {
GenericEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, ex.getMessage(), ex));
}

Back to the top