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;
}
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()));
}
}
}
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);
}
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);
}
}
}
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;
}
Aggregations