Java Code Examples for org.eclipse.xtext.resource.impl.ResourceDescriptionsData#getAllURIs()

The following examples show how to use org.eclipse.xtext.resource.impl.ResourceDescriptionsData#getAllURIs() . 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: FlatResourceSetBasedAllContainersState.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Collection<URI> getContainedURIs(String containerHandle) {
	if (!HANDLE.equals(containerHandle))
		return Collections.emptySet();
	if (resourceSet instanceof XtextResourceSet) {
		ResourceDescriptionsData descriptionsData = findResourceDescriptionsData(resourceSet);
		if (descriptionsData != null) {
			return descriptionsData.getAllURIs();
		}
		return newArrayList(((XtextResourceSet) resourceSet).getNormalizationMap().values());
	}
	List<URI> uris = Lists.newArrayListWithCapacity(resourceSet.getResources().size());
	URIConverter uriConverter = resourceSet.getURIConverter();
	for (Resource r : resourceSet.getResources())
		uris.add(uriConverter.normalize(r.getURI()));
	return uris;
}
 
Example 2
Source File: XProjectManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return all resource descriptions that start with the given prefix */
public List<URI> findResourcesStartingWithPrefix(URI prefix) {
	ResourceDescriptionsData resourceDescriptionsData = fullIndex.getContainer(projectDescription.getName());

	// TODO: Moving this into ResourceDescriptionsData and using a sorted Map could increase performance
	List<URI> uris = new ArrayList<>();
	for (URI uri : resourceDescriptionsData.getAllURIs()) {
		if (UriUtil.isPrefixOf(prefix, uri)) {
			uris.add(uri);
		}
	}
	return uris;
}
 
Example 3
Source File: XStatefulIncrementalBuilder.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Run the build.
 * <p>
 * Cancellation behavior: does not throw exception but returns with a partial result.
 */
public XBuildResult launch() {
	List<IResourceDescription.Delta> allProcessedDeltas = new ArrayList<>();

	try {
		XSource2GeneratedMapping newSource2GeneratedMapping = this.request.getState().getFileMappings();

		Set<URI> unloaded = new HashSet<>();
		for (URI deleted : request.getDeletedFiles()) {
			if (unloaded.add(deleted)) {
				unloadResource(deleted);
			}
		}
		for (URI dirty : request.getDirtyFiles()) {
			if (unloaded.add(dirty)) {
				unloadResource(dirty);
			}
		}

		for (URI source : request.getDeletedFiles()) {
			request.setResultIssues(request.getProjectName(), source, Collections.emptyList());
			removeGeneratedFiles(source, newSource2GeneratedMapping);
		}

		List<Delta> allProcessedAndExternalDeltas = new ArrayList<>(request.getExternalDeltas());

		ResourceDescriptionsData oldIndex = context.getOldState().getResourceDescriptions();
		Set<URI> remainingURIs = new LinkedHashSet<>(oldIndex.getAllURIs()); // note: creating a copy!

		XIndexer.XIndexResult result = indexer.computeAndIndexDeletedAndChanged(request, context);
		ResourceDescriptionsData newIndex = result.getNewIndex();
		List<Delta> deltasToBeProcessed = result.getResourceDeltas();
		List<Delta> deltasFromExternal = indexer.computeAndIndexAffected(newIndex, remainingURIs,
				request.getExternalDeltas(), allProcessedAndExternalDeltas, context);
		deltasToBeProcessed.addAll(deltasFromExternal);

		operationCanceledManager.checkCanceled(request.getCancelIndicator());

		// continue as long as there are more deltas to be processed (either the deltas representing the initial
		// deletions/changes or in later iterations the deltas representing affected resources)
		while (!deltasToBeProcessed.isEmpty()) {

			// process the deltas
			List<Delta> newDeltas = new ArrayList<>();
			List<URI> urisToBeBuilt = new ArrayList<>();
			for (IResourceDescription.Delta delta : deltasToBeProcessed) {
				URI uri = delta.getUri();
				if (delta.getOld() != null && unloaded.add(uri)) {
					unloadResource(uri);
				}
				if (delta.getNew() == null) {
					// deleted resources are not being built, thus add immediately to 'newDeltas'
					newDeltas.add(delta);
				} else {
					urisToBeBuilt.add(uri);
				}
				remainingURIs.remove(uri);
			}

			List<IResourceDescription.Delta> deltasBuilt = context.executeClustered(urisToBeBuilt,
					(resource) -> buildClustured(resource, newSource2GeneratedMapping, result));
			newDeltas.addAll(deltasBuilt);

			allProcessedDeltas.addAll(newDeltas);
			allProcessedAndExternalDeltas.addAll(newDeltas);

			// find more deltas to be processed (for affected resources)
			deltasToBeProcessed = indexer.computeAndIndexAffected(newIndex, remainingURIs, newDeltas,
					allProcessedAndExternalDeltas, context);
		}

	} catch (CancellationException e) {
		// catch CancellationException here and proceed normally to save already resolved deltas
		// (note: do not handle OperationCanceledException this way; it would break the builder, see GH-1775)
	}

	return new XBuildResult(this.request.getState(), allProcessedDeltas);
}