Search in sources :

Example 46 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-eclipse by eclipse.

the class ReferenceGrammarUiTestLanguageStandaloneSetupGenerated method register.

public void register(Injector injector) {
    if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/ui/common/tests/ReferenceGrammar")) {
        EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/ui/common/tests/ReferenceGrammar", ReferenceGrammarUiPackage.eINSTANCE);
    }
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("referencegrammaruitestlanguage", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("referencegrammaruitestlanguage", serviceProvider);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 47 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-eclipse by eclipse.

the class DefaultLinkedPositionGroupCalculator method getLinkedPositionGroup.

@Override
public Provider<LinkedPositionGroup> getLinkedPositionGroup(IRenameElementContext renameElementContext, IProgressMonitor monitor) {
    final SubMonitor progress = SubMonitor.convert(monitor, 100);
    final XtextEditor editor = (XtextEditor) renameElementContext.getTriggeringEditor();
    IProject project = projectUtil.getProject(renameElementContext.getContextResourceURI());
    if (project == null)
        throw new IllegalStateException("Could not determine project for context resource " + renameElementContext.getContextResourceURI());
    RefactoringResourceSetProvider resourceSetProvider = new CachingResourceSetProvider(DefaultLinkedPositionGroupCalculator.this.resourceSetProvider);
    ResourceSet resourceSet = resourceSetProvider.get(project);
    EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true);
    if (targetElement == null)
        throw new IllegalStateException("Target element could not be loaded");
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    IRenameStrategy.Provider strategyProvider = globalServiceProvider.findService(targetElement, IRenameStrategy.Provider.class);
    IRenameStrategy renameStrategy = null;
    try {
        renameStrategy = strategyProvider.get(targetElement, renameElementContext);
    } catch (NoSuchStrategyException exc) {
    // handle in next line
    }
    if (renameStrategy == null)
        throw new IllegalArgumentException("Cannot find a rename strategy for " + notNull(renameElementContext.getTargetElementURI()));
    String newName = renameStrategy.getOriginalName();
    IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(renameElementContext.getTargetElementURI());
    IDependentElementsCalculator dependentElementsCalculator = resourceServiceProvider.get(IDependentElementsCalculator.class);
    Iterable<URI> dependentElementURIs = dependentElementsCalculator.getDependentElementURIs(targetElement, progress.newChild(10));
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    LocalResourceRefactoringUpdateAcceptor updateAcceptor = updateAcceptorProvider.get();
    updateAcceptor.setLocalResourceURI(renameElementContext.getContextResourceURI());
    renameStrategy.createDeclarationUpdates(newName, resourceSet, updateAcceptor);
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    Map<URI, URI> original2newEObjectURI = renamedElementTracker.renameAndTrack(concat(Collections.singleton(renameElementContext.getTargetElementURI()), dependentElementURIs), newName, resourceSet, renameStrategy, progress.newChild(10));
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    ElementRenameArguments elementRenameArguments = new ElementRenameArguments(renameElementContext.getTargetElementURI(), newName, renameStrategy, original2newEObjectURI, resourceSetProvider);
    final List<IReferenceDescription> referenceDescriptions = newArrayList();
    IReferenceFinder.Acceptor referenceAcceptor = new IReferenceFinder.Acceptor() {

        @Override
        public void accept(IReferenceDescription referenceDescription) {
            referenceDescriptions.add(referenceDescription);
        }

        @Override
        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) {
            referenceDescriptions.add(new DefaultReferenceDescription(EcoreUtil2.getFragmentPathURI(source), targetURI, eReference, index, null));
        }
    };
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    referenceFinder.findReferences(targetURIConverter.fromIterable(elementRenameArguments.getRenamedElementURIs()), resourceSet.getResource(renameElementContext.getContextResourceURI(), true), referenceAcceptor, progress.newChild(10));
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    referenceUpdater.createReferenceUpdates(elementRenameArguments, referenceDescriptions, updateAcceptor, progress.newChild(60));
    final List<ReplaceEdit> textEdits = updateAcceptor.getTextEdits();
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    final IRenameStrategy renameStrategy2 = renameStrategy;
    return new Provider<LinkedPositionGroup>() {

        @Override
        public LinkedPositionGroup get() {
            LinkedPositionGroup linkedGroup = createLinkedGroupFromReplaceEdits(textEdits, editor, renameStrategy2.getOriginalName(), progress.newChild(10));
            return linkedGroup;
        }
    };
}
Also used : IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) ElementRenameArguments(org.eclipse.xtext.ui.refactoring.ElementRenameArguments) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) URI(org.eclipse.emf.common.util.URI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) EObject(org.eclipse.emf.ecore.EObject) IDependentElementsCalculator(org.eclipse.xtext.ui.refactoring.IDependentElementsCalculator) DefaultReferenceDescription(org.eclipse.xtext.resource.impl.DefaultReferenceDescription) CachingResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.CachingResourceSetProvider) NoSuchStrategyException(org.eclipse.xtext.ui.refactoring.IRenameStrategy.Provider.NoSuchStrategyException) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IRefactoringUpdateAcceptor(org.eclipse.xtext.ui.refactoring.IRefactoringUpdateAcceptor) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) SubMonitor(org.eclipse.core.runtime.SubMonitor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IProject(org.eclipse.core.resources.IProject) CachingResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.CachingResourceSetProvider) IGlobalServiceProvider(org.eclipse.xtext.resource.IGlobalServiceProvider) RefactoringResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.RefactoringResourceSetProvider) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Provider(com.google.inject.Provider) LinkedPositionGroup(org.eclipse.jface.text.link.LinkedPositionGroup) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) RefactoringResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.RefactoringResourceSetProvider) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit)

Example 48 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-eclipse by eclipse.

the class EPackageChooser method createResourceSet.

private ResourceSet createResourceSet(URI genModelUri) {
    ResourceSetImpl resourceSet;
    if (genModelUri.fileExtension().equals("xcore")) {
        IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(genModelUri);
        IStorage2UriMapper storage2UriMapper = resourceServiceProvider.get(IStorage2UriMapper.class);
        IProject project = storage2UriMapper.getStorages(genModelUri).iterator().next().getSecond();
        resourceSet = (ResourceSetImpl) resourceServiceProvider.get(IResourceSetProvider.class).get(project);
    } else {
        resourceSet = new ResourceSetImpl();
    }
    Resource ecorePackageResource = EcorePackage.eINSTANCE.eResource();
    Map<URI, Resource> uriResourceMap = Maps.newHashMap();
    uriResourceMap.put(URI.createPlatformResourceURI(PATH_TO_ECORE_ECORE, true), ecorePackageResource);
    uriResourceMap.put(URI.createPlatformPluginURI(PATH_TO_ECORE_ECORE, true), ecorePackageResource);
    resourceSet.setURIResourceMap(uriResourceMap);
    return resourceSet;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IStorage2UriMapper(org.eclipse.xtext.ui.resource.IStorage2UriMapper) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) IResourceSetProvider(org.eclipse.xtext.ui.resource.IResourceSetProvider)

Example 49 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project n4js by eclipse.

the class RegularExpressionStandaloneSetupGenerated method register.

public void register(Injector injector) {
    if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/n4js/regex/RegularExpression")) {
        EPackage.Registry.INSTANCE.put("http://www.eclipse.org/n4js/regex/RegularExpression", RegularExpressionPackage.eINSTANCE);
    }
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("regex", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("regex", serviceProvider);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 50 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project n4js by eclipse.

the class EagerResourceSetBasedResourceDescriptions method computeResourceDescription.

private IResourceDescription computeResourceDescription(URI uri) {
    Resource resource = resourceSet.getResource(uri, false);
    if (resource == null)
        return null;
    IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
    if (resourceServiceProvider == null)
        return null;
    IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
    if (manager == null)
        return null;
    return manager.getResourceDescription(resource);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource)

Aggregations

IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)267 IResourceFactory (org.eclipse.xtext.resource.IResourceFactory)190 URI (org.eclipse.emf.common.util.URI)25 Resource (org.eclipse.emf.ecore.resource.Resource)21 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)20 XtextResource (org.eclipse.xtext.resource.XtextResource)13 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)10 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)5 IResource (org.eclipse.core.resources.IResource)5 EObject (org.eclipse.emf.ecore.EObject)5 Manager (org.eclipse.xtext.resource.IResourceDescription.Manager)5 Issue (org.eclipse.xtext.validation.Issue)5 Injector (com.google.inject.Injector)4 IProject (org.eclipse.core.resources.IProject)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)4