use of org.eclipse.xtext.findReferences.TargetURIs in project xtext-core by eclipse.
the class DocumentSymbolService method getDefinitions.
public List<? extends Location> getDefinitions(final XtextResource resource, final int offset, final IReferenceFinder.IResourceAccess resourceAccess, final CancelIndicator cancelIndicator) {
final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if ((element == null)) {
return CollectionLiterals.<Location>emptyList();
}
final ArrayList<Location> locations = CollectionLiterals.<Location>newArrayList();
final TargetURIs targetURIs = this.collectTargetURIs(element);
for (final URI targetURI : targetURIs) {
{
this.operationCanceledManager.checkCanceled(cancelIndicator);
final Procedure1<EObject> _function = (EObject obj) -> {
final Location location = this._documentExtensions.newLocation(obj);
if ((location != null)) {
locations.add(location);
}
};
this.doRead(resourceAccess, targetURI, _function);
}
}
return locations;
}
use of org.eclipse.xtext.findReferences.TargetURIs in project xtext-core by eclipse.
the class DocumentSymbolService method getReferences.
public List<? extends Location> getReferences(final XtextResource resource, final int offset, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) {
final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if ((element == null)) {
return CollectionLiterals.<Location>emptyList();
}
final ArrayList<Location> locations = CollectionLiterals.<Location>newArrayList();
final TargetURIs targetURIs = this.collectTargetURIs(element);
final IAcceptor<IReferenceDescription> _function = (IReferenceDescription reference) -> {
final Procedure1<EObject> _function_1 = (EObject obj) -> {
final Location location = this._documentExtensions.newLocation(obj, reference.getEReference(), reference.getIndexInList());
if ((location != null)) {
locations.add(location);
}
};
this.doRead(resourceAccess, reference.getSourceEObjectUri(), _function_1);
};
ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(this.resourceServiceProviderRegistry, _function);
CancelIndicatorProgressMonitor _cancelIndicatorProgressMonitor = new CancelIndicatorProgressMonitor(cancelIndicator);
this.referenceFinder.findAllReferences(targetURIs, resourceAccess, indexData, _referenceAcceptor, _cancelIndicatorProgressMonitor);
return locations;
}
use of org.eclipse.xtext.findReferences.TargetURIs in project xtext-core by eclipse.
the class DefaultDocumentHighlightService method getTargetURIs.
/**
* Returns with an iterable of URIs that points to all elements that are
* referenced by the argument or vice-versa.
*
* @return an iterable of URIs that are referenced by the argument or the
* other way around.
*/
protected Iterable<URI> getTargetURIs(final EObject primaryTarget) {
final TargetURIs result = targetURIsProvider.get();
uriCollector.add(primaryTarget, result);
return result;
}
use of org.eclipse.xtext.findReferences.TargetURIs in project xtext-core by eclipse.
the class DefaultDocumentHighlightService method getDocumentHighlights.
@Override
public List<DocumentHighlight> getDocumentHighlights(final XtextResource resource, final int offset) {
if (resource == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Resource was null.");
}
return emptyList();
}
final URI uri = resource.getURI();
if (offset < 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Invalid offset argument. Offset must be a non-negative integer for resource: " + uri);
}
return emptyList();
}
final IParseResult parseResult = resource.getParseResult();
if (parseResult == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Parse result was null for resource: " + uri);
}
return emptyList();
}
final ICompositeNode rootNode = parseResult.getRootNode();
final String docContent = rootNode.getText();
final int docLength = docContent.length();
if (offset >= docLength) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Offset exceeds document lenght. Document was " + docLength + " and offset was: " + offset + " for resource: " + uri);
}
return emptyList();
}
final EObject selectedElemnt = offsetHelper.resolveElementAt(resource, offset);
if (!isDocumentHighlightAvailableFor(selectedElemnt, resource, offset)) {
return emptyList();
}
final Supplier<Document> docSupplier = Suppliers.memoize(() -> new Document(UNUSED_VERSION, docContent));
Iterable<URI> targetURIs = getTargetURIs(selectedElemnt);
if (!(targetURIs instanceof TargetURIs)) {
final TargetURIs result = targetURIsProvider.get();
result.addAllURIs(targetURIs);
targetURIs = result;
}
final Builder<DocumentHighlight> resultBuilder = ImmutableList.<DocumentHighlight>builder();
final Acceptor acceptor = (Acceptor2) (source, sourceURI, eReference, index, targetOrProxy, targetURI) -> {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(source, eReference, index);
if (!isNullOrEmpty(region)) {
resultBuilder.add(textRegionTransformer.apply(docSupplier.get(), region, DocumentHighlightKind.Read));
}
};
referenceFinder.findReferences((TargetURIs) targetURIs, resource, acceptor, new NullProgressMonitor());
if (resource.equals(selectedElemnt.eResource())) {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(selectedElemnt);
if (!isNullOrEmpty(region)) {
resultBuilder.add(textRegionTransformer.apply(docSupplier.get(), region, DocumentHighlightKind.Write));
}
}
return FluentIterable.from(resultBuilder.build()).toSortedList(comparator);
}
use of org.eclipse.xtext.findReferences.TargetURIs in project xtext-core by eclipse.
the class DefaultCallHierarchyBuilder method collectTargetURIs.
protected TargetURIs collectTargetURIs(final URI targetURI) {
final TargetURIs targetURIs = this.getTargetURIProvider().get();
if ((targetURI == null)) {
return targetURIs;
}
final IUnitOfWork<Object, EObject> _function = (EObject targetObject) -> {
if ((targetObject != null)) {
this.getTargetURICollector().add(targetObject, targetURIs);
}
return null;
};
this.<Object>readOnly(targetURI, _function);
return targetURIs;
}
Aggregations