org.eclipse.xtext.resource.IResourceServiceProvider.Registry Java Examples

The following examples show how to use org.eclipse.xtext.resource.IResourceServiceProvider.Registry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegistryProvider.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void register(IResourceServiceProvider.Registry registry, Injector injector) {
    IResourceServiceProvider resourceServiceProvider = injector.getInstance(IResourceServiceProvider.class);
    FileExtensionProvider extensionProvider = injector.getInstance(FileExtensionProvider.class);
    for (String ext : extensionProvider.getFileExtensions()) {
        if (registry.getExtensionToFactoryMap().containsKey(ext)) {
            if (extensionProvider.getPrimaryFileExtension() == ext) {
                registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
            }
        } else {
            registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
        }

        IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(ext, resourceFactory);
    }
}
 
Example #2
Source File: ResourceServiceProviderServiceLoader.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private Registry loadRegistry() {
	ResourceServiceProviderRegistryImpl registry = new ResourceServiceProviderRegistryImpl();
	for (ISetup cp : setupLoader) {
		Injector injector = cp.createInjectorAndDoEMFRegistration();
		IResourceServiceProvider resourceServiceProvider = injector.getInstance(IResourceServiceProvider.class);
		FileExtensionProvider extensionProvider = injector.getInstance(FileExtensionProvider.class);
		String primaryFileExtension = extensionProvider.getPrimaryFileExtension();
		for (String ext : extensionProvider.getFileExtensions()) {
			if (registry.getExtensionToFactoryMap().containsKey(ext)) {
				if (primaryFileExtension.equals(ext))
					registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
			} else {
				registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
			}
		}
	}
	return registry;
}
 
Example #3
Source File: RegistryProvider.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
private void register(IResourceServiceProvider.Registry registry, Injector injector) {
    IResourceServiceProvider resourceServiceProvider = injector.getInstance(IResourceServiceProvider.class);
    FileExtensionProvider extensionProvider = injector.getInstance(FileExtensionProvider.class);
    for (String ext : extensionProvider.getFileExtensions()) {
        if (registry.getExtensionToFactoryMap().containsKey(ext)) {
            if (extensionProvider.getPrimaryFileExtension() == ext) {
                registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
            }
        } else {
            registry.getExtensionToFactoryMap().put(ext, resourceServiceProvider);
        }

        IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(ext, resourceFactory);
    }
}
 
Example #4
Source File: CheckConfigurationStoreService.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the language for the given object.
 *
 * @param context
 *          object
 * @return the language the corresponding resource was parsed from, may be {@code null}
 */
private String getLanguage(final Object context) {
  if (context instanceof EObject) {
    Resource resource = ((EObject) context).eResource();
    if (resource instanceof LazyLinkingResource) {
      return ((LazyLinkingResource) resource).getLanguageName();
    }
  } else if (context instanceof Issue && !LANGUAGE_AGNOSTIC_DIAGNOSTICS.contains(((Issue) context).getCode())) {
    URI uri = ((Issue) context).getUriToProblem();
    if (uri != null) {
      Registry registry = IResourceServiceProvider.Registry.INSTANCE;
      IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
      if (resourceServiceProvider != null) {
        return resourceServiceProvider.get(Injector.class).getInstance(Key.get(String.class, Names.named(Constants.LANGUAGE_NAME)));
      } else {
        LOGGER.error("Could not fetch a ResourceServiceProvider for URI: " + uri); //$NON-NLS-1$
      }
    } else {
      LOGGER.warn("Could not fetch eResource from issue: URI to problem is null"); //$NON-NLS-1$
    }
  }

  return null;
}
 
Example #5
Source File: CheckCfgUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the all languages available in the workbench.
 *
 * @return set of all languages
 */
public Set<String> getAllLanguages() {
  Set<String> languages = new HashSet<String>();
  for (String extension : Registry.INSTANCE.getExtensionToFactoryMap().keySet()) {
    final URI dummyUri = URI.createURI("foo:/foo." + extension);
    IResourceServiceProvider resourceServiceProvider = Registry.INSTANCE.getResourceServiceProvider(dummyUri);
    // By checking that description manager is AbstractCachingResourceDescriptionManager we exclude technical languages of the framework
    if (resourceServiceProvider != null && resourceServiceProvider.getResourceDescriptionManager() instanceof AbstractCachingResourceDescriptionManager) {
      try {
        IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
        if (grammarAccess != null && grammarAccess.getGrammar() != null) {
          languages.add(grammarAccess.getGrammar().getName());
        }
      } catch (ConfigurationException e) {
        // Will happen if no binding for IGrammarAccess was present.
      }
    }
  }
  return languages;
}
 
Example #6
Source File: ResourceServiceProviderProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testResourceServiceProviderProvider() {
	String contenttype = "mycontent";
	String ext = "TestResourceServiceProviderProvider";
	URI uri = URI.createFileURI("foofile." + ext);
	Registry registry = IResourceServiceProvider.Registry.INSTANCE;

	// the file extension is registered via plugin.xml
	IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri, contenttype);
	Assert.assertTrue(resourceServiceProvider instanceof TestResourceServiceProvider);
	TestResourceServiceProvider provider = (TestResourceServiceProvider) resourceServiceProvider;
	Assert.assertEquals(uri, provider.uri);
	Assert.assertEquals(contenttype, provider.contentType);
}
 
Example #7
Source File: RegistryProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void registerDefaultFactories() {
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
    }
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    }
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin")) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtextbin",
                new BinaryGrammarResourceFactoryImpl());
    }
    if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) {
        EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE);
    }
}
 
Example #8
Source File: RegistryProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private Registry createRegistry() {
    registerDefaultFactories();

    IResourceServiceProvider.Registry registry = new ResourceServiceProviderRegistryImpl();
    register(registry, new ItemsIdeSetup().createInjector());
    register(registry, new PersistenceIdeSetup().createInjector());
    register(registry, new RulesIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new ScriptIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new SitemapIdeSetup().createInjector());
    register(registry, new ThingIdeSetup().createInjector());
    return registry;
}
 
Example #9
Source File: RegistryProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public synchronized IResourceServiceProvider.Registry get() {
    if (registry == null) {
        registry = createRegistry();
    }
    return registry;
}
 
Example #10
Source File: RegistryProvider.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private void registerDefaultFactories() {
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
    }
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    }
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin")) {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtextbin",
                new BinaryGrammarResourceFactoryImpl());
    }
    if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) {
        EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE);
    }
}
 
Example #11
Source File: RegistryProvider.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private Registry createRegistry() {
    registerDefaultFactories();

    IResourceServiceProvider.Registry registry = new ResourceServiceProviderRegistryImpl();
    register(registry, new ItemsIdeSetup().createInjector());
    register(registry, new PersistenceIdeSetup().createInjector());
    register(registry, new RulesIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new ScriptIdeSetup().setScriptServiceUtil(scriptServiceUtil).setScriptEngine(scriptEngine)
            .createInjector());
    register(registry, new SitemapIdeSetup().createInjector());
    register(registry, new ThingIdeSetup().createInjector());
    return registry;
}
 
Example #12
Source File: RegistryProvider.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public synchronized IResourceServiceProvider.Registry get() {
    if (registry == null) {
        registry = createRegistry();
    }
    return registry;
}
 
Example #13
Source File: Validator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void validate(ResourceSet resourceSet, IResourceServiceProvider.Registry registry, Issues issues) {
	List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
	for (Resource resource : resources) {
		try {
			resource.load(null);
			IResourceServiceProvider provider = registry.getResourceServiceProvider(resource.getURI());
			if (provider != null) {
				List<Issue> result = provider.getResourceValidator().validate(resource, CheckMode.ALL, null);
				for (Issue issue : result) {
					switch (issue.getSeverity()) {
						case ERROR:
							issues.addError(issue.getMessage(), issue);
							break;
						case WARNING:
							issues.addWarning(issue.getMessage(), issue);
							break;
						case INFO:
							issues.addInfo(issue.getMessage(), issue);
							break;
						case IGNORE:
							break;
					}
				}
			}
		} catch (IOException e) {
			throw new WorkflowInterruptedException("Couldn't load resource (" + resource.getURI() + ")", e);
		}
	}
	if (isStopOnError() && issues.hasErrors()) {
		String errorMessage = toString(issues);
		throw new WorkflowInterruptedException("Validation problems: \n" + errorMessage);
	}
}
 
Example #14
Source File: TraceEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateText(EObject obj) {
	DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
	if (region == null) {
		text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
		return;
	}
	final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
	SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
	if (sourceURI == null) {
		text.setText("Could not find associated URI");
		return;
	}
	Registry registry = IResourceServiceProvider.Registry.INSTANCE;
	IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
	URI traceURI = obj.eResource().getURI();
	IStorage localStorage = getLocalStorage(serviceProvider, traceURI);

	StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
	traceProvider.setLocalStorage(localStorage);
	traceProvider.setTraceToSource(true);
	traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {
		@Override
		public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
			return trace;
		}
	});
	String newText = traceProvider.toString();
	text.setText(newText);
}
 
Example #15
Source File: ResourceServiceProviderProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testResourceServiceProviderProviderWithExecutableExtensionFactory() {
	String contenttype = "mycontent";
	String ext = "TestResourceServiceProviderExecutableExtensionFactory";
	URI uri = URI.createFileURI("foofile." + ext);
	Registry registry = IResourceServiceProvider.Registry.INSTANCE;
	
	// the file extension is registered via plugin.xml
	IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri, contenttype);
	Assert.assertTrue(resourceServiceProvider instanceof TestResourceServiceProvider);
	TestResourceServiceProvider provider = (TestResourceServiceProvider) resourceServiceProvider;
	Assert.assertEquals(uri, provider.uri);
	Assert.assertEquals(contenttype, provider.contentType);
}
 
Example #16
Source File: Validator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void validate(ResourceSet resourceSet, Registry registry, Issues issues) {
	// do nothing
}
 
Example #17
Source File: ResourceServiceProviderServiceLoader.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IResourceServiceProvider.Registry get() {
	return this.registry;
}
 
Example #18
Source File: ReferenceUpdaterDispatcher.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public ReferenceDescriptionAcceptor(IResourceServiceProvider.Registry resourceServiceProviderRegistry,
		StatusWrapper status) {
	this.resourceServiceProviderRegistry = resourceServiceProviderRegistry;
	this.status = status;
}
 
Example #19
Source File: CheckMarkerUpdateJob.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Instantiates a new marker update job in which all sources identified by given
 * set of URIs are validated.
 *
 * @param name
 *          the name of the job, must not be {@code null}
 * @param uris
 *          the set of URIs to be validated, must not be {@code null}
 */
public CheckMarkerUpdateJob(final String name, final Set<URI> uris) {
  super(name);

  this.serviceProviderRegistry = IResourceServiceProvider.Registry.INSTANCE;
  this.uris = uris;
  this.checkMode = CheckMode.ALL;
}