diff options
author | Andrew Obuchowicz | 2019-09-13 18:38:04 +0000 |
---|---|---|
committer | Andrew Obuchowicz | 2019-09-19 18:59:13 +0000 |
commit | b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047 (patch) | |
tree | b043ced9521db39cb5ac46b91ce316cd0ba584c1 | |
parent | 58f91bfc319901c60999a9f6ac226d152fcde15d (diff) | |
download | eclipse.platform.text-b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047.tar.gz eclipse.platform.text-b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047.tar.xz eclipse.platform.text-b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047.zip |
Bug 544448 - Add extension point for quickAssistantProcessorsI20190919-1800
Change-Id: If9e4aab45c7389b92475e07b955c45c50bbdd251
Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
10 files changed, 374 insertions, 10 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml index 2bf886673d6..b029e501c0f 100644 --- a/org.eclipse.ui.genericeditor.tests/plugin.xml +++ b/org.eclipse.ui.genericeditor.tests/plugin.xml @@ -279,4 +279,11 @@ contentType="org.eclipse.ui.genericeditor.tests.sub-specialized-content-type" icon="platform:/plugin/org.eclipse.ui.ide/icons/full/etool16/newprj_wiz.png"/> </extension> + <extension + point="org.eclipse.ui.genericeditor.quickAssistProcessors"> + <quickAssistProcessor + class="org.eclipse.ui.genericeditor.tests.contributions.QuickAssistProcessor" + contentType="org.eclipse.ui.genericeditor.tests.content-type"> + </quickAssistProcessor> + </extension> </plugin> diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java index d6504cd6289..31be5ba3115 100644 --- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java @@ -29,6 +29,7 @@ import org.eclipse.swt.custom.ST; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; @@ -58,7 +59,7 @@ public class CompletionTest extends AbstratGenericEditorTest { final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); editor.selectAndReveal(3, 0); openConentAssist(); - this.completionShell= findNewShell(beforeShells); + this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay()); final Table completionProposalList = findCompletionSelectionControl(completionShell); checkCompletionContent(completionProposalList); // TODO find a way to actually trigger completion and verify result against Editor content @@ -71,7 +72,7 @@ public class CompletionTest extends AbstratGenericEditorTest { editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("abc"); editor.selectAndReveal(0, 3); openConentAssist(); - this.completionShell= findNewShell(beforeShells); + this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay()); final Table completionProposalList = findCompletionSelectionControl(completionShell); assertTrue(new DisplayHelper() { @Override @@ -102,7 +103,7 @@ public class CompletionTest extends AbstratGenericEditorTest { final Set<Shell> beforeEnabledShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); editor.selectAndReveal(3, 0); openConentAssist(); - assertNotNull(findNewShell(beforeEnabledShells)); + assertNotNull(findNewShell(beforeEnabledShells, editor.getSite().getShell().getDisplay())); } private void openConentAssist() { @@ -147,8 +148,8 @@ public class CompletionTest extends AbstratGenericEditorTest { assertEquals("Addition of completion proposal should keep selection", selectedProposal, completionProposalList.getSelection()[0].getData()); } - private Shell findNewShell(Set<Shell> beforeShells) { - Shell[] afterShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()) + public static Shell findNewShell(Set<Shell> beforeShells, Display display) { + Shell[] afterShells = Arrays.stream(display.getShells()) .filter(Shell::isVisible) .filter(shell -> !beforeShells.contains(shell)) .toArray(Shell[]::new); @@ -161,7 +162,7 @@ public class CompletionTest extends AbstratGenericEditorTest { final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); editor.selectAndReveal(3, 0); openConentAssist(); - this.completionShell= findNewShell(beforeShells); + this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay()); final Table completionProposalList = findCompletionSelectionControl(this.completionShell); // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait new DisplayHelper() { @@ -188,7 +189,7 @@ public class CompletionTest extends AbstratGenericEditorTest { testCompletion(); emulatePressLeftArrowKey(); DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), LongRunningBarContentAssistProcessor.DELAY + 500); // adding delay is a workaround for bug521484, use only 100ms without the bug - this.completionShell= findNewShell(beforeShells); + this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay()); final Table completionProposalList = findCompletionSelectionControl(this.completionShell); assertEquals("Missing proposals from a Processor", 2, completionProposalList.getItemCount()); // replace with line below when #5214894 is done // checkCompletionContent(completionProposalList); // use this instead of assert above when #521484 is done @@ -205,7 +206,7 @@ public class CompletionTest extends AbstratGenericEditorTest { styledText.notifyListeners(ST.VerifyKey, e); } - private Table findCompletionSelectionControl(Widget control) { + public static Table findCompletionSelectionControl(Widget control) { if (control instanceof Table) { return (Table)control; } else if (control instanceof Composite) { diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java new file mode 100644 index 00000000000..cbc6d4d3d7e --- /dev/null +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2016-2019 Red Hat Inc. and others + * + * 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 + * + * Contributors: + * Andrew Obuchowicz (Red Hat Inc.) + *******************************************************************************/ +package org.eclipse.ui.genericeditor.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +import org.junit.After; +import org.junit.Test; + +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +import org.eclipse.jface.text.tests.util.DisplayHelper; + +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.TextOperationAction; + +/** + * @since 1.2 + */ +public class TestQuickAssist extends AbstratGenericEditorTest { + + private Shell completionShell; + + @Test + public void testCompletion() throws Exception { + final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet()); + openQuickAssist(); + this.completionShell= CompletionTest.findNewShell(beforeShells, editor.getSite().getShell().getDisplay()); + final Table completionProposalList = CompletionTest.findCompletionSelectionControl(completionShell); + checkCompletionContent(completionProposalList); + } + + private void openQuickAssist() { + editor.selectAndReveal(3, 0); + TextOperationAction action = (TextOperationAction) editor.getAction(ITextEditorActionConstants.QUICK_ASSIST); + action.update(); + action.run(); + waitAndDispatch(100); + } + + /** + * Checks that a mock quick assist proposal comes up + * @param completionProposalList the quick assist proposal list + */ + private void checkCompletionContent(final Table completionProposalList) { + // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait + new DisplayHelper() { + @Override + protected boolean condition() { + return completionProposalList.getItemCount() == 1; + } + }.waitForCondition(completionProposalList.getDisplay(), 200); + assertEquals(1, completionProposalList.getItemCount()); + final TableItem quickAssistItem = completionProposalList.getItem(0); + assertTrue("Missing quick assist proposal", quickAssistItem.getText().contains("QUICK ASSIST PROPOSAL")); //$NON-NLS-1$ //$NON-NLS-2$ + + } + + + @After + public void closeShell() { + if (this.completionShell != null && !completionShell.isDisposed()) { + completionShell.close(); + } + } +} diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java new file mode 100644 index 00000000000..4b46e2517cf --- /dev/null +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2019 Red Hat Inc. and others + * + * 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 + * + * Contributors: + * Andrew Obuchowicz (Red Hat Inc.) + *******************************************************************************/ +package org.eclipse.ui.genericeditor.tests.contributions; + +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; +import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; +import org.eclipse.jface.text.source.Annotation; + +public class MockQuickAssistProcessor implements IQuickAssistProcessor{ + + @Override + public String getErrorMessage() { + return "A MOCK ERROR MESSAGE"; + } + + @Override + public boolean canFix(Annotation annotation) { + return true; + } + + @Override + public boolean canAssist(IQuickAssistInvocationContext invocationContext) { + return true; + } + + @Override + public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { + CompletionProposal proposal = new CompletionProposal("QUICK ASSIST PROPOSAL", 0, 10, 0); + ICompletionProposal[] proposals = {proposal}; + return proposals; + } + +} diff --git a/org.eclipse.ui.genericeditor/build.properties b/org.eclipse.ui.genericeditor/build.properties index 90701dab1e6..bd0de62a7e0 100644 --- a/org.eclipse.ui.genericeditor/build.properties +++ b/org.eclipse.ui.genericeditor/build.properties @@ -19,7 +19,8 @@ bin.includes = META-INF/,\ plugin.properties,\ about.html,\ icons/,\ - resources/ + resources/,\ + schema/ src.includes = about.html,\ schema/ diff --git a/org.eclipse.ui.genericeditor/plugin.xml b/org.eclipse.ui.genericeditor/plugin.xml index 9d01b2e0dad..e086d38ce32 100644 --- a/org.eclipse.ui.genericeditor/plugin.xml +++ b/org.eclipse.ui.genericeditor/plugin.xml @@ -25,6 +25,7 @@ <extension-point id="foldingReconcilers" name="%ExtPoint.foldingReconcilers" schema="schema/foldingReconcilers.exsd"/> <extension-point id="characterPairMatchers" name="%ExtPoint.characterPairMatchers" schema="schema/characterPairMatchers.exsd"/> <extension-point id="icons" name="%ExtPoint.iconProviders" schema="schema/icons.exsd"/> + <extension-point id="quickAssistProcessors" name="%ExtPoint.quickAssistProcessors" schema="schema/quickAssistProcessors.exsd"/> <extension point="org.eclipse.ui.editors"> <editor diff --git a/org.eclipse.ui.genericeditor/schema/quickAssistProcessors.exsd b/org.eclipse.ui.genericeditor/schema/quickAssistProcessors.exsd new file mode 100644 index 00000000000..55d95d2c1e2 --- /dev/null +++ b/org.eclipse.ui.genericeditor/schema/quickAssistProcessors.exsd @@ -0,0 +1,112 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.ui.genericeditor" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.ui.genericeditor" id="quickAssistProcessors" name="%ExtPoint.quickAssistProcessors"/> + </appinfo> + <documentation> + This extension point is used to contribute quick assist processors for quick content assist support to a given content type. + </documentation> + </annotation> + + <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence minOccurs="1" maxOccurs="unbounded"> + <element ref="quickAssistProcessor"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="quickAssistProcessor"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.jface.text.quickassist.IQuickAssistProcessor"/> + </appinfo> + </annotation> + </attribute> + <attribute name="contentType" type="string" use="required"> + <annotation> + <documentation> + The target content-type for this extension. Content-types are defined as extension to the org.eclipse.core.contenttype.contentTypes extension point. + </documentation> + <appinfo> + <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + 1.1.600 + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + <extension + point="org.eclipse.ui.genericeditor.quickAssistProcessors"> + <quickAssistProcessor + class="org.eclipse.ui.genericeditor.tests.contributions.QuickAssistProcessor" + contentType="org.eclipse.ui.genericeditor.tests.content-type"> + </quickAssistProcessor> + </extension> + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="apiinfo"/> + </appinfo> + <documentation> + This extension point does not require specific API's to use. Instead, it reuses IQuickAssistProcessor from org.jface.text.quickassist + </documentation> + </annotation> + + + +</schema> diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java index c3a77d760c1..0258fd21e95 100644 --- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java +++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java @@ -17,6 +17,7 @@ *******************************************************************************/ package org.eclipse.ui.internal.genericeditor; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -44,6 +45,7 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.quickassist.IQuickAssistAssistant; +import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; import org.eclipse.jface.text.quickassist.QuickAssistAssistant; import org.eclipse.jface.text.reconciler.IReconciler; import org.eclipse.jface.text.source.ISourceViewer; @@ -192,7 +194,11 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe @Override public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) { QuickAssistAssistant quickAssistAssistant = new QuickAssistAssistant(); - quickAssistAssistant.setQuickAssistProcessor(new MarkerResoltionQuickAssistProcessor()); + List<IQuickAssistProcessor> quickAssistProcessors = new ArrayList<IQuickAssistProcessor>(); + quickAssistProcessors.add(new MarkerResoltionQuickAssistProcessor()); + quickAssistProcessors.addAll(GenericEditorPlugin.getDefault().getQuickAssistProcessorRegistry().getQuickAssistProcessors(sourceViewer, editor, getContentTypes(sourceViewer))); + CompositeQuickAssistProcessor compQuickAssistProcessor = new CompositeQuickAssistProcessor(quickAssistProcessors); + quickAssistAssistant.setQuickAssistProcessor(compQuickAssistProcessor); quickAssistAssistant.setRestoreCompletionProposalSize(EditorsPlugin.getDefault().getDialogSettingsSection("quick_assist_proposal_size")); //$NON-NLS-1$ quickAssistAssistant.setInformationControlCreator(parent -> new DefaultInformationControl(parent, EditorsPlugin.getAdditionalInfoAffordanceString())); return quickAssistAssistant; diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java index 750d4d26393..dcb29fa0c5d 100644 --- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java +++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java @@ -18,6 +18,7 @@ import org.eclipse.jface.text.IAutoEditStrategy; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; import org.eclipse.jface.text.reconciler.IReconciler; import org.eclipse.jface.text.source.ICharacterPairMatcher; import org.eclipse.jface.util.IPropertyChangeListener; @@ -43,6 +44,7 @@ public class GenericEditorPlugin extends AbstractUIPlugin { private TextHoverRegistry textHoversRegistry; private ContentAssistProcessorRegistry contentAssistProcessorsRegistry; + private QuickAssistProcessorRegistry quickAssistProcessorRegistry; private ReconcilerRegistry reconcilierRegistry; private PresentationReconcilerRegistry presentationReconcilierRegistry; private AutoEditStrategyRegistry autoEditStrategyRegistry; @@ -107,6 +109,18 @@ public class GenericEditorPlugin extends AbstractUIPlugin { } /** + * @return the registry allowing to access contributed + * {@link IQuickAssistProcessor}s. + * @since 1.2 + */ + public synchronized QuickAssistProcessorRegistry getQuickAssistProcessorRegistry() { + if (this.quickAssistProcessorRegistry == null) { + this.quickAssistProcessorRegistry = new QuickAssistProcessorRegistry(); + } + return this.quickAssistProcessorRegistry; + } + + /** * @return the registry allowing to access contributed {@link IReconciler}s. * @since 1.1 */ diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/QuickAssistProcessorRegistry.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/QuickAssistProcessorRegistry.java new file mode 100644 index 00000000000..a9dbfc07b6a --- /dev/null +++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/QuickAssistProcessorRegistry.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2016-2019 Red Hat Inc. and others. + * + * 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 + * + * Contributors: + * - Andrew Obuchowicz (Red Hat Inc.) + *******************************************************************************/ +package org.eclipse.ui.internal.genericeditor; + +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.IConfigurationElement; +import org.eclipse.core.runtime.IRegistryChangeEvent; +import org.eclipse.core.runtime.IRegistryChangeListener; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.texteditor.ITextEditor; + +public class QuickAssistProcessorRegistry { + + private static final String EXTENSION_POINT_ID = GenericEditorPlugin.BUNDLE_ID + ".quickAssistProcessors"; //$NON-NLS-1$ + private Map<IConfigurationElement, GenericContentTypeRelatedExtension<IQuickAssistProcessor>> extensions = new HashMap<>(); + private boolean outOfSync = true; + + /** + * Creates the registry and binds it to the extension point. + */ + public QuickAssistProcessorRegistry() { + Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() { + @Override + public void registryChanged(IRegistryChangeEvent event) { + outOfSync = true; + } + }, EXTENSION_POINT_ID); + } + + /** + * Get the contributed {@link IQuickAssistProcessor}s + * + * @return the list of {@link IQuickAssistProcessor} contributed + */ + + public List<IQuickAssistProcessor> getQuickAssistProcessors(ISourceViewer sourceViewer, ITextEditor editor, + Set<IContentType> contentTypes) { + if (this.outOfSync) { + sync(); + } + return this.extensions.values().stream() + .filter(ext -> contentTypes.contains(ext.targetContentType)) + .filter(ext -> ext.matches(sourceViewer, editor)) + .sorted(new ContentTypeSpecializationComparator<IQuickAssistProcessor>()) + .map(GenericContentTypeRelatedExtension<IQuickAssistProcessor>::createDelegate) + .collect(Collectors.toList()); + } + + private void sync() { + Set<IConfigurationElement> toRemoveExtensions = new HashSet<>(this.extensions.keySet()); + for (IConfigurationElement extension : Platform.getExtensionRegistry() + .getConfigurationElementsFor(EXTENSION_POINT_ID)) { + toRemoveExtensions.remove(extension); + if (!this.extensions.containsKey(extension)) { + try { + this.extensions.put(extension, + new GenericContentTypeRelatedExtension<IQuickAssistProcessor>(extension)); + } catch (Exception ex) { + GenericEditorPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, ex.getMessage(), ex)); + } + } + } + for (IConfigurationElement toRemove : toRemoveExtensions) { + this.extensions.remove(toRemove); + } + this.outOfSync = false; + } + +} |