org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta Java Examples

The following examples show how to use org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta. 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: XBuildManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** @since 2.18 */
protected void mergeWithUnreportedDeltas(List<IResourceDescription.Delta> newDeltas) {
	if (allBuildDeltas.isEmpty()) {
		allBuildDeltas.addAll(newDeltas);
	} else {
		Map<URI, IResourceDescription.Delta> unreportedByUri = IterableExtensions.toMap(
				allBuildDeltas, IResourceDescription.Delta::getUri);

		for (IResourceDescription.Delta newDelta : newDeltas) {
			IResourceDescription.Delta unreportedDelta = unreportedByUri.get(newDelta.getUri());
			if (unreportedDelta == null) {
				allBuildDeltas.add(newDelta);
			} else {
				allBuildDeltas.remove(unreportedDelta);
				IResourceDescription _old = unreportedDelta.getOld();
				IResourceDescription _new = newDelta.getNew();
				allBuildDeltas.add(new DefaultResourceDescriptionDelta(_old, _new));
			}
		}
	}
}
 
Example #2
Source File: XIndexer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Process the deleted resources.
 */
protected List<IResourceDescription.Delta> getDeltasForDeletedResources(XBuildRequest request,
		ResourceDescriptionsData oldIndex, XBuildContext context) {

	List<IResourceDescription.Delta> deltas = new ArrayList<>();
	for (URI deleted : request.getDeletedFiles()) {
		IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(deleted);
		if (resourceServiceProvider != null) {
			this.operationCanceledManager.checkCanceled(context.getCancelIndicator());
			IResourceDescription oldDescription = oldIndex != null ? oldIndex.getResourceDescription(deleted)
					: null;
			if (oldDescription != null) {
				DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(oldDescription, null);
				deltas.add(delta);
			}
		}
	}
	return deltas;
}
 
Example #3
Source File: AbstractBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected Collection<IResourceDescription.Delta> doClean(Set<URI> toBeRemoved, IProgressMonitor monitor) throws OperationCanceledException {
	SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.AbstractBuilderState_2, toBeRemoved.size() / MONITOR_CHUNK_SIZE_CLEAN + 1);
	subMonitor.subTask(Messages.AbstractBuilderState_2);
	Set<IResourceDescription.Delta> result = newLinkedHashSet();
	int i = 0;
	for (URI toDelete : toBeRemoved) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		IResourceDescription resourceDescription = getResourceDescription(toDelete);
		if (resourceDescription != null) {
			result.add(new DefaultResourceDescriptionDelta(resourceDescription, null));
		}
		i++;
		if (i % MONITOR_CHUNK_SIZE_CLEAN == 0)
			subMonitor.worked(1);
	}
	return result;
}
 
Example #4
Source File: Indexer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Process the deleted resources.
 */
protected List<IResourceDescription.Delta> getDeltasForDeletedResources(BuildRequest request,
		ResourceDescriptionsData oldIndex, BuildContext context) {
	List<IResourceDescription.Delta> deltas = new ArrayList<>();
	for (URI deleted : request.getDeletedFiles()) {
		IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(deleted);
		if (resourceServiceProvider != null) {
			operationCanceledManager.checkCanceled(context.getCancelIndicator());
			IResourceDescription oldDescription = oldIndex != null ? oldIndex.getResourceDescription(deleted)
					: null;
			if (oldDescription != null) {
				DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(oldDescription, null);
				deltas.add(delta);
			}
		}
	}
	return deltas;
}
 
Example #5
Source File: BuildManager.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.18
 */
protected void mergeWithUnreportedDeltas(List<IResourceDescription.Delta> newDeltas) {
	if (unreportedDeltas.isEmpty()) {
		unreportedDeltas.addAll(newDeltas);
	} else {
		Map<URI, IResourceDescription.Delta> unreportedByUri = IterableExtensions.toMap(unreportedDeltas,
				IResourceDescription.Delta::getUri);
		for(IResourceDescription.Delta newDelta: newDeltas) {
			IResourceDescription.Delta unreportedDelta = unreportedByUri.get(newDelta.getUri());
			if (unreportedDelta == null) {
				unreportedDeltas.add(newDelta);
			} else {
				unreportedDeltas.remove(unreportedDelta);
				IResourceDescription oldDescription = unreportedDelta.getOld();
				IResourceDescription newDescription = newDelta.getNew();
				unreportedDeltas.add(new DefaultResourceDescriptionDelta(oldDescription, newDescription));
			}
		}
	}
}
 
Example #6
Source File: DoUpdateImplementation.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private Delta createRemoveDelta(URI uri) {
	final IResourceDescription oldDescription = state.getResourceDescription(uri);
	if (oldDescription != null) {
		return new DefaultResourceDescriptionDelta(oldDescription, null);
	}
	return null;
}
 
Example #7
Source File: DoUpdateImplementation.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void removeDeleted() {
	if (!toBeDeleted.isEmpty()) {
		for (final URI uri : toBeDeleted) {
			newData.removeDescription(uri);
			final IResourceDescription oldDescription = state.getResourceDescription(uri);
			if (oldDescription != null) {
				allDeltas.add(new DefaultResourceDescriptionDelta(oldDescription, null));
			}
		}
	}
}
 
Example #8
Source File: WriteNewResourceDescriptionsImplementation.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void indexNextResource(LoadResult loadResult) {
	URI uri = null;
	Resource resource = null;
	try {
		uri = loadResult.getUri();
		progress.subTask("Indexing " + uri.lastSegment());
		buildLogger.log("Indexing " + uri);
		resource = state.addResource(loadResult.getResource(), resourceSet);

		registerDelta(uri, resource);
	} catch (final RuntimeException ex) {
		if (ex instanceof LoadOperationException) {
			uri = ((LoadOperationException) ex).getUri();
		}
		if (uri == null) {
			LOGGER.error("Error loading resource", ex); //$NON-NLS-1$
		} else {
			if (resourceSet.getURIConverter().exists(uri, Collections.emptyMap())) {
				LOGGER.error("Error loading resource from: " + uri.toString(), ex); //$NON-NLS-1$
			}
			if (resource != null) {
				resourceSet.getResources().remove(resource);
			}
			final IResourceDescription oldDescription = oldState.getResourceDescription(uri);
			if (oldDescription != null) {
				newState.register(new DefaultResourceDescriptionDelta(oldDescription, null));
			}
		}
	} finally {
		progress.worked(1);
	}
}
 
Example #9
Source File: DefaultResourceDescriptionManagerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testIsAffected() {
	DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(null, resourceDescription);
	assertFalse(manager.isAffected(delta, resourceDescription));
	importedNames = Collections.singleton(QualifiedName.create("eclass"));
	assertTrue(manager.isAffected(delta, resourceDescription));
	importedNames = Collections.singleton(QualifiedName.create("ECLASS"));
	assertFalse(manager.isAffected(delta, resourceDescription));
}
 
Example #10
Source File: JavaResourceDescriptionManager.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IResourceDescription.Delta createDelta(IResourceDescription oldDescription,
		IResourceDescription newDescription) {
	return new DefaultResourceDescriptionDelta(oldDescription, newDescription);
}
 
Example #11
Source File: DocumentBasedDirtyResourceTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Delta createDelta(IResourceDescription oldDescription, IResourceDescription newDescription) {
	return new DefaultResourceDescriptionDelta(oldDescription, newDescription);
}
 
Example #12
Source File: DirtyStateEditorSupportTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Delta createDelta(IResourceDescription oldDescription, IResourceDescription newDescription) {
	return new DefaultResourceDescriptionDelta(oldDescription, newDescription);
}
 
Example #13
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create new resource descriptions for a set of resources given by their URIs.
 *
 * @param buildData
 *            The underlying data for the write operation.
 * @param oldState
 *            The old index
 * @param newState
 *            The new index
 * @param monitor
 *            The progress monitor used for user feedback
 */
protected void writeNewResourceDescriptions(
        BuildData buildData,
        IResourceDescriptions oldState,
        CurrentDescriptions newState,
        final IProgressMonitor monitor) {
    int index = 0;
    ResourceSet resourceSet = buildData.getResourceSet();
    Set<URI> toBeUpdated = buildData.getToBeUpdated();
    final SubMonitor subMonitor = SubMonitor.convert(monitor, "Write new resource descriptions", toBeUpdated.size() + 1); // TODO: NLS
    IProject currentProject = getBuiltProject(buildData);
    LoadOperation loadOperation = null;
    try {
    	compilerPhases.setIndexing(resourceSet, true);
        loadOperation = globalIndexResourceLoader.create(resourceSet, currentProject);
        loadOperation.load(toBeUpdated);

        while (loadOperation.hasNext()) {
            if (subMonitor.isCanceled()) {
                loadOperation.cancel();
                throw new OperationCanceledException();
            }

            if (!clusteringPolicy.continueProcessing(resourceSet, null, index)) {
                clearResourceSet(resourceSet);
            }

            URI uri = null;
            Resource resource = null;
            try {
                LoadResult loadResult = loadOperation.next();
                uri = loadResult.getUri();
                resource = addResource(loadResult.getResource(), resourceSet);
                subMonitor.subTask("Writing new resource description " + resource.getURI().lastSegment());
                if (LOGGER.isDebugEnabled()) {
                	LOGGER.debug("Writing new resource description " + uri);
                }

                final IResourceDescription.Manager manager = getResourceDescriptionManager(uri);
                if (manager != null) {
                    // We don't care here about links, we really just want the exported objects so that we can link in the
                    // next phase.
                    final IResourceDescription description = manager.getResourceDescription(resource);
                    final IResourceDescription copiedDescription = new CopiedResourceDescription(description);
                    // We also don't care what kind of Delta we get here; it's just a temporary transport vehicle. That interface
                    // could do with some clean-up, too, because all we actually want to do is register the new resource
                    // description, not the delta.
                    newState.register(new DefaultResourceDescriptionDelta(oldState.getResourceDescription(uri), copiedDescription));
                    buildData.queueURI(uri);
                }
            } catch (final RuntimeException ex) {
                if(ex instanceof LoadOperationException) {
                    uri = ((LoadOperationException) ex).getUri();
                }
                if (uri == null) {
                    LOGGER.error("Error loading resource", ex); //$NON-NLS-1$
                } else {
                    if (resourceSet.getURIConverter().exists(uri, Collections.emptyMap())) {
                        LOGGER.error("Error loading resource from: " + uri.toString(), ex); //$NON-NLS-1$
                    }
                    if (resource != null) {
                        resourceSet.getResources().remove(resource);
                    }
                    final IResourceDescription oldDescription = oldState.getResourceDescription(uri);
                    if (oldDescription != null) {
                        newState.register(new DefaultResourceDescriptionDelta(oldDescription, null));
                    }
                }
                // If we couldn't load it, there's no use trying again: do not add it to the queue
            }
            index++;
            subMonitor.split(1);
        }
    } finally {
    	compilerPhases.setIndexing(resourceSet, false);
        if(loadOperation != null) loadOperation.cancel();
    }
}
 
Example #14
Source File: GenericResourceDescriptionManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Delta createDelta(IResourceDescription oldDescription, IResourceDescription newDescription) {
	return new DefaultResourceDescriptionDelta(oldDescription, newDescription);
}