org.eclipse.xtext.resource.IReferenceDescription Java Examples

The following examples show how to use org.eclipse.xtext.resource.IReferenceDescription. 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: DefaultReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void findAllReferences(
		Iterable<URI> targetURIs,
		ILocalResourceAccess localResourceAccess,
		IAcceptor<IReferenceDescription> referenceAcceptor,
		IProgressMonitor monitor) {
	TargetURIs converted = converter.fromIterable(targetURIs);
	if (!converted.isEmpty()) {
		findAllIndexedReferences(referenceAcceptor, SubMonitor.convert(monitor, 1), converted.asSet(), localResourceAccess);
		if (localResourceAccess != null && !converted.isEmpty() && getClass() != DefaultReferenceFinder.class) {
			// All the references have already been collected, but if this method was overridden,
			// we have to call it again from here
			findLocalReferences(converted, localResourceAccess, referenceAcceptor, monitor);
		}
	}
	
}
 
Example #2
Source File: FastReferenceSearchResultContentProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@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);
      }
    }
  }
}
 
Example #3
Source File: AbstractReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createReferenceUpdates(
		ElementRenameArguments elementRenameArguments,
		Iterable<IReferenceDescription> referenceDescriptions,
		IRefactoringUpdateAcceptor updateAcceptor,
		RefactoringResourceSetProvider resourceSetProvider,
		IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, 100);
	progress.beginTask("Sort references by project", 1);
	Multimap<IProject, IReferenceDescription> project2references = sorter.sortByProject(referenceDescriptions);
	SubMonitor allProjectsProgress = progress.newChild(98).setWorkRemaining(project2references.keySet().size());
	for (IProject project : project2references.keySet()) {
		if (allProjectsProgress.isCanceled()) {
			throw new OperationCanceledException();
		}
		Multimap<URI, IReferenceDescription> resource2references = sorter.sortByResource(project2references
				.get(project));
		ResourceSet resourceSet = resourceSetProvider.get(project);
		StatusWrapper status = updateAcceptor.getRefactoringStatus();
		createClusteredReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor,
				status, allProjectsProgress.newChild(1));
	}
}
 
Example #4
Source File: DefaultCallHierarchyBuilder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void findSourceDeclarations(URI targetDeclarationURI, IProgressMonitor monitor,
		Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) {
	TargetURIs targetURIs = collectTargetURIs(targetDeclarationURI);
	ReferenceAcceptor referenceAcceptor = new ReferenceAcceptor(getResourceServiceProviderRegistry(),
			reference -> {
				if (filterReference(reference)) {
					IEObjectDescription sourceDeclaration = null;
					if (reference != null) {
						sourceDeclaration = findSourceDeclaration(reference);
					}
					acceptor.apply(sourceDeclaration, reference);
				}
			});
	getReferenceFinder().findAllReferences(targetURIs, getResourceAccess(), getIndexData(), referenceAcceptor,
			monitor);
}
 
Example #5
Source File: DotDescriptionLabelProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object image(IReferenceDescription referenceDescription) {
	String result = ""; //$NON-NLS-1$
	EObject eObject = getEObject(referenceDescription);

	if (eObject instanceof NodeId) {
		EObject container = eObject.eContainer();
		if (container instanceof NodeStmt) {
			// the node is a node statement
			result = "node.png"; //$NON-NLS-1$
		}
		if (container instanceof EdgeStmtNode
				|| container instanceof EdgeRhs) {
			// the node is part of an edge
			result = "edge.png"; //$NON-NLS-1$
		}
	}

	return !result.isEmpty() ? result : super.image(referenceDescription);
}
 
Example #6
Source File: ReferenceSearchResultContentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	synchronized (viewer) {
		if (rootNodes != null) {
			rootNodes.clear();
		}
		if (oldInput instanceof ReferenceSearchResult) {
			((ReferenceSearchResult) oldInput).removeListener(this);
		}
		if (newInput instanceof ReferenceSearchResult && viewer instanceof TreeViewer) {
			((ReferenceSearchResult) newInput).addListener(this);
			this.viewer = (TreeViewer) viewer;
			for (IReferenceDescription referenceDescription : ((ReferenceSearchResult) newInput)
					.getMatchingReferences()) {
				addReference(referenceDescription, false);
			}
		}
	}
}
 
Example #7
Source File: ReferenceSearchViewPageActions.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	TreeViewer viewer = page.getViewer();
	ITreeSelection selection = viewer.getStructuredSelection();
	ReferenceSearchViewTreeNode[] removedNodes = Iterables.toArray(
			Iterables.filter(selection.toList(), ReferenceSearchViewTreeNode.class),
			ReferenceSearchViewTreeNode.class);
	page.getContentProvider().remove(removedNodes);
	
	if (searchResult instanceof ReferenceSearchResult) {
		List<IReferenceDescription> descriptions = new ArrayList<IReferenceDescription>();
		IAcceptor<IReferenceDescription> acceptor = CollectionBasedAcceptor.of(descriptions);
		for (ReferenceSearchViewTreeNode removedNode : removedNodes) {
			removedNode.collectReferenceDescriptions(acceptor);
		}
		IReferenceDescription[] descriptionsArray = descriptions.toArray(new IReferenceDescription[descriptions.size()]);
		((ReferenceSearchResult) searchResult).remove(descriptionsArray);
	}
	viewer.refresh();
}
 
Example #8
Source File: DefaultReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createReferenceUpdate(IReferenceDescription referenceDescription, URI referringResourceURI,
		ElementRenameArguments elementRenameArguments, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {
	URI referringElementNewURI = elementRenameArguments
			.getNewElementURI(referenceDescription.getSourceEObjectUri());
	EObject referringElement = resourceSet.getEObject(referringElementNewURI, false);
	if (referringElement == null) {
		updateAcceptor.getRefactoringStatus().add(RefactoringStatus.ERROR, "Cannot find new referring element.", referringElementNewURI);
		log.error("Cannot find new referring element. ReferringElementURI:" + referringElementNewURI);
		return;
	}
	URI targetElementNewURI = elementRenameArguments.getNewElementURI(referenceDescription.getTargetEObjectUri());
	EObject newTargetElement = resourceSet.getEObject(targetElementNewURI, false);
	if (newTargetElement == null) {
		updateAcceptor.getRefactoringStatus().add(RefactoringStatus.ERROR, "Cannot find new target element.", targetElementNewURI);
		log.error("Cannot find new target element. ReferringElement:" + referringElement + " targetElementNewURI:" + targetElementNewURI);
		return;
	}
	createReferenceUpdate(referringElement, referringResourceURI, referenceDescription.getEReference(),
			referenceDescription.getIndexInList(), newTargetElement, updateAcceptor);
}
 
Example #9
Source File: BuilderUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static Set<IReferenceDescription> getContainedReferences(URI uri) {
	Set<IReferenceDescription> desc = Sets.newHashSet();
	Iterable<IResourceDescription> descriptions = getBuilderState().getAllResourceDescriptions();
	for (IResourceDescription res : descriptions) {
		Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
		for (IReferenceDescription ref : descriptions2) {
			if (uri.hasFragment()) {
				if (ref.getSourceEObjectUri().equals(uri))
					desc.add(ref);
			} else {
				if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment()))
					desc.add(ref);
			}
		}
	}
	return desc;
}
 
Example #10
Source File: ValidationJobSchedulerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(final URI uri) {
	return new AbstractResourceDescription() {

		@Override
		public Iterable<QualifiedName> getImportedNames() {
			return Collections.emptyList();
		}

		@Override
		public Iterable<IReferenceDescription> getReferenceDescriptions() {
			return Collections.emptyList();
		}

		@Override
		public URI getURI() {
			return uri;
		}

		@Override
		protected List<IEObjectDescription> computeExportedObjects() {
			return Collections.singletonList(EObjectDescription.create(exportedName, EcoreFactory.eINSTANCE.createEObject()));
		}
		
	};
}
 
Example #11
Source File: EmfResourceReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
		Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
	for (URI referringResourceURI : resource2references.keySet()) {
		try {
			if (monitor.isCanceled())
				throw new OperationCanceledException();
			Resource referringResource = resourceSet.getResource(referringResourceURI, false);
			EObject refactoredElement = resourceSet.getEObject(elementRenameArguments.getNewElementURI(elementRenameArguments.getTargetElementURI()), true);
			if (referringResource != refactoredElement.eResource()) {
				if (refactoredElement instanceof EClassifier) { 
					for (IReferenceDescription reference : resource2references.get(referringResourceURI)) {
						EObject source = referringResource.getEObject(reference.getSourceEObjectUri().fragment());
						if (source == null) {
							LOG.error("Couldn't find source element "+ reference.getSourceEObjectUri() + " in " + referringResource.getURI());
						} else {
							EObject referringEReference = source.eContainer();
							if (referringEReference != null && referringEReference instanceof EReference)
								((EReference) referringEReference).setEType((EClassifier) refactoredElement);
						}
					}
				}
				changeUtil.addSaveAsUpdate(referringResource, updateAcceptor);
			}
		} catch (OperationCanceledException e) {
			throw e;
		} catch (Exception exc) {
			throw new WrappedException(exc);
		}
	}
}
 
Example #12
Source File: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Iterable<IReferenceDescription> getNotImportTypeReferences(Iterable<IReferenceDescription> referenceDescriptions) {
	return IterableExtensions.filter(referenceDescriptions, new Functions.Function1<IReferenceDescription, Boolean>() {

		@Override
		public Boolean apply(IReferenceDescription p) {
			return !isImportTypeReference(p);
		}
		
	});
}
 
Example #13
Source File: AbstractEMFBasedPersisterTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IReferenceDescription createReferenceDescription(int idx) {
	ReferenceDescriptionImpl result = (ReferenceDescriptionImpl) BuilderStateFactory.eINSTANCE.createReferenceDescription();
	result.setIndexInList(idx);
	result.setReference(BuilderStatePackage.eINSTANCE.getIEObjectDescription_EClass());
	result.setSourceEObjectUri(URI.createFileURI(idx + "source.uri"));
	result.setSourceEObjectUri(URI.createFileURI(idx + "target.uri"));
	return result;
}
 
Example #14
Source File: UIParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void showMatch(Match match, int currentOffset, int currentLength, boolean activate) {
	Object o = match.getElement();
	if (o instanceof IReferenceDescription) {
		IReferenceDescription descr = (IReferenceDescription) o;
		if (activate) {
			uriEditorOpener.open(descr.getSourceEObjectUri(), descr.getEReference(), descr.getIndexInList(),
					true);
		}
	}
}
 
Example #15
Source File: AbstractReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
		Iterable<IReferenceDescription> referenceDescriptions, IRefactoringUpdateAcceptor updateAcceptor,
		IProgressMonitor monitor) {
	RefactoringResourceSetProvider provider = elementRenameArguments.getResourceSetProvider();
	createReferenceUpdates(elementRenameArguments, referenceDescriptions, updateAcceptor, provider != null ? provider : resourceSetProvider, monitor);
}
 
Example #16
Source File: SimpleProjectsIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReexportedSource() throws Exception {
	IJavaProject foo = createJavaProject("foo");
	IJavaProject bar = createJavaProject("bar");
	IJavaProject baz = createJavaProject("baz");
	addNature(foo.getProject(), XtextProjectHelper.NATURE_ID);
	addNature(bar.getProject(), XtextProjectHelper.NATURE_ID);
	addNature(baz.getProject(), XtextProjectHelper.NATURE_ID);
	IFile file = foo.getProject().getFile("foo.jar");
	file.create(JavaProjectSetupUtil.jarInputStream(new TextFile("foo/Foo"+F_EXT, "object Foo")), true, monitor());
	IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(file.getFullPath(), null, null,true);
	addToClasspath(foo, newLibraryEntry);
	addToClasspath(bar, JavaCore.newProjectEntry(foo.getPath(), true));
	addToClasspath(baz, JavaCore.newProjectEntry(bar.getPath(), false));
	addSourceFolder(baz, "src");
	IFile bazFile = createFile("baz/src/Baz"+F_EXT, "object Baz references Foo");
	build();
	assertEquals(0,countMarkers(bazFile));
	assertEquals(2, countResourcesInIndex());
	Iterator<IReferenceDescription> references = getContainedReferences(URI.createPlatformResourceURI(bazFile.getFullPath().toString(),true)).iterator();
	IReferenceDescription next = references.next();
	assertFalse(references.hasNext());
	assertEquals("platform:/resource/baz/src/Baz.buildertestlanguage#/",next.getSourceEObjectUri().toString());
	assertEquals("archive:platform:/resource/foo/foo.jar!/foo/Foo.buildertestlanguage#/",next.getTargetEObjectUri().toString());
	assertEquals(-1,next.getIndexInList());
	assertEquals(BuilderTestLanguagePackage.Literals.ELEMENT__REFERENCES,next.getEReference());
}
 
Example #17
Source File: AbstractReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected EObject resolveReference(EObject referringElement, IReferenceDescription referenceDescription) {
	Object resolvedValue = referringElement.eGet(referenceDescription.getEReference());
	if (referenceDescription.getEReference().isMany()) {
		List<?> list = (List<?>) resolvedValue;
		resolvedValue = list.get(referenceDescription.getIndexInList());
	}
	return (EObject) resolvedValue;
}
 
Example #18
Source File: ReferenceFinder2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Omits repeated references, which may arise due to some uses of derived attributes in some DSLs.
 * Considers {@code IReferenceDescription}s with the same source URI to be redundant.
 * Only the first such occurrence in the list is retained, the rest are omitted.
 *
 * @param refs
 *          the original list of reference descriptions
 * @return a list of unique reference descriptions with respect to their source URI
 */
protected List<IReferenceDescription> uniqueReferences(final List<IReferenceDescription> refs) {
  Set<String> addedRefs = Sets.newHashSetWithExpectedSize(refs.size());
  List<IReferenceDescription> noRepeats = Lists.newArrayListWithExpectedSize(refs.size());
  for (IReferenceDescription ref : refs) {
    String sourceURI = ref.getSourceEObjectUri().toString();
    if (!addedRefs.contains(sourceURI)) {
      addedRefs.add(sourceURI);
      noRepeats.add(ref);
    }
  }
  return noRepeats;
}
 
Example #19
Source File: AbstractReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void createClusteredReferenceUpdates(ElementRenameArguments elementRenameArguments,
		Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, resource2references.keySet().size() + 1);
	if (loadTargetResources(resourceSet, elementRenameArguments, status, progress.newChild(1))) {
		if (getClusterSize() > 0) {
			Set<Resource> targetResources = newHashSet(resourceSet.getResources());
			Multimap<URI, IReferenceDescription> cluster = HashMultimap.create();
			SubMonitor clusterMonitor = progress.newChild(1);
			for (URI referringResourceURI : resource2references.keySet()) {
				cluster.putAll(referringResourceURI, resource2references.get(referringResourceURI));
				if (cluster.keySet().size() == getClusterSize()) {
					unloadNonTargetResources(resourceSet, targetResources);
					createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor, status, clusterMonitor);
					cluster.clear();
				}
			}
			if (!cluster.isEmpty()) {
				unloadNonTargetResources(resourceSet, targetResources);
				createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor,
						status, clusterMonitor);
			}
		} else {
			createReferenceUpdatesForCluster(elementRenameArguments, resource2references, resourceSet,
					updateAcceptor, status, progress.newChild(resource2references.keySet().size()));
		}
	}
}
 
Example #20
Source File: ReferenceFinder2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #21
Source File: StatefulResourceDescription.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
	// find references was triggered - use up-to-date reference descriptions
	// the content of this copied description is updated as soon as the exported
	// objects of a resource change thus the default algorithm of the find 
	// references UI for the display string should work
	IResourceDescription snapShot = snapShotProvider.get();
	if (snapShot != null)
		return snapShot.getReferenceDescriptions();
	return Collections.emptyList();
}
 
Example #22
Source File: ResourceDescriptionsUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
  });
}
 
Example #23
Source File: CopiedResourceDescription.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
	public Iterable<IReferenceDescription> getReferenceDescriptions() {
    	// TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=344373
    	IllegalStateException exception = new IllegalStateException("getReferenceDescriptions "+getURI());
    	log.error(exception, exception);
    	return Collections.emptyList();
//        throw new UnsupportedOperationException("getReferenceDescriptions()");
    }
 
Example #24
Source File: ReferenceSearchResult.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void remove(IReferenceDescription[] referenceDescriptions) {
	if (matchingReferences.removeAll(Arrays.asList(referenceDescriptions))) {
		//remember all URIs that have been removed by the user so when re-running
		//this search from history we don't show them again
		Arrays.stream(referenceDescriptions).map(d -> d.getSourceEObjectUri()).forEach(uri -> removedURIs.add(uri));
		fireEvent(new ReferenceSearchResultEvents.Removed(this, referenceDescriptions));
	}
}
 
Example #25
Source File: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Iterable<IReferenceDescription> getImportTypeReferences(Iterable<IReferenceDescription> referenceDescriptions) {
	return IterableExtensions.filter(referenceDescriptions, new Functions.Function1<IReferenceDescription, Boolean>() {

		@Override
		public Boolean apply(IReferenceDescription p) {
			return isImportTypeReference(p);
		}
		
	});
}
 
Example #26
Source File: ReferenceSearchViewTreeNode.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * recursively collects the node's description into the given {@link IAcceptor} including the node's children.
 * Only IReferenceDescriptions are collected
 */
public void collectReferenceDescriptions(IAcceptor<IReferenceDescription> descriptionsAcceptor) {
	if(description instanceof IReferenceDescription) {
		descriptionsAcceptor.accept((IReferenceDescription) description);
	}
	for (ReferenceSearchViewTreeNode child : getChildren()) {
		child.collectReferenceDescriptions(descriptionsAcceptor);
	}
}
 
Example #27
Source File: DefaultReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Override this method for pre- or post-processing hooks.
 */
protected void processReferringResource(Resource referringResource,
		Iterable<IReferenceDescription> referenceDescriptions, ElementRenameArguments elementRenameArguments,
		IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
	((XtextResource) referringResource).getCache().clear(referringResource);
	for (IReferenceDescription referenceDescription : referenceDescriptions) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		createReferenceUpdate(referenceDescription, referringResource.getURI(), elementRenameArguments,
				referringResource.getResourceSet(), updateAcceptor);
	}
}
 
Example #28
Source File: DelegatingReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void findReferences(Iterable<URI> targetURIs, Iterable<URI> sourceResourceURIs,
		ILocalResourceAccess localResourceAccess, IAcceptor<IReferenceDescription> acceptor,
		IProgressMonitor monitor) {
	Set<URI> asSet = Sets.newHashSet(sourceResourceURIs);
	delegate.findReferences(converter.fromIterable(targetURIs), asSet, localResourceAccess, indexData, toAcceptor(acceptor), monitor);
}
 
Example #29
Source File: FindReferencesTestUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void init(EObject target, String expectedLabel, final IAcceptor<IReferenceDescription> acceptor) {
	targetURIs = getTargetURIs(target);
	filter = getFilter(target);
	assertEquals(expectedLabel, getLabel(target));
	this.filteringAcceptor = new IAcceptor<IReferenceDescription>() {
		@Override
		public void accept(IReferenceDescription t) {
			if (filter.apply(t))
				acceptor.accept(t);
		}
	};
	localResourceAccess = resourceAccessProvider.get();
	localResourceAccess.registerResourceSet(target.eResource().getResourceSet());
}
 
Example #30
Source File: BuilderStateUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void copyReferenceDescriptions(IResourceDescription from, ResourceDescriptionImpl result) {
	Iterator<IReferenceDescription> sourceReferenceDescriptions = from.getReferenceDescriptions().iterator();
	if (sourceReferenceDescriptions.hasNext()) {
		InternalEList<IReferenceDescription> targetReferenceDescriptions = (InternalEList<IReferenceDescription>) result.getReferenceDescriptions();
		do {
			targetReferenceDescriptions.addUnique(BuilderStateUtil.create(sourceReferenceDescriptions.next()));	
		} while(sourceReferenceDescriptions.hasNext());
	}
}