Search in sources :

Example 1 with TargetURIs

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) URI(org.eclipse.emf.common.util.URI) Location(org.eclipse.lsp4j.Location)

Example 2 with TargetURIs

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;
}
Also used : ReferenceAcceptor(org.eclipse.xtext.findReferences.ReferenceAcceptor) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) CancelIndicatorProgressMonitor(org.eclipse.xtext.ide.util.CancelIndicatorProgressMonitor) Location(org.eclipse.lsp4j.Location) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 3 with TargetURIs

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;
}
Also used : TargetURIs(org.eclipse.xtext.findReferences.TargetURIs)

Example 4 with TargetURIs

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);
}
Also used : DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Acceptor(org.eclipse.xtext.findReferences.IReferenceFinder.Acceptor) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 5 with TargetURIs

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

TargetURIs (org.eclipse.xtext.findReferences.TargetURIs)7 EObject (org.eclipse.emf.ecore.EObject)4 URI (org.eclipse.emf.common.util.URI)2 Location (org.eclipse.lsp4j.Location)2 ReferenceAcceptor (org.eclipse.xtext.findReferences.ReferenceAcceptor)2 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 DocumentHighlight (org.eclipse.lsp4j.DocumentHighlight)1 Acceptor (org.eclipse.xtext.findReferences.IReferenceFinder.Acceptor)1 Document (org.eclipse.xtext.ide.server.Document)1 CancelIndicatorProgressMonitor (org.eclipse.xtext.ide.util.CancelIndicatorProgressMonitor)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1