mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[findReferences] Added new API to look up references for the object
scope and all reference for the resource and object scopes Change-Id: I6ca72af424d72658ce56cad8ebcf8c366a57a87b Signed-off-by: akosyakov <anton.kosyakov@typefox.io>
This commit is contained in:
parent
6ec65c43f4
commit
f1cd5f07d7
3 changed files with 140 additions and 4 deletions
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) 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.findReferences
|
||||
|
||||
import com.google.common.collect.Iterators
|
||||
import com.google.inject.Singleton
|
||||
import org.eclipse.emf.common.util.URI
|
||||
|
||||
/**
|
||||
* It is used to look up all references for a resource or object scope.
|
||||
*
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
@Singleton
|
||||
package class AnyTargetURISet implements TargetURIs {
|
||||
|
||||
override addAllURIs(Iterable<URI> uris) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override addURI(URI uri) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override asSet() {
|
||||
emptySet
|
||||
}
|
||||
|
||||
override contains(URI uri) {
|
||||
true
|
||||
}
|
||||
|
||||
override containsResource(URI resourceURI) {
|
||||
true
|
||||
}
|
||||
|
||||
override getEObjectURIs(URI resourceURI) {
|
||||
emptySet
|
||||
}
|
||||
|
||||
override getTargetResourceURIs() {
|
||||
emptySet
|
||||
}
|
||||
|
||||
override <T> getUserData(Key<T> key) {
|
||||
null
|
||||
}
|
||||
|
||||
override isEmpty() {
|
||||
true
|
||||
}
|
||||
|
||||
override <T> putUserData(Key<T> key, T data) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override size() {
|
||||
0
|
||||
}
|
||||
|
||||
override iterator() {
|
||||
Iterators.emptyIterator
|
||||
}
|
||||
|
||||
}
|
|
@ -122,6 +122,53 @@ public interface IReferenceFinder {
|
|||
Acceptor acceptor,
|
||||
IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* Finds all references from the given source resource.
|
||||
*
|
||||
* @param scope
|
||||
* the search scope for the resources containing the sources of the references.
|
||||
* @param acceptor
|
||||
* accepts the matches.
|
||||
* @param monitor
|
||||
* the progress monitor. Can be null.
|
||||
*/
|
||||
void findAllReferences(
|
||||
Resource scope,
|
||||
Acceptor acceptor,
|
||||
IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* Finds the references from the given source object to the given <code>targetURIs</code>.
|
||||
*
|
||||
* @param targetURIs
|
||||
* the URIs of the target elements of the references. Should be normalized.
|
||||
* @param scope
|
||||
* the search scope for the object containing the sources of the references.
|
||||
* @param acceptor
|
||||
* accepts the matches.
|
||||
* @param monitor
|
||||
* the progress monitor. Can be null.
|
||||
*/
|
||||
void findReferences(
|
||||
TargetURIs targetURIs,
|
||||
EObject scope,
|
||||
Acceptor acceptor,
|
||||
IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* Finds all references from the given source object.
|
||||
*
|
||||
* @param scope
|
||||
* the search scope for the object containing the sources of the references.
|
||||
* @param acceptor
|
||||
* accepts the matches.
|
||||
* @param monitor
|
||||
* the progress monitor. Can be null.
|
||||
*/
|
||||
void findAllReferences(
|
||||
EObject scope,
|
||||
Acceptor acceptor,
|
||||
IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* Finds all references to the given <code>targetURIs</code>.
|
||||
|
|
|
@ -38,6 +38,9 @@ import com.google.inject.Singleton;
|
|||
*/
|
||||
@Singleton
|
||||
public class ReferenceFinder implements IReferenceFinder {
|
||||
|
||||
@Inject
|
||||
private AnyTargetURISet anyTargetURISet;
|
||||
|
||||
@Inject
|
||||
private IResourceServiceProvider.Registry serviceProviderRegistry;
|
||||
|
@ -113,16 +116,31 @@ public class ReferenceFinder implements IReferenceFinder {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findAllReferences(Resource scope, Acceptor acceptor, IProgressMonitor monitor) {
|
||||
findReferences(anyTargetURISet, scope, acceptor, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findReferences(TargetURIs targetURIs, Resource resource, Acceptor acceptor, IProgressMonitor monitor) {
|
||||
for (EObject content : resource.getContents()) {
|
||||
if (monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
findLocalReferencesFromElement(targetURIs, content, resource, acceptor);
|
||||
findReferences(targetURIs, content, acceptor, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findAllReferences(EObject scope, Acceptor acceptor, IProgressMonitor monitor) {
|
||||
findReferences(anyTargetURISet, scope, acceptor, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findReferences(TargetURIs targetURIs, EObject scope, Acceptor acceptor, IProgressMonitor monitor) {
|
||||
if (monitor != null && monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
findLocalReferencesFromElement(targetURIs, scope, scope.eResource(), acceptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findReferences(final TargetURIs targetURIs, IResourceDescription resourceDescription,
|
||||
IResourceAccess resourceAccess, final Acceptor acceptor, final IProgressMonitor monitor) {
|
||||
|
|
Loading…
Reference in a new issue