Search in sources :

Example 1 with SharedStateContribution

use of org.eclipse.xtext.ui.shared.contribution.SharedStateContribution in project xtext-eclipse by eclipse.

the class SharedStateContributionRegistryImpl method initializeContributions.

private synchronized ImmutableList<? extends SharedStateContribution> initializeContributions() {
    if (contributions == null) {
        final ImmutableList.Builder<SharedStateContribution> listBuilder = ImmutableList.builder();
        IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(EXTENSION_POINT);
        IExtension[] extensions = extensionPoint.getExtensions();
        for (IExtension extension : extensions) {
            IConfigurationElement[] configurationElements = extension.getConfigurationElements();
            for (IConfigurationElement configurationElement : configurationElements) {
                try {
                    Module childModule = (Module) configurationElement.createExecutableExtension("class");
                    SharedStateContribution contribution = createContribution(childModule);
                    listBuilder.add(contribution);
                } catch (CoreException e) {
                    logger.error(e.getMessage(), e);
                } catch (ProvisionException e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
        contributions = listBuilder.build();
    }
    return contributions;
}
Also used : ProvisionException(com.google.inject.ProvisionException) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) ImmutableList(com.google.common.collect.ImmutableList) IExtension(org.eclipse.core.runtime.IExtension) Module(com.google.inject.Module) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) SharedStateContribution(org.eclipse.xtext.ui.shared.contribution.SharedStateContribution)

Example 2 with SharedStateContribution

use of org.eclipse.xtext.ui.shared.contribution.SharedStateContribution in project xtext-eclipse by eclipse.

the class SharedStateContributionRegistryImplTest method testCreateContribution.

@Test
public void testCreateContribution() {
    SharedStateContributionRegistryImpl registry = new SharedStateContributionRegistryImpl(injector);
    SharedStateContribution contribution = registry.createContribution(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(CharSequenceClient.class).to(CharSequenceClientImpl.class);
        }
    });
    Assert.assertTrue(contribution.isContributionSupported(CharSequenceClient.class));
    Assert.assertFalse(contribution.isContributionSupported(IXtextDocument.class));
    Assert.assertEquals("fromParentInjector", contribution.getContribution(CharSequenceClient.class).getSeq());
}
Also used : Binder(com.google.inject.Binder) SharedStateContributionRegistryImpl(org.eclipse.xtext.ui.shared.internal.SharedStateContributionRegistryImpl) Module(com.google.inject.Module) SharedStateContribution(org.eclipse.xtext.ui.shared.contribution.SharedStateContribution) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 3 with SharedStateContribution

use of org.eclipse.xtext.ui.shared.contribution.SharedStateContribution in project xtext-eclipse by eclipse.

the class SharedStateContributionRegistryImpl method createContribution.

/*
	 * Public for testing purpose.
	 */
public SharedStateContribution createContribution(final Module childModule) {
    Injector childInjector = createInjectorWithoutJITBindings(childModule);
    SharedStateContribution contribution = childInjector.getInstance(SharedStateContribution.class);
    return contribution;
}
Also used : Injector(com.google.inject.Injector) SharedStateContribution(org.eclipse.xtext.ui.shared.contribution.SharedStateContribution)

Aggregations

SharedStateContribution (org.eclipse.xtext.ui.shared.contribution.SharedStateContribution)3 Module (com.google.inject.Module)2 ImmutableList (com.google.common.collect.ImmutableList)1 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 ProvisionException (com.google.inject.ProvisionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 SharedStateContributionRegistryImpl (org.eclipse.xtext.ui.shared.internal.SharedStateContributionRegistryImpl)1 Test (org.junit.Test)1