org.eclipse.xtext.findReferences.TargetURIs Java Examples

The following examples show how to use org.eclipse.xtext.findReferences.TargetURIs. 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 vote down vote up
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 #2
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 #3
Source File: DotReferenceFinder.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Using the @Override notation leads to a compile error on some (e.g NEON,
 * OXYGEN, PHOTON, ...) platforms, since this internal Xtext API has been
 * changed over time.
 *
 * see
 * https://github.com/eclipse/xtext-core/commit/69064ac12f0144b60d8c7511d41c834db44a67f2
 *
 * This method will be invoked on ...LUNA, MARS, platforms
 */
public void findReferences(TargetURIs targetURIs, Resource resource,
		Acceptor acceptor, IProgressMonitor monitor) {
	// add DOT specific references
	for (URI targetURI : targetURIs) {
		EObject target = resource.getEObject(targetURI.fragment());
		// currently, only a selection of a nodeId is supported
		if (target instanceof NodeId) {
			acceptor.accept(target, targetURI, null, -1, target, targetURI);
			NodeId selectedNodeId = (NodeId) target;
			for (NodeId source : DotAstHelper
					.getAllNodeIds(selectedNodeId)) {
				URI sourceURI = EcoreUtil2
						.getPlatformResourceOrNormalizedURI(source);
				acceptor.accept(source, sourceURI, null, -1, target,
						targetURI);
			}
		}
	}
}
 
Example #4
Source File: FindReferenceHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private TargetURIs getTargets(EObject declaration) {
	// Special handling for composed members
	List<EObject> realTargets = new ArrayList<>();
	if ((declaration instanceof TMember) && ((TMember) declaration).isComposed()) {
		// In case of composed member, add the constituent members instead.
		List<TMember> constituentMembers = ((TMember) declaration).getConstituentMembers();
		for (TMember constituentMember : constituentMembers) {
			realTargets.add(constituentMember);
		}
	} else {
		// Standard case
		realTargets.add(declaration);
	}

	TargetURIs targets = targetURISetProvider.get();

	for (EObject realTarget : realTargets) {
		collector.add(realTarget, targets);
	}
	return targets;
}
 
Example #5
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 #6
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 #7
Source File: HeadlessReferenceFinder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #8
Source File: ConcreteSyntaxAwareReferenceFinder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected EObject toValidInstanceOrNull(Resource resource, Predicate<URI> targetURIs, EObject value) {
	EObject result = value;
	if (result.eIsProxy()) {
		URI proxyURI = EcoreUtil.getURI(result);
		if (uriEncoder.isCrossLinkFragment(resource, proxyURI.fragment())) {
			INode node = uriEncoder.decode(resource, proxyURI.fragment()).getThird();
			try {
				String string = linkingHelper.getCrossRefNodeAsString(node, true);
				if (((TargetURIs) targetURIs).getUserData(TargetURIKey.KEY).isMatchingConcreteSyntax(string)) {
					result = resolveInternalProxy(value, resource);
				} else {
					result = null;
				}
			} catch (IllegalNodeException ine) {
				// illegal nodes exist in broken ASTs
				// fired in linkingHelper.getCrossRefNodeAsString(...)
				result = null;
			}
		} else {
			result = resolveInternalProxy(value, resource);
		}
	}
	return result;
}
 
Example #9
Source File: ConcreteSyntaxAwareReferenceFinder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void findReferences(Predicate<URI> targetURIs, Resource resource, Acceptor acceptor,
		IProgressMonitor monitor) {
	// make sure data is present
	keys.getData((TargetURIs) targetURIs, new SimpleResourceAccess(resource.getResourceSet()));
	EList<EObject> astContents;
	if (resource instanceof N4JSResource) {
		// In case of N4JSResource, we search only in the AST but NOT in TModule tree!
		Script script = (Script) ((N4JSResource) resource).getContents().get(0);
		astContents = new BasicEList<>();
		astContents.add(script);
	} else {
		astContents = resource.getContents();
	}
	for (EObject content : astContents) {
		findReferences(targetURIs, content, acceptor, monitor);
	}
}
 
Example #10
Source File: TargetURIKey.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void init(Data result, IResourceAccess resourceAccess, TargetURIs targetURIs) {
	targetURIs.getTargetResourceURIs().forEach((resourceURI) -> {
		resourceAccess.readOnly(resourceURI, (resourceSet) -> {
			targetURIs.getEObjectURIs(resourceURI).forEach((objectURI) -> {
				try {
					EObject object = resourceSet.getEObject(objectURI, true);
					if (object != null) {
						result.add(object);
					}
				} catch (RuntimeException e) {
					// ignore
				}
			});
			return null;
		});
	});
}
 
Example #11
Source File: DefaultCallHierarchyBuilder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TargetURIs collectTargetURIs(URI targetURI) {
	TargetURIs targetURIs = getTargetURIProvider().get();
	if (targetURI == null) {
		return targetURIs;
	}
	readOnly(targetURI, (EObject targetObject) -> {
		if (targetObject != null) {
			getTargetURICollector().add(targetObject, targetURIs);
		}
		return null;
	});
	return targetURIs;
}
 
Example #12
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 #13
Source File: Declarators.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 #14
Source File: ReferenceFinder2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void findAllReferences(final TargetURIs targetURIs, final IResourceAccess resourceAccess, final IResourceDescriptions indexData, final Acceptor acceptor, final IProgressMonitor monitor) {
  final SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
  if (!Iterables.isEmpty(targetURIs)) {
    if (indexData instanceof IResourceDescriptions2) {
      findReferences(targetURIs, Sets.newHashSet(targetURIs.getTargetResourceURIs()), resourceAccess, indexData, acceptor, subMonitor.newChild(1));
      findAllIndexedReferences(targetURIs, indexData, acceptor, subMonitor.newChild(9));
    } else {
      super.findAllReferences(targetURIs, resourceAccess, indexData, acceptor, subMonitor);
    }
  }
}
 
Example #15
Source File: DotReferenceFinder.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method will be invoked on NEON, OXYGEN, PHOTON... platforms
 */
public void findReferences(Predicate<URI> targetURIs, EObject scope,
		Acceptor acceptor, IProgressMonitor monitor) {

	if (targetURIs instanceof TargetURIs) {
		findReferences((TargetURIs) targetURIs, scope.eResource(), acceptor,
				monitor);
	}

}
 
Example #16
Source File: DefaultReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void findLocalReferences(
		Iterable<URI> localTargets,
		ILocalResourceAccess localResourceAccess,
		final IAcceptor<IReferenceDescription> acceptor,
		IProgressMonitor monitor) {
	if ((monitor != null && monitor.isCanceled()))
		throw new OperationCanceledException();

	final TargetURIs targetURIs = converter.fromIterable(localTargets);
	Collection<URI> resourceURIs = targetURIs.getTargetResourceURIs();
	final SubMonitor subMonitor = SubMonitor.convert(monitor, resourceURIs.size() / MONITOR_FIND_LOCAL_CHUNK_SIZE + 1);
	int i = 0;
	for(final URI resourceURI: resourceURIs) {
		if (subMonitor.isCanceled())
			throw new OperationCanceledException();
		localResourceAccess.readOnly(resourceURI, new IUnitOfWork.Void<ResourceSet>() {
			@Override
			public void process(ResourceSet resourceSet) throws Exception {
				Resource resource = resourceSet.getResource(resourceURI, true);
				DefaultReferenceFinder.super.findReferences(targetURIs, resource, toAcceptor(acceptor), subMonitor);
			}
		});
		i++;
		if (i % MONITOR_FIND_LOCAL_CHUNK_SIZE == 0)
			subMonitor.worked(1);
	}
}
 
Example #17
Source File: DefaultReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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 #18
Source File: TargetURIKey.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #19
Source File: DefaultReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void findReferences(Iterable<URI> targetURIs, final Iterable<URI> sourceResourceURIs,
		ILocalResourceAccess localResourceAccess, IAcceptor<IReferenceDescription> referenceAcceptor,
		IProgressMonitor monitor) {
	TargetURIs converted = converter.fromIterable(targetURIs);
	HashSet<URI> sourceResourcesAsSet = Sets.newHashSet(sourceResourceURIs);
	super.findReferences(converted, sourceResourcesAsSet, localResourceAccess, indexData, toAcceptor(referenceAcceptor), monitor);
	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 #20
Source File: OccurrencesService.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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 #21
Source File: JvmModelTargetURICollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doAdd(EObject object, TargetURIs targetURIs) {
	super.doAdd(object, targetURIs);
	Set<EObject> jvmElements = associations.getJvmElements(object);
	for(EObject jvmElement: jvmElements) {
		super.doAdd(jvmElement, targetURIs);
	}
}
 
Example #22
Source File: FindReferenceHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return all references to the given declaration in the given {@link Resource} */
public List<EObject> findReferencesInResource(EObject declaration, Resource resource) {
	declaration = getDeclaration(declaration);
	TargetURIs targets = getTargets(declaration);
	ReferenceAcceptor acceptor = new ReferenceAcceptor();

	referenceFinder.findReferences(targets, resource, acceptor, null);

	return acceptor.results;
}
 
Example #23
Source File: FindReferenceHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return all references to the given declaration. Respect editor states. */
public List<EObject> findReferences(EObject declaration, ResourceSet resourceSet) {
	declaration = getDeclaration(declaration);
	TargetURIs targets = getTargets(declaration);
	SimpleResourceAccess resourceAccess = new SimpleResourceAccess(resourceSet);
	IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(resourceSet);
	ReferenceAcceptor acceptor = new ReferenceAcceptor();

	referenceFinder.findAllReferences(targets, resourceAccess, index, acceptor, null);
	return acceptor.results;
}
 
Example #24
Source File: InferredElementsTargetURICollector.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void doAdd(EObject primaryTarget, TargetURIs targetURIsAddHere) {
	Resource resource = primaryTarget.eResource();
	// If the target is not contained in a resource, we cannot do anything but return.
	if (resource == null)
		return;
	EcoreUtil.resolveAll(primaryTarget.eResource());

	// Special handling for composed members and TStructMember
	if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
		// In case of composed member, add the constituent members instead.
		List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
		for (TMember constituentMember : constituentMembers) {
			super.doAdd(constituentMember, targetURIsAddHere);
		}
	} else {
		if (primaryTarget instanceof TStructMember) {
			TStructMember crossRefStructMember = ((TStructMember) primaryTarget).getDefinedMember();
			if (crossRefStructMember != null)
				// If this TStructMember is an AST, also add the defined member located in the TModule
				super.doAdd(((TStructMember) primaryTarget).getDefinedMember(), targetURIsAddHere);
		}
		super.doAdd(primaryTarget, targetURIsAddHere);
	}

	inferredElements.collectInferredElements(primaryTarget, (object) -> {
		if (object != null) {
			super.doAdd(object, targetURIsAddHere);
		}
	}, staticPolyfillHelper);
}
 
Example #25
Source File: TargetURIKey.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private Data initData(TargetURIs targetURIs, IReferenceFinder.IResourceAccess resourceAccess) {
	Data result = new Data(qualifiedNameProvider);
	init(result, resourceAccess, targetURIs);
	targetURIs.putUserData(KEY, result);
	return result;
}
 
Example #26
Source File: ConcreteSyntaxAwareReferenceFinder.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void findReferencesInDescription(TargetURIs targetURIs, IResourceDescription resourceDescription,
		IResourceAccess resourceAccess, Acceptor acceptor, IProgressMonitor monitor) {
	TargetURIKey.Data findReferencesData = keys.getData(targetURIs, resourceAccess);
	if (monitor.isCanceled())
		throw new OperationCanceledException();

	final Set<QualifiedName> typesOrModulesToFind = findReferencesData.getTypesOrModulesToFind();
	if (typesOrModulesToFind.isEmpty()) {
		return;
	}
	Iterable<QualifiedName> importedNames = resourceDescription.getImportedNames();
	// scenario 1: imported names from index
	// TODO check if imported names from editors are returned as a set?
	// maybe we need another check for instanceof SortedSet<?>
	if (importedNames instanceof List<?>) {
		List<QualifiedName> sorted = (List<QualifiedName>) importedNames;
		List<QualifiedName> searchMe = sorted;
		// Optimize search
		for (QualifiedName typeOrModuleToFind : typesOrModulesToFind) {
			int insertionIndex = Collections.binarySearch(searchMe, typeOrModuleToFind);
			if (insertionIndex >= 0) {
				resourceAccess.readOnly(
						resourceDescription.getURI(),
						(resourceSet) -> {
							findReferences(targetURIs, resourceSet.getResource(resourceDescription.getURI(), true),
									acceptor, monitor);
							return null;
						});
				return;
			} else {
				int startFrom = -(insertionIndex + 1);
				if (startFrom >= sorted.size()) {
					return;
				}
				searchMe = sorted.subList(startFrom, sorted.size());
			}
		}
	} else {
		for (QualifiedName importedName : importedNames) {
			if (typesOrModulesToFind.contains(importedName)) {
				resourceAccess.readOnly(
						resourceDescription.getURI(),
						(resourceSet) -> {
							findReferences(targetURIs, resourceSet.getResource(resourceDescription.getURI(), true),
									acceptor, monitor);
							return null;
						});
				return;
			}
		}
	}
}
 
Example #27
Source File: ConcreteSyntaxAwareReferenceFinder.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected boolean doProcess(EReference reference, Predicate<URI> targetURISet) {
	return ((TargetURIs) targetURISet).getUserData(TargetURIKey.KEY)
			.isEReferenceTypeApplicable(reference.getEReferenceType());
}
 
Example #28
Source File: HeadlessReferenceFinder.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private TargetURIs getTargetURIs(EObject primaryTarget) {
	TargetURIs result = targetURIsProvider.get();
	uriCollector.add(primaryTarget, result);
	return result;
}
 
Example #29
Source File: AbstractHierarchyBuilder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void setTargetURIProvider(Provider<TargetURIs> targetURIProvider) {
	this.targetURIProvider = targetURIProvider;
}
 
Example #30
Source File: AbstractHierarchyBuilder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Provider<TargetURIs> getTargetURIProvider() {
	return targetURIProvider;
}