Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.findrefs;
  
 import static com.google.common.collect.Iterables.*;
 import static com.google.common.collect.Maps.*;
 
 import java.util.Map;
 import java.util.Set;
 
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.core.runtime.OperationCanceledException;
 import  org.eclipse.core.runtime.SubMonitor;
 
Maintained for backwards compatibility reasons. Most methods delegate to the runtime implementation which in turn is specialized to call methods of this class where appropriate. Most overriding scenarios should still work. Clients are encouraged to drop this implementation in favor of the DelegatingReferenceFinder. Customizing should be applied to the ReferenceFinder instead.

Deprecated:
use DelegatingReferenceFinder instead.
Author(s):
Jan Koehnlein - Initial contribution and API
Since:
2.3
 
 
 
 	
 			IResourceServiceProvider.Registry serviceProviderRegistry) {
 		this(indexDataserviceProviderRegistrynew TargetURIConverter());
 	}
 	
 			IResourceServiceProvider.Registry serviceProviderRegistry
 			TargetURIConverter converter) {
 		super(serviceProviderRegistry);
 		this. = indexData;
 		this. = converter;
 	}
 	
 		return ;
 	}
 	
 	protected static class MyReferenceAcceptor extends ReferenceAcceptor implements IAcceptor<IReferenceDescription> {
 
 		protected MyReferenceAcceptor(IAcceptor<IReferenceDescriptiondelegateIResourceServiceProvider.Registry serviceProviderRegistry) {
 			super(delegateserviceProviderRegistry);
 		}
 	}
 	
 		if (acceptor instanceof MyReferenceAcceptor)
 			return (MyReferenceAcceptoracceptor;
 		return new MyReferenceAcceptor(acceptorgetServiceProviderRegistry());
 	}
 	
 	@SuppressWarnings("unchecked")
 	public void findReferences(TargetURIs targetURIsIResourceDescription resourceDescription,
 			IResourceAccess resourceAccessAcceptor acceptor, IProgressMonitor monitor) {
 		findReferences(targetURIs.asSet(), resourceDescription, (IAcceptor<IReferenceDescription>) acceptormonitor, (ILocalResourceAccessresourceAccess);
 	}
 	
	@SuppressWarnings("unchecked")
	public void findReferences(TargetURIs targetURIsResource resourceAcceptor acceptor, IProgressMonitor monitor) {
		findLocalReferencesInResource(targetURIs.asSet(), resource, (IAcceptor<IReferenceDescription>) acceptor);
	}
		// bogus old implementation did not dispatch properly for all candidates
		return this;
	}
	public void findReferences(Iterable<URItargetURIsfinal Iterable<URIsourceResourceURIs,
			ILocalResourceAccess localResourceAccessIAcceptor<IReferenceDescriptionreferenceAcceptor,
			IProgressMonitor monitor) {
		TargetURIs converted = .fromIterable(targetURIs);
		HashSet<URIsourceResourcesAsSet = Sets.newHashSet(sourceResourceURIs);
		super.findReferences(convertedsourceResourcesAsSetlocalResourceAccesstoAcceptor(referenceAcceptor), monitor);
		if (localResourceAccess != null && !converted.isEmpty() && getClass() != DefaultReferenceFinder.class) {
			// All the references have already been collected, but if this method was overridden,
			// we have to call it again from here
			findLocalReferences(convertedlocalResourceAccessreferenceAcceptormonitor);
		}
	}
	public void findAllReferences(
			Iterable<URItargetURIs,
			ILocalResourceAccess localResourceAccess,
			IAcceptor<IReferenceDescriptionreferenceAcceptor,
			IProgressMonitor monitor) {
		TargetURIs converted = .fromIterable(targetURIs);
		if (!converted.isEmpty()) {
			findAllIndexedReferences(referenceAcceptor, SubMonitor.convert(monitor, 1), converted.asSet(), localResourceAccess);
			if (localResourceAccess != null && !converted.isEmpty() && getClass() != DefaultReferenceFinder.class) {
				// All the references have already been collected, but if this method was overridden,
				// we have to call it again from here
				findLocalReferences(convertedlocalResourceAccessreferenceAcceptormonitor);
			}
		}
	}

Deprecated:
use findAllIndexedReferences(IAcceptor, SubMonitor, Set, org.eclipse.xtext.ui.editor.findrefs.IReferenceFinder.ILocalResourceAccess)
	protected void findAllIndexedReferences(IAcceptor<IReferenceDescriptionreferenceAcceptor, SubMonitor subMonitor,
			Set<URItargetURIsAsSet) {
		findAllIndexedReferences(referenceAcceptorsubMonitortargetURIsAsSetnull);
	}

Since:
2.4
	protected void findAllIndexedReferences(
			IAcceptor<IReferenceDescriptionreferenceAcceptor,
			SubMonitor subMonitor,
			Set<URItargetURIsAsSet,
			ILocalResourceAccess localResourceAccess) {
		TargetURIs targetURIs = .fromIterable(targetURIsAsSet);
		if (!targetURIs.isEmpty()) {
			subMonitor.setWorkRemaining(size(.getAllResourceDescriptions()) /  + 1);
			int i = 0;
			IProgressMonitor useMe = subMonitor.newChild(1);
			for (IResourceDescription resourceDescription : .getAllResourceDescriptions()) {
				if (serviceProvider != null) {
					IReferenceFinder referenceFinder = serviceProvider.get(IReferenceFinder.class);
					if (referenceFinder instanceof IReferenceFinderExtension1) {
						IReferenceFinderExtension1 extension1 = (IReferenceFinderExtension1referenceFinder;
						extension1.findReferences(targetURIsAsSetresourceDescriptionreferenceAcceptoruseMelocalResourceAccess);
else {
						// don't use the language specific reference finder here for backwards compatibility reasons
						findReferences(targetURIsAsSetresourceDescriptionreferenceAcceptoruseMelocalResourceAccess);
					}
				}
				i++;
				if (i %  == 0) {
					useMe = subMonitor.newChild(1);
				}
			}
		}
	}
	private static final int MONITOR_FIND_LOCAL_CHUNK_SIZE = 10;
	protected void findLocalReferences(
			Iterable<URIlocalTargets,
			ILocalResourceAccess localResourceAccess,
			IProgressMonitor monitor) {
		if ((monitor != null && monitor.isCanceled()))
			throw new OperationCanceledException();
		final TargetURIs targetURIs = .fromIterable(localTargets);
		Collection<URIresourceURIs = targetURIs.getTargetResourceURIs();
		final SubMonitor subMonitor = SubMonitor.convert(monitorresourceURIs.size() /  + 1);
		int i = 0;
		for(final URI resourceURIresourceURIs) {
			if (subMonitor.isCanceled())
				throw new OperationCanceledException();
			localResourceAccess.readOnly(resourceURInew IUnitOfWork.Void<ResourceSet>() {
				public void process(ResourceSet resourceSetthrows Exception {
					Resource resource = resourceSet.getResource(resourceURItrue);
					DefaultReferenceFinder.super.findReferences(targetURIsresourcetoAcceptor(acceptor), subMonitor);
				}
			});
			i++;
				subMonitor.worked(1);
		}
	}
	protected void findLocalReferencesInResource(final Iterable<URItargetURIsResource resource,
			final IAcceptor<IReferenceDescriptionacceptor) {
		Map<EObjectURIexportedElementsMap = createExportedElementsMap(resource);
		Set<URIconverted = .fromIterable(targetURIs).asSet();
		for(EObject contentresource.getContents()) {
			findLocalReferencesFromElement(convertedcontentresourceacceptornullexportedElementsMap);
		}
	}
			final Set<URItargetURISet
			EObject sourceCandidate,
			Resource localResource,
			final IAcceptor<IReferenceDescriptionacceptor
			URI currentExportedContainerURI
			Map<EObjectURIexportedElementsMap) {
		super.findLocalReferencesFromElement(.fromIterable(targetURISet), sourceCandidatelocalResourcetoAcceptor(acceptor));
	}
	protected Map<EObjectURIcreateExportedElementsMap(final Resource resource) {
		return new ForwardingMap<EObjectURI>() {
			private Map<EObjectURIdelegate;
			protected Map<EObjectURIdelegate() {
				if ( != null) {
					return ;
				}
				URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(resource);
				if (resourceServiceProvider == null) {
					return  = Collections.emptyMap();
				}
				IResourceDescription.Manager resourceDescriptionManager = resourceServiceProvider.getResourceDescriptionManager();
				if (resourceDescriptionManager == null) {
					return  = Collections.emptyMap();
				}
				IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);
				Map<EObjectURIexportedElementMap = newIdentityHashMap();
				if (resourceDescription != null) {
					for (IEObjectDescription exportedEObjectDescription : resourceDescription.getExportedObjects()) {
						EObject eObject = resource.getEObject(exportedEObjectDescription.getEObjectURI().fragment());
						if (eObject != null)
							exportedElementMap.put(eObjectexportedEObjectDescription.getEObjectURI());
					}
				}
				return  = exportedElementMap;
			}
		};
	}

Deprecated:
no longer used
	protected URI findClosestExportedContainerURI(EObject elementMap<EObjectURIexportedElementsMap) {
		EObject current = element;
		while (current != null) {
			URI uri = exportedElementsMap.get(current);
			if (uri != null)
				return uri;
			current = current.eContainer();
		}
		return null;
	}

Deprecated:
use findReferences(Set, IResourceDescription, IAcceptor, IProgressMonitor, org.eclipse.xtext.ui.editor.findrefs.IReferenceFinder.ILocalResourceAccess)
	protected void findIndexedReferences(Set<URItargetURIsIResourceDescription resourceDescriptionIAcceptor<IReferenceDescriptionacceptor, IProgressMonitor monitor) {
		findReferences(targetURIsresourceDescriptionacceptormonitornull);
	}

Since:
2.4
	public void findReferences(Set<URItargetURIsIResourceDescription resourceDescriptionIAcceptor<IReferenceDescriptionacceptor, IProgressMonitor monitorILocalResourceAccess localResourceAccess) {
		super.findReferences(.fromIterable(targetURIs), resourceDescriptionlocalResourceAccesstoAcceptor(acceptor), monitor);
	}
New to GrepCode? Check out our FAQ X