Search in sources :

Example 21 with IReferenceDescription

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

the class AbstractReferenceUpdater method resolveReferenceProxies.

protected List<IReferenceDescription> resolveReferenceProxies(ResourceSet resourceSet, Collection<IReferenceDescription> values, StatusWrapper status, IProgressMonitor monitor) {
    List<IReferenceDescription> unresolvedDescriptions = null;
    for (IReferenceDescription referenceDescription : values) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        EObject sourceEObject = resourceSet.getEObject(referenceDescription.getSourceEObjectUri(), true);
        if (sourceEObject == null) {
            handleCannotLoadReferringElement(referenceDescription, status);
        } else {
            // this should not be necessary. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=385408
            if (sourceEObject.eIsProxy()) {
                sourceEObject = EcoreUtil.resolve(sourceEObject, sourceEObject.eResource());
                if (sourceEObject.eIsProxy()) {
                    handleCannotLoadReferringElement(referenceDescription, status);
                }
            }
            EObject resolvedReference = resolveReference(sourceEObject, referenceDescription);
            if (resolvedReference == null || resolvedReference.eIsProxy())
                handleCannotResolveExistingReference(sourceEObject, referenceDescription, status);
            else
                continue;
        }
        if (unresolvedDescriptions == null)
            unresolvedDescriptions = newArrayList();
        unresolvedDescriptions.add(referenceDescription);
    }
    return (unresolvedDescriptions == null) ? Collections.<IReferenceDescription>emptyList() : unresolvedDescriptions;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) EObject(org.eclipse.emf.ecore.EObject) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 22 with IReferenceDescription

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

the class AbstractReferenceUpdater method createClusteredReferenceUpdates.

protected void createClusteredReferenceUpdates(ElementRenameArguments elementRenameArguments, Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet, IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, resource2references.keySet().size() + 1);
    if (loadTargetResources(resourceSet, elementRenameArguments, status, progress.newChild(1))) {
        if (getClusterSize() > 0) {
            Set<Resource> targetResources = newHashSet(resourceSet.getResources());
            Multimap<URI, IReferenceDescription> cluster = HashMultimap.create();
            SubMonitor clusterMonitor = progress.newChild(1);
            for (URI referringResourceURI : resource2references.keySet()) {
                cluster.putAll(referringResourceURI, resource2references.get(referringResourceURI));
                if (cluster.keySet().size() == getClusterSize()) {
                    unloadNonTargetResources(resourceSet, targetResources);
                    createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor, status, clusterMonitor);
                    cluster.clear();
                }
            }
            if (!cluster.isEmpty()) {
                unloadNonTargetResources(resourceSet, targetResources);
                createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor, status, clusterMonitor);
            }
        } else {
            createReferenceUpdatesForCluster(elementRenameArguments, resource2references, resourceSet, updateAcceptor, status, progress.newChild(resource2references.keySet().size()));
        }
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 23 with IReferenceDescription

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

the class AbstractReferenceUpdater method createReferenceUpdatesForCluster.

protected void createReferenceUpdatesForCluster(ElementRenameArguments elementRenameArguments, Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet, IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    List<URI> unloadableResources = loadReferringResources(resourceSet, resource2references.keySet(), status, progress.newChild(10));
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    for (URI unloadableResouce : unloadableResources) resource2references.removeAll(unloadableResouce);
    List<IReferenceDescription> unresolvableReferences = resolveReferenceProxies(resourceSet, resource2references.values(), status, progress.newChild(70));
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    for (IReferenceDescription unresolvableReference : unresolvableReferences) {
        URI unresolvableReferringResource = unresolvableReference.getSourceEObjectUri().trimFragment();
        resource2references.remove(unresolvableReferringResource, unresolvableReference);
    }
    elementRenameArguments.getRenameStrategy().applyDeclarationChange(elementRenameArguments.getNewName(), resourceSet);
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    createReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor, progress.newChild(20));
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    elementRenameArguments.getRenameStrategy().revertDeclarationChange(resourceSet);
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 24 with IReferenceDescription

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

the class NavigationService method open.

public void open(INavigatable navigatable, boolean select) {
    if (navigatable != null) {
        Object navigatableElement = navigatable.getNavigationElement();
        if (navigatableElement instanceof IReferenceDescription) {
            IReferenceDescription referenceDescription = (IReferenceDescription) navigatableElement;
            // 
            uriEditorOpener.open(// 
            referenceDescription.getSourceEObjectUri(), // 
            referenceDescription.getEReference(), // 
            referenceDescription.getIndexInList(), select);
        } else if (navigatableElement instanceof IEObjectDescription) {
            uriEditorOpener.open(((IEObjectDescription) navigatableElement).getEObjectURI(), select);
        } else if (navigatableElement instanceof IResourceDescription) {
            uriEditorOpener.open(((IResourceDescription) navigatableElement).getURI(), select);
        } else if (navigatableElement instanceof INavigatable) {
            open((INavigatable) navigatableElement, select);
        }
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) INavigatable(org.eclipse.xtext.ide.editor.navigation.INavigatable) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 25 with IReferenceDescription

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

the class HeadlessReferenceFinder method findReferencesTo.

/**
 * Find all references to the given target with its resource set as working environment.
 *
 * @param target
 *            the object to look for.
 * @param monitor
 *            the progress monitor.
 * @return the list of reference descriptions.
 */
public List<IReferenceDescription> findReferencesTo(EObject target, IProgressMonitor monitor) {
    final TargetURIs targetURIs = getTargetURIs(target);
    final ResourceSet resourceSet = target.eResource().getResourceSet();
    final List<IReferenceDescription> result = Lists.newArrayList();
    IReferenceFinder.IResourceAccess resourceAccess = new SimpleResourceAccess(resourceSet);
    IReferenceFinder.Acceptor acceptor = new IReferenceFinder.Acceptor() {

        @Override
        public void accept(IReferenceDescription description) {
            result.add(description);
        }

        @Override
        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) {
            accept(new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, null));
        }
    };
    referenceFinder.findAllReferences(targetURIs, resourceAccess, resourceDescriptionsProvider.getResourceDescriptions(resourceSet), acceptor, monitor);
    return result;
}
Also used : TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) SimpleResourceAccess(org.eclipse.n4js.ts.findReferences.SimpleResourceAccess) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) EObject(org.eclipse.emf.ecore.EObject) DefaultReferenceDescription(org.eclipse.xtext.resource.impl.DefaultReferenceDescription) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Aggregations

IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)42 URI (org.eclipse.emf.common.util.URI)18 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)17 EObject (org.eclipse.emf.ecore.EObject)12 Test (org.junit.Test)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)7 EReference (org.eclipse.emf.ecore.EReference)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 EClass (org.eclipse.emf.ecore.EClass)3 EPackage (org.eclipse.emf.ecore.EPackage)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 Main (org.eclipse.xtext.linking.langATestLanguage.Main)3