use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.
the class DirtyStateAwareResourceDescriptions2 method findReferencesToObjects.
/**
* {@inheritDoc}
*/
public Iterable<IReferenceDescription> findReferencesToObjects(final Set<URI> targetObjects) {
final Set<URI> dirtyReferencingUris = Sets.newHashSet();
Iterable<IReferenceDescription> dirtyReferences = Collections.emptyList();
for (URI dirtyURI : dirtyResources) {
IResourceDescription desc = dirtyStateManager.getDirtyResourceDescription(dirtyURI);
if (desc == null) {
continue;
}
Iterable<IReferenceDescription> local = Iterables.filter(desc.getReferenceDescriptions(), new Predicate<IReferenceDescription>() {
public boolean apply(final IReferenceDescription input) {
return targetObjects.contains(input.getTargetEObjectUri());
}
});
if (!Iterables.isEmpty(local)) {
dirtyReferences = Iterables.concat(dirtyReferences, local);
dirtyReferencingUris.add(desc.getURI());
}
}
return Iterables.concat(dirtyReferences, Iterables.filter(globalDescriptions.findReferencesToObjects(targetObjects), new Predicate<IReferenceDescription>() {
public boolean apply(final IReferenceDescription input) {
return !dirtyReferencingUris.contains(input.getSourceEObjectUri().trimQuery().trimFragment());
}
}));
}
use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.
the class FastReferenceSearchResultContentProvider method inputChanged.
@Override
public void inputChanged(final Viewer v, final Object oldInput, final Object newInput) {
synchronized (v) {
rootNodes.clear();
if (oldInput instanceof ReferenceSearchResult) {
((ReferenceSearchResult) oldInput).removeListener(this);
}
if (newInput instanceof ReferenceSearchResult && v instanceof TreeViewer) {
((ReferenceSearchResult) newInput).addListener(this);
this.viewer = (TreeViewer) v;
for (IReferenceDescription referenceDescription : ((ReferenceSearchResult) newInput).getMatchingReferences()) {
addReference(referenceDescription);
}
}
}
}
use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.
the class ReferenceFinder2 method findAllIndexedReferences.
/**
* Uses IResourceDescriptions2 to find all indexed references.
*
* @param targetURIs
* the URIs to find references to, must not be {@code null}
* @param indexData
* index to use when finding references, must not be {@code null}
* @param referenceAcceptor
* the reference acceptor, must not be {@code null}
* @param subMonitor
* the progress monitor, can be {@code null}
*/
protected void findAllIndexedReferences(final TargetURIs targetURIs, final IResourceDescriptions indexData, final Acceptor referenceAcceptor, final SubMonitor subMonitor) {
IResourceDescriptions2 idx = (IResourceDescriptions2) indexData;
List<IReferenceDescription> refs = uniqueReferences(Lists.newArrayList(idx.findReferencesToObjects(targetURIs.asSet())));
final SubMonitor monitor = SubMonitor.convert(subMonitor, Messages.ReferenceQuery_monitor, refs.size());
for (IReferenceDescription desc : refs) {
if (monitor.isCanceled()) {
return;
}
referenceAcceptor.accept(desc);
monitor.worked(1);
}
monitor.done();
}
use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.
the class ResourceDescriptionsUtil method findExactReferencingResources.
/**
* Utility implementation to find all exact references to a set of objects.
*
* @param descriptions
* context
* @param targetObjects
* objects to find references to
* @param matchPolicy
* match policy
* @return all resources containing outgoing references to one of the objects
*/
@SuppressWarnings("PMD.NPathComplexity")
public static Iterable<IResourceDescription> findExactReferencingResources(final IResourceDescriptions descriptions, final Set<IEObjectDescription> targetObjects, final ReferenceMatchPolicy matchPolicy) {
if (targetObjects.isEmpty()) {
return ImmutableSet.of();
}
final Set<URI> targetUris = Sets.newHashSetWithExpectedSize(targetObjects.size());
final Set<QualifiedName> exportedNames = Sets.newHashSet();
for (IEObjectDescription obj : targetObjects) {
targetUris.add(obj.getEObjectURI());
if (matchPolicy.includes(ReferenceMatchPolicy.IMPORTED_NAMES)) {
exportedNames.add(obj.getName());
}
if (matchPolicy.includes(ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
exportedNames.add(QualifiedNames.toUnresolvedName(obj.getName()));
}
}
return Iterables.filter(descriptions.getAllResourceDescriptions(), input -> {
if (matchPolicy.includes(ReferenceMatchPolicy.IMPORTED_NAMES) || matchPolicy.includes(ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
for (QualifiedName name : input.getImportedNames()) {
if (exportedNames.contains(name)) {
return true;
}
}
}
if (matchPolicy.includes(ReferenceMatchPolicy.REFERENCES)) {
for (IReferenceDescription ref : input.getReferenceDescriptions()) {
if (targetUris.contains(ref.getTargetEObjectUri())) {
return true;
}
}
}
return false;
});
}
use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.
the class ResourceDescription2 method computeReferenceDescriptions.
@Override
protected List<IReferenceDescription> computeReferenceDescriptions() {
final ImmutableList.Builder<IReferenceDescription> referenceDescriptions = ImmutableList.builder();
EcoreUtil2.resolveLazyCrossReferences(getResource(), CancelIndicator.NullImpl);
Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(getResource(), true);
while (contents.hasNext()) {
EObject eObject = contents.next();
URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, referenceDescriptions::add)) {
contents.prune();
}
}
if (strategy instanceof AbstractResourceDescriptionStrategy) {
((AbstractResourceDescriptionStrategy) strategy).createImplicitReferenceDescriptions(getResource(), referenceDescriptions::add);
}
return referenceDescriptions.build();
}
Aggregations