org.eclipse.xtext.resource.IResourceServiceProvider Java Examples

The following examples show how to use org.eclipse.xtext.resource.IResourceServiceProvider. 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: XIndexer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Process the deleted resources.
 */
protected List<IResourceDescription.Delta> getDeltasForDeletedResources(XBuildRequest request,
		ResourceDescriptionsData oldIndex, XBuildContext context) {

	List<IResourceDescription.Delta> deltas = new ArrayList<>();
	for (URI deleted : request.getDeletedFiles()) {
		IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(deleted);
		if (resourceServiceProvider != null) {
			this.operationCanceledManager.checkCanceled(context.getCancelIndicator());
			IResourceDescription oldDescription = oldIndex != null ? oldIndex.getResourceDescription(deleted)
					: null;
			if (oldDescription != null) {
				DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(oldDescription, null);
				deltas.add(delta);
			}
		}
	}
	return deltas;
}
 
Example #2
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void didRefreshOpenFile(OpenFileContext ofc, CancelIndicator ci) {
	if (client instanceof LanguageClientExtensions) {

		LanguageClientExtensions clientExtensions = (LanguageClientExtensions) client;
		XtextResource resource = ofc.getResource();
		IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider();
		IColoringService coloringService = resourceServiceProvider.get(IColoringService.class);

		if (coloringService != null) {
			XDocument doc = ofc.getDocument();
			List<? extends ColoringInformation> colInfos = coloringService.getColoring(resource, doc);

			if (!IterableExtensions.isNullOrEmpty(colInfos)) {
				String uri = resource.getURI().toString();
				ColoringParams colParams = new ColoringParams(uri, colInfos);
				clientExtensions.updateColoring(colParams);
			}
		}
	}

	ILanguageServerAccess.Context ctx = new ILanguageServerAccess.Context(ofc.getResource(), ofc.getDocument(),
			true, ci);
	semanticHighlightingRegistry.update(ctx);
}
 
Example #3
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 #4
Source File: GlobalRegistries.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static GlobalStateMemento makeCopyOfGlobalState() {
	GlobalStateMemento memento = new GlobalStateMemento();
	memento.validatorReg = new HashMap<EPackage, Object>(EValidator.Registry.INSTANCE);
	for(Map.Entry<EPackage, Object> validatorEntry: memento.validatorReg.entrySet()) {
		Object existingValue = validatorEntry.getValue();
		if (existingValue instanceof CompositeEValidator) {
			validatorEntry.setValue(((CompositeEValidator) existingValue).getCopyAndClearContents());
		}
	}
	memento.epackageReg = new HashMap<String, Object>(EPackage.Registry.INSTANCE);
	memento.protocolToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
	memento.extensionToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
	memento.contentTypeIdentifierToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());

	memento.protocolToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getProtocolToFactoryMap());
	memento.extensionToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap());
	memento.contentTypeIdentifierToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getContentTypeToFactoryMap());
	
	memento.annotationValidatorMap = new HashMap<>(getAnnotationValidatorMap());
	return memento;
}
 
Example #5
Source File: N4JSStandaloneSetupGenerated.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4js", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4js", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsx", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsx", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("js", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("js", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("jsx", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("jsx", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsd", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsd", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4idl", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4idl", serviceProvider);
}
 
Example #6
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Compute the code action commands. Executed in a read request.
 * @since 2.20
 */
protected List<Either<Command, CodeAction>> codeAction(CodeActionParams params, CancelIndicator cancelIndicator) {
	URI uri = getURI(params.getTextDocument());
	IResourceServiceProvider serviceProvider = getResourceServiceProvider(uri);
	ICodeActionService2 service2 = getService(serviceProvider, ICodeActionService2.class);
	if (service2 == null) {
		return Collections.emptyList();
	}
	return workspaceManager.doRead(uri, (doc, resource) -> {
		List<Either<Command, CodeAction>> result = new ArrayList<>();
		if (service2 != null) {
			ICodeActionService2.Options options = new ICodeActionService2.Options();
			options.setDocument(doc);
			options.setResource(resource);
			options.setLanguageServerAccess(access);
			options.setCodeActionParams(params);
			options.setCancelIndicator(cancelIndicator);
			List<Either<Command, CodeAction>> actions = service2.getCodeActions(options);
			if (actions != null) {
				result.addAll(actions);
			}
		}
		return result;
	});
}
 
Example #7
Source File: OwnResourceValidatorAwareValidatingEditorCallback.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private ValidationJob newValidationJob(final XtextEditor editor) {

		final IXtextDocument document = editor.getDocument();
		final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();

		final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
		final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
		final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);

		final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(
				new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider),
				new MarkerIssueProcessor(editor.getResource(), annotationModel, markerCreator, markerTypeProvider));

		return editor.getDocument().modify(resource -> {
			final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
			final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
			return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
		});
	}
 
Example #8
Source File: ResourceSetBasedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(URI uri) {
	if (data != null) {
		return data.getResourceDescription(uri);
	}
	Resource resource = resourceSet.getResource(uri, false);
	if (resource == null)
		return null;
	IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
	if (resourceServiceProvider == null)
		return null;
	Manager manager = resourceServiceProvider.getResourceDescriptionManager();
	if (manager == null)
		return null;
	return manager.getResourceDescription(resource);
}
 
Example #9
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 #10
Source File: XIndexer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Index the given resource.
 *
 * @param isPreIndexing
 *            can be evaluated to produce different index entries depending on the phase
 */
protected IResourceDescription.Delta addToIndex(Resource resource, boolean isPreIndexing,
		ResourceDescriptionsData oldIndex, XBuildContext context) {
	this.operationCanceledManager.checkCanceled(context.getCancelIndicator());
	if (context.getResourceSet() != resource.getResourceSet()) {
		// we are seeing an out-of-sequence resource - don't index it
		return null;
	}
	URI uri = resource.getURI();
	IResourceServiceProvider serviceProvider = context.getResourceServiceProvider(uri);
	IResourceDescription.Manager manager = serviceProvider.getResourceDescriptionManager();
	IResourceDescription newDescription = manager.getResourceDescription(resource);
	IResourceDescription toBeAdded = new XIndexer.XResolvedResourceDescription(newDescription);
	IResourceDescription.Delta delta = manager
			.createDelta(oldIndex != null ? oldIndex.getResourceDescription(uri) : null, toBeAdded);
	return delta;
}
 
Example #11
Source File: MultiGenMMTestLanguageStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("multigenmmtestlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("multigenmmtestlanguage", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://eclipse.org/xtext/tests/SimpleTest")) {
		EPackage.Registry.INSTANCE.put("http://eclipse.org/xtext/tests/SimpleTest", SimpleTestPackage.eINSTANCE);
	}
	if (!EPackage.Registry.INSTANCE.containsKey("http://eclipse.org/xtext/tests/OtherTest")) {
		EPackage.Registry.INSTANCE.put("http://eclipse.org/xtext/tests/OtherTest", OtherTestPackage.eINSTANCE);
	}
}
 
Example #12
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 #13
Source File: XbaseWithAnnotationsStandaloneSetupGenerated.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("___xbasewithannotations", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("___xbasewithannotations", serviceProvider);
}
 
Example #14
Source File: ScriptImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(final IEvaluationContext evaluationContext) throws ScriptExecutionException {
    if (xExpression != null) {
        Resource resource = xExpression.eResource();
        IExpressionInterpreter interpreter = null;
        if (resource instanceof XtextResource) {
            IResourceServiceProvider provider = ((XtextResource) resource).getResourceServiceProvider();
            interpreter = provider.get(IExpressionInterpreter.class);
        }
        if (interpreter == null) {
            throw new ScriptExecutionException("Script interpreter couldn't be obtain");
        }
        try {
            IEvaluationResult result = interpreter.evaluate(xExpression, evaluationContext,
                    CancelIndicator.NullImpl);
            if (result == null) {
                // this can only happen on an InterpreterCancelledException,
                // i.e. NEVER ;-)
                return null;
            }
            if (result.getException() != null) {
                throw new ScriptExecutionException(result.getException().getMessage(), result.getException());
            }
            return result.getResult();
        } catch (Throwable e) {
            if (e instanceof ScriptExecutionException) {
                throw (ScriptExecutionException) e;
            } else {
                throw new ScriptExecutionException(
                        "An error occurred during the script execution: " + e.getMessage(), e);
            }
        }
    } else {
        throw new ScriptExecutionException("Script does not contain any expression");
    }
}
 
Example #15
Source File: Ecore2XtextTestStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore2xtexttest", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore2xtexttest", serviceProvider);
}
 
Example #16
Source File: MarkerUpdaterImpl.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IMarkerContributor getMarkerContributor(URI uri) {
	IResourceServiceProvider provider = resourceServiceProviderRegistry.getResourceServiceProvider(uri);
	if (provider != null) {
		return provider.get(IMarkerContributor.class);
	}
	return null;
}
 
Example #17
Source File: Bug289515TestLanguageStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug289515testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug289515testlanguage", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://eclipse.org/xtext/Bug289515TestLanguage")) {
		EPackage.Registry.INSTANCE.put("http://eclipse.org/xtext/Bug289515TestLanguage", Bug289515TestPackage.eINSTANCE);
	}
}
 
Example #18
Source File: RefactoringTestLanguage2StandaloneSetupGenerated.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("typesRefactoring2", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("typesRefactoring2", serviceProvider);
}
 
Example #19
Source File: UnorderedGroupsTestLanguageStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/ui/tests/2010/UnorderedGroupsTest")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/ui/tests/2010/UnorderedGroupsTest", UnorderedGroupsTestPackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("unorderedgroupstestlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("unorderedgroupstestlanguage", serviceProvider);
}
 
Example #20
Source File: JavaSearchHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void search(URI uri, IProgressMonitor monitor) {
	int numResources = Iterables.size(resourceDescriptions.getAllResourceDescriptions());
	SubMonitor subMonitor = SubMonitor.convert(monitor, numResources / 10);
	subMonitor.subTask("Find references in EMF resources");
	try {
		int i = 0;
		for (IResourceDescription resourceDescription : resourceDescriptions.getAllResourceDescriptions()) {
			URI resourceURI = resourceDescription.getURI();
			IResourceServiceProvider resourceServiceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceURI);
			if(resourceServiceProvider != null) {
				IJavaSearchParticipation javaSearchParticipation = resourceServiceProvider
						.get(IJavaSearchParticipation.class);
				if(javaSearchParticipation == null || javaSearchParticipation.canContainJvmReferences(resourceURI))
					searchIn(uri, resourceDescription);
			}
			if (++i % 10 == 0) {
				if (subMonitor.isCanceled()) {
					return; // not throwing OperationCanceledException, as the client in JDT doesn't seem to handle it properly
				}
				subMonitor.worked(1);
			}
		}
		for(ResourceSet resourceSet: projectToResourceSet.values()) {
			resourceSet.getResources().clear();
			resourceSet.eAdapters().clear();
		}
	} finally {
		subMonitor.done();
	}
}
 
Example #21
Source File: GH341TestLanguageStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/ui/common/tests/2012/gh341TestLanguage")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/ui/common/tests/2012/gh341TestLanguage", Gh341TestLanguagePackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("gh341testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("gh341testlanguage", serviceProvider);
}
 
Example #22
Source File: Bug362902StandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug362902", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug362902", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.xtext.org/linking/Bug362902")) {
		EPackage.Registry.INSTANCE.put("http://www.xtext.org/linking/Bug362902", Bug362902Package.eINSTANCE);
	}
}
 
Example #23
Source File: SerializationBug269362TestLanguageStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("serializationbug269362testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("serializationbug269362testlanguage", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2009/tmf/xtext/SerializationBugTest/269362")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2009/tmf/xtext/SerializationBugTest/269362", SerializationBug269362TestLanguagePackage.eINSTANCE);
	}
}
 
Example #24
Source File: Bug291022TestLanguageStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/ui/common/tests/2009/bug291022TestLanguage")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/ui/common/tests/2009/bug291022TestLanguage", Bug291022TestLanguagePackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug291022testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug291022testlanguage", serviceProvider);
}
 
Example #25
Source File: XtextServlet.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Resolve the Guice injector for the language associated with the given
 * context.
 */
protected Injector getInjector(HttpServiceContext serviceContext)
		throws InvalidRequestException.UnknownLanguageException {
	IResourceServiceProvider resourceServiceProvider = null;
	String parameter = serviceContext.getParameter("resource");
	if (parameter == null) {
		parameter = "";
	}
	URI emfURI = URI.createURI(parameter);
	String contentType = serviceContext.getParameter("contentType");
	if (Strings.isNullOrEmpty(contentType)) {
		resourceServiceProvider = serviceProviderRegistry.getResourceServiceProvider(emfURI);
		if (resourceServiceProvider == null) {
			if (emfURI.toString().isEmpty()) {
				throw new InvalidRequestException.UnknownLanguageException(
						"Unable to identify the Xtext language: missing parameter 'resource' or 'contentType'.");
			} else {
				throw new InvalidRequestException.UnknownLanguageException(
						"Unable to identify the Xtext language for resource " + emfURI + ".");
			}
		}
	} else {
		resourceServiceProvider = serviceProviderRegistry.getResourceServiceProvider(emfURI, contentType);
		if (resourceServiceProvider == null) {
			throw new InvalidRequestException.UnknownLanguageException(
					"Unable to identify the Xtext language for contentType " + contentType + ".");
		}
	}
	return resourceServiceProvider.get(Injector.class);
}
 
Example #26
Source File: XtextStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtext", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xtext", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtext2", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xtext2", serviceProvider);
}
 
Example #27
Source File: SubTestLanguageStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("subtestlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("subtestlanguage", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2009/tmf/xtext/SubTestLanguage")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2009/tmf/xtext/SubTestLanguage", SubPackagePackage.eINSTANCE);
	}
}
 
Example #28
Source File: EncodingUiTestLanguageStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2010/tmf/xtext/parser/EncodingUiTest")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2010/tmf/xtext/parser/EncodingUiTest", EncodingTestPackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("encodinguitestlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("encodinguitestlanguage", serviceProvider);
}
 
Example #29
Source File: OpenFileContext.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public List<Issue> validateOpenFile(CancelIndicator cancelIndicator) {
	// validate
	IResourceServiceProvider resourceServiceProvider = languagesRegistry.getResourceServiceProvider(mainURI);
	IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator();
	List<Issue> issues = resourceValidator.validate(mainResource, CheckMode.ALL, cancelIndicator);
	operationCanceledManager.checkCanceled(cancelIndicator); // #validate() sometimes returns null when canceled!
	// notify LSP client
	publishIssues(issues, cancelIndicator);
	return issues;
}
 
Example #30
Source File: OpenFileContext.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
protected IResourceDescription.Manager getResourceDescriptionManager(URI uri) {
	IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry
			.getResourceServiceProvider(uri);
	if (resourceServiceProvider == null) {
		return null;
	}
	return resourceServiceProvider.getResourceDescriptionManager();
}