Java Code Examples for org.eclipse.xtext.findReferences.IReferenceFinder#Acceptor
The following examples show how to use
org.eclipse.xtext.findReferences.IReferenceFinder#Acceptor .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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); }