org.eclipse.xtext.findReferences.IReferenceFinder Java Examples
The following examples show how to use
org.eclipse.xtext.findReferences.IReferenceFinder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public List<? extends Location> getDefinitions(XtextResource resource, int offset, IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) { EObject element = eObjectAtOffsetHelper.resolveElementAt(resource, offset); if (element == null) { return Collections.emptyList(); } List<Location> locations = new ArrayList<>(); TargetURIs targetURIs = collectTargetURIs(element); for (URI targetURI : targetURIs) { operationCanceledManager.checkCanceled(cancelIndicator); doRead(resourceAccess, targetURI, (EObject obj) -> { Location location = documentExtensions.newLocation(obj); if (location != null) { locations.add(location); } }); } return locations; }
Example #2
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public List<? extends Location> getReferences(XtextResource resource, int offset, IReferenceFinder.IResourceAccess resourceAccess, IResourceDescriptions indexData, CancelIndicator cancelIndicator) { EObject element = eObjectAtOffsetHelper.resolveElementAt(resource, offset); if (element == null) { return Collections.emptyList(); } List<Location> locations = new ArrayList<>(); TargetURIs targetURIs = collectTargetURIs(element); referenceFinder.findAllReferences(targetURIs, resourceAccess, indexData, new ReferenceAcceptor(resourceServiceProviderRegistry, (IReferenceDescription reference) -> { doRead(resourceAccess, reference.getSourceEObjectUri(), (EObject obj) -> { Location location = documentExtensions.newLocation(obj, reference.getEReference(), reference.getIndexInList()); if (location != null) { locations.add(location); } }); }), new CancelIndicatorProgressMonitor(cancelIndicator)); return locations; }
Example #3
Source File: HeadlessReferenceFinder.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Find all references to the given target with its resource set as working environment. * * @param target * the object to look for. * @param monitor * the progress monitor. * @return the list of reference descriptions. */ public List<IReferenceDescription> findReferencesTo(EObject target, IProgressMonitor monitor) { final TargetURIs targetURIs = getTargetURIs(target); final ResourceSet resourceSet = target.eResource().getResourceSet(); final List<IReferenceDescription> result = Lists.newArrayList(); IReferenceFinder.IResourceAccess resourceAccess = new SimpleResourceAccess(resourceSet); IReferenceFinder.Acceptor acceptor = new IReferenceFinder.Acceptor() { @Override public void accept(IReferenceDescription description) { result.add(description); } @Override public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) { accept(new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, null)); } }; referenceFinder.findAllReferences(targetURIs, resourceAccess, resourceDescriptionsProvider.getResourceDescriptions(resourceSet), acceptor, monitor); return result; }
Example #4
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void getSymbolLocation(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess, Procedure1<? super Location> acceptor) { doRead(resourceAccess, description.getEObjectURI(), (EObject obj) -> { Location location = getSymbolLocation(obj); if (location != null) { acceptor.apply(location); } }); }
Example #5
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public List<? extends Location> getReferences(Document document, XtextResource resource, ReferenceParams params, IReferenceFinder.IResourceAccess resourceAccess, IResourceDescriptions indexData, CancelIndicator cancelIndicator) { int offset = document.getOffSet(params.getPosition()); List<? extends Location> definitions = Collections.emptyList(); if (params.getContext().isIncludeDeclaration()) { definitions = getDefinitions(resource, offset, resourceAccess, cancelIndicator); } List<? extends Location> references = getReferences(resource, offset, resourceAccess, indexData, cancelIndicator); List<Location> result = new ArrayList<>(); result.addAll(definitions); result.addAll(references); return result; }
Example #6
Source File: XtendReferenceFinder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void addReferenceIfTarget(final EObject candidate, final Predicate<URI> targetURISet, final EObject sourceElement, final EReference reference, final IReferenceFinder.Acceptor acceptor) { final URI candidateURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(candidate); boolean _apply = targetURISet.apply(candidateURI); if (_apply) { final URI sourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(sourceElement); acceptor.accept(sourceElement, sourceURI, reference, (-1), candidate, candidateURI); } }
Example #7
Source File: XtendReferenceFinder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void addReferenceToTypeFromStaticImport(final XAbstractFeatureCall sourceCandidate, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) { final JvmIdentifiableElement feature = sourceCandidate.getFeature(); if ((feature instanceof JvmMember)) { final JvmDeclaredType type = ((JvmMember)feature).getDeclaringType(); this.addReferenceIfTarget(type, targetURISet, sourceCandidate, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor); } }
Example #8
Source File: TargetURIKey.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Get or create a data cache in the user data space of the given target URIs. * * @return a new or existing data cache. */ public Data getData(TargetURIs targetURIs, IReferenceFinder.IResourceAccess resourceAccess) { Data result = targetURIs.getUserData(KEY); if (result != null) { return result; } return initData(targetURIs, resourceAccess); }
Example #9
Source File: XtendReferenceFinder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void addReferencesToSuper(final AnonymousClass anonymousClass, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) { final XConstructorCall constructorCall = anonymousClass.getConstructorCall(); final JvmGenericType superType = this._anonymousClassUtil.getSuperType(anonymousClass); if (superType!=null) { this.addReferenceIfTarget(superType, targetURISet, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, acceptor); } final JvmConstructor superConstructor = this._anonymousClassUtil.getSuperTypeConstructor(anonymousClass); if (superConstructor!=null) { this.addReferenceIfTarget(superConstructor, targetURISet, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, acceptor); } }
Example #10
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public List<? extends SymbolInformation> getSymbols(IResourceDescription resourceDescription, String query, IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) { List<SymbolInformation> symbols = new LinkedList<>(); for (IEObjectDescription description : resourceDescription.getExportedObjects()) { operationCanceledManager.checkCanceled(cancelIndicator); if (filter(description, query)) { createSymbol(description, resourceAccess, (SymbolInformation symbol) -> { symbols.add(symbol); }); } } return symbols; }
Example #11
Source File: Declarators.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public Declarators.DeclaratorsData getDeclaratorData(final TargetURIs targetURIs, final IReferenceFinder.IResourceAccess resourceAccess) { Declarators.DeclaratorsData result = targetURIs.<Declarators.DeclaratorsData>getUserData(Declarators.KEY); if ((result != null)) { return result; } final HashSet<QualifiedName> declaratorNames = CollectionLiterals.<QualifiedName>newHashSet(); final Consumer<URI> _function = (URI uri) -> { final IUnitOfWork<Object, ResourceSet> _function_1 = (ResourceSet it) -> { Object _xblockexpression = null; { final Consumer<URI> _function_2 = (URI objectURI) -> { final EObject object = it.getEObject(objectURI, true); if ((object != null)) { final JvmType type = EcoreUtil2.<JvmType>getContainerOfType(object, JvmType.class); if ((type != null)) { QualifiedName _lowerCase = this.nameConverter.toQualifiedName(type.getIdentifier()).toLowerCase(); declaratorNames.add(_lowerCase); QualifiedName _lowerCase_1 = this.nameConverter.toQualifiedName(type.getQualifiedName('.')).toLowerCase(); declaratorNames.add(_lowerCase_1); } } }; targetURIs.getEObjectURIs(uri).forEach(_function_2); _xblockexpression = null; } return _xblockexpression; }; resourceAccess.<Object>readOnly(uri, _function_1); }; targetURIs.getTargetResourceURIs().forEach(_function); Declarators.DeclaratorsData _declaratorsData = new Declarators.DeclaratorsData(declaratorNames); result = _declaratorsData; targetURIs.<Declarators.DeclaratorsData>putUserData(Declarators.KEY, result); return result; }
Example #12
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void createSymbol(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess, Procedure1<? super SymbolInformation> acceptor) { String name = getSymbolName(description); if (name == null) { return; } SymbolKind kind = getSymbolKind(description); if (kind == null) { return; } getSymbolLocation(description, resourceAccess, (Location location) -> { SymbolInformation symbol = new SymbolInformation(name, kind, location); acceptor.apply(symbol); }); }
Example #13
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 */ protected void findAllIndexedReferences( IAcceptor<IReferenceDescription> referenceAcceptor, SubMonitor subMonitor, Set<URI> targetURIsAsSet, ILocalResourceAccess localResourceAccess) { TargetURIs targetURIs = converter.fromIterable(targetURIsAsSet); if (!targetURIs.isEmpty()) { subMonitor.setWorkRemaining(size(indexData.getAllResourceDescriptions()) / MONITOR_CHUNK_SIZE + 1); int i = 0; IProgressMonitor useMe = subMonitor.newChild(1); for (IResourceDescription resourceDescription : indexData.getAllResourceDescriptions()) { IResourceServiceProvider serviceProvider = getServiceProviderRegistry().getResourceServiceProvider(resourceDescription.getURI()); if (serviceProvider != null) { IReferenceFinder referenceFinder = serviceProvider.get(IReferenceFinder.class); if (referenceFinder instanceof IReferenceFinderExtension1) { IReferenceFinderExtension1 extension1 = (IReferenceFinderExtension1) referenceFinder; extension1.findReferences(targetURIsAsSet, resourceDescription, referenceAcceptor, useMe, localResourceAccess); } else { // don't use the language specific reference finder here for backwards compatibility reasons findReferences(targetURIsAsSet, resourceDescription, referenceAcceptor, useMe, localResourceAccess); } } i++; if (i % MONITOR_CHUNK_SIZE == 0) { useMe = subMonitor.newChild(1); } } } }
Example #14
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void doRead(IReferenceFinder.IResourceAccess resourceAccess, URI objectURI, Procedure1<? super EObject> acceptor) { resourceAccess.readOnly(objectURI, (ResourceSet resourceSet) -> { EObject object = resourceSet.getEObject(objectURI, true); if (object != null) { acceptor.apply(object); } return null; }); }
Example #15
Source File: OccurrencesService.java From xtext-web with Eclipse Public License 2.0 | 5 votes |
/** * Find occurrences of the element at the given offset. */ public OccurrencesResult findOccurrences(XtextWebDocumentAccess document, int offset) { return document.readOnly(new CancelableUnitOfWork<OccurrencesResult, IXtextWebDocument>() { @Override public OccurrencesResult exec(IXtextWebDocument doc, CancelIndicator cancelIndicator) throws Exception { EObject element = elementAtOffsetUtil.getElementAt(doc.getResource(), offset); OccurrencesResult occurrencesResult = new OccurrencesResult(doc.getStateId()); if (element != null && filter(element)) { URI elementURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(element); TargetURIs targetURIs = targetURIsProvider.get(); targetURIs.addURI(elementURI); IReferenceFinder.Acceptor acceptor = new IReferenceFinder.Acceptor() { @Override public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) { ITextRegion region = locationInFileProvider.getSignificantTextRegion(source, eReference, index); occurrencesResult.getReadRegions() .add(new TextRegion(region.getOffset(), region.getLength())); } @Override public void accept(IReferenceDescription description) { } }; referenceFinder.findReferences(targetURIs, doc.getResource(), acceptor, new CancelIndicatorProgressMonitor(cancelIndicator)); if (Objects.equal(element.eResource(), doc.getResource())) { ITextRegion definitionRegion = locationInFileProvider.getSignificantTextRegion(element); if (definitionRegion != null && definitionRegion != ITextRegionWithLineInformation.EMPTY_REGION) { occurrencesResult.getWriteRegions() .add(new TextRegion(definitionRegion.getOffset(), definitionRegion.getLength())); } } } return occurrencesResult; } }); }
Example #16
Source File: ForwardingResourceAccess.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Configure the delegate. * * @param delegate * the delegate to use. */ public ForwardingResourceAccess(IReferenceFinder.IResourceAccess delegate, IResourceSetProvider resourceSetProvider) { this.delegate = delegate; this.resourceSetProvider = resourceSetProvider; }
Example #17
Source File: XtendReferenceFinder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void addReferenceToFeatureFromStaticImport(final XImportDeclaration importDeclaration, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) { final Consumer<JvmFeature> _function = (JvmFeature it) -> { this.addReferenceIfTarget(it, targetURISet, importDeclaration, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, acceptor); }; this._staticallyImportedMemberProvider.getAllFeatures(importDeclaration).forEach(_function); }
Example #18
Source File: AbstractHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected IReferenceFinder.IResourceAccess getResourceAccess() { return resourceAccess; }
Example #19
Source File: AbstractHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void setResourceAccess(IReferenceFinder.IResourceAccess resourceAccess) { this.resourceAccess = resourceAccess; }
Example #20
Source File: AbstractHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected IReferenceFinder getReferenceFinder() { return referenceFinder; }
Example #21
Source File: AbstractHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void setReferenceFinder(IReferenceFinder referenceFinder) { this.referenceFinder = referenceFinder; }
Example #22
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.21 */ public List<? extends Location> getDefinitions(Document document, XtextResource resource, DefinitionParams params, IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) { int offset = document.getOffSet(params.getPosition()); return getDefinitions(resource, offset, resourceAccess, cancelIndicator); }
Example #23
Source File: LanguageServerImpl.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.16 */ protected IReferenceFinder.IResourceAccess getWorkspaceResourceAccess() { return resourceAccess; }
Example #24
Source File: XtendReferenceFinder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override protected void findLocalReferencesFromElement(final Predicate<URI> targetURIs, final EObject sourceCandidate, final Resource localResource, final IReferenceFinder.Acceptor acceptor) { boolean _matched = false; if (sourceCandidate instanceof XAbstractFeatureCall) { boolean _isPackageFragment = ((XAbstractFeatureCall)sourceCandidate).isPackageFragment(); if (_isPackageFragment) { _matched=true; return; } } super.findLocalReferencesFromElement(targetURIs, sourceCandidate, localResource, acceptor); boolean _matched_1 = false; if (sourceCandidate instanceof XImportDeclaration) { if ((((XImportDeclaration)sourceCandidate).isStatic() && (!((XImportDeclaration)sourceCandidate).isWildcard()))) { _matched_1=true; this.addReferenceToFeatureFromStaticImport(((XImportDeclaration)sourceCandidate), targetURIs, acceptor); } } if (!_matched_1) { if (sourceCandidate instanceof XFeatureCall) { if (((((XFeatureCall)sourceCandidate).getActualReceiver() == null) && ((XFeatureCall)sourceCandidate).isStatic())) { _matched_1=true; this.addReferenceToTypeFromStaticImport(((XAbstractFeatureCall)sourceCandidate), targetURIs, acceptor); } } } if (!_matched_1) { if (sourceCandidate instanceof XMemberFeatureCall) { _matched_1=true; if ((((XMemberFeatureCall)sourceCandidate).isStatic() && (!((XMemberFeatureCall)sourceCandidate).isStaticWithDeclaringType()))) { this.addReferenceToTypeFromStaticImport(((XAbstractFeatureCall)sourceCandidate), targetURIs, acceptor); } } } if (!_matched_1) { if (sourceCandidate instanceof AnonymousClass) { _matched_1=true; this.addReferencesToSuper(((AnonymousClass)sourceCandidate), targetURIs, acceptor); } } }
Example #25
Source File: DotReferenceFinder.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected IReferenceFinder getLanguageSpecificReferenceFinder( URI candidate) { return getInstance(); }
Example #26
Source File: DefaultLinkedPositionGroupCalculator.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public Provider<LinkedPositionGroup> getLinkedPositionGroup( IRenameElementContext renameElementContext, IProgressMonitor monitor) { final SubMonitor progress = SubMonitor.convert(monitor, 100); final XtextEditor editor = (XtextEditor) renameElementContext.getTriggeringEditor(); IProject project = projectUtil.getProject(renameElementContext.getContextResourceURI()); if (project == null) throw new IllegalStateException("Could not determine project for context resource " + renameElementContext.getContextResourceURI()); RefactoringResourceSetProvider resourceSetProvider = new CachingResourceSetProvider(DefaultLinkedPositionGroupCalculator.this.resourceSetProvider); ResourceSet resourceSet = resourceSetProvider.get(project); EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true); if (targetElement == null) throw new IllegalStateException("Target element could not be loaded"); if (monitor.isCanceled()) { throw new OperationCanceledException(); } IRenameStrategy.Provider strategyProvider = globalServiceProvider.findService(targetElement, IRenameStrategy.Provider.class); IRenameStrategy renameStrategy = null; try { renameStrategy = strategyProvider.get(targetElement, renameElementContext); } catch(NoSuchStrategyException exc) { // handle in next line } if(renameStrategy == null) throw new IllegalArgumentException("Cannot find a rename strategy for " + notNull(renameElementContext.getTargetElementURI())); String newName = renameStrategy.getOriginalName(); IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(renameElementContext.getTargetElementURI()); IDependentElementsCalculator dependentElementsCalculator = resourceServiceProvider.get(IDependentElementsCalculator.class); Iterable<URI> dependentElementURIs = dependentElementsCalculator.getDependentElementURIs(targetElement, progress.newChild(10)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } LocalResourceRefactoringUpdateAcceptor updateAcceptor = updateAcceptorProvider.get(); updateAcceptor.setLocalResourceURI(renameElementContext.getContextResourceURI()); renameStrategy.createDeclarationUpdates(newName, resourceSet, updateAcceptor); if (monitor.isCanceled()) { throw new OperationCanceledException(); } Map<URI, URI> original2newEObjectURI = renamedElementTracker.renameAndTrack( concat(Collections.singleton(renameElementContext.getTargetElementURI()), dependentElementURIs), newName, resourceSet, renameStrategy, progress.newChild(10)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } ElementRenameArguments elementRenameArguments = new ElementRenameArguments( renameElementContext.getTargetElementURI(), newName, renameStrategy, original2newEObjectURI, resourceSetProvider); final List<IReferenceDescription> referenceDescriptions = newArrayList(); IReferenceFinder.Acceptor referenceAcceptor = new IReferenceFinder.Acceptor() { @Override public void accept(IReferenceDescription referenceDescription) { referenceDescriptions.add(referenceDescription); } @Override public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) { referenceDescriptions.add(new DefaultReferenceDescription(EcoreUtil2.getFragmentPathURI(source), targetURI, eReference, index, null)); } }; if (monitor.isCanceled()) { throw new OperationCanceledException(); } referenceFinder.findReferences( targetURIConverter.fromIterable(elementRenameArguments.getRenamedElementURIs()), resourceSet.getResource(renameElementContext.getContextResourceURI(), true), referenceAcceptor, progress.newChild(10)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } referenceUpdater.createReferenceUpdates(elementRenameArguments, referenceDescriptions, updateAcceptor, progress.newChild(60)); final List<ReplaceEdit> textEdits = updateAcceptor.getTextEdits(); if (monitor.isCanceled()) { throw new OperationCanceledException(); } final IRenameStrategy renameStrategy2 = renameStrategy; return new Provider<LinkedPositionGroup>() { @Override public LinkedPositionGroup get() { LinkedPositionGroup linkedGroup = createLinkedGroupFromReplaceEdits(textEdits, editor, renameStrategy2.getOriginalName(), progress.newChild(10)); return linkedGroup; } }; }
Example #27
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override protected IReferenceFinder getLanguageSpecificReferenceFinder(URI candidate) { // bogus old implementation did not dispatch properly for all candidates return this; }
Example #28
Source File: N4JSRuntimeModule.java From n4js with Eclipse Public License 1.0 | 4 votes |
/***/ public Class<? extends IReferenceFinder> bindReferenceFinder() { return ConcreteSyntaxAwareReferenceFinder.class; }
Example #29
Source File: N4JSUiModule.java From n4js with Eclipse Public License 1.0 | 4 votes |
/***/ public Class<? extends IReferenceFinder> bindReferenceFinder() { return ConcreteSyntaxAwareReferenceFinder.class; }
Example #30
Source File: TargetURIKey.java From n4js with Eclipse Public License 1.0 | 4 votes |
private Data initData(TargetURIs targetURIs, IReferenceFinder.IResourceAccess resourceAccess) { Data result = new Data(qualifiedNameProvider); init(result, resourceAccess, targetURIs); targetURIs.putUserData(KEY, result); return result; }