use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project dsl-devkit by dsldevkit.
the class MonitoredClusteringBuilderState method clean.
@Override
public synchronized ImmutableList<IResourceDescription.Delta> clean(final Set<URI> toBeRemoved, final IProgressMonitor monitor) {
ensureLoaded();
Set<URI> toBeRemovedCopy = ensureNotNull(toBeRemoved);
SubMonitor subMonitor = SubMonitor.convert(monitor, org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0, 2);
subMonitor.subTask(org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0);
if (toBeRemovedCopy.isEmpty()) {
return ImmutableList.of();
}
checkForCancellation(monitor);
Collection<IResourceDescription.Delta> deltas = doClean(toBeRemovedCopy, subMonitor.newChild(1));
final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
ResourceDescriptionChangeEvent event = null;
try {
checkForCancellation(monitor);
for (IResourceDescription.Delta delta : deltas) {
newData.removeDescription(delta.getOld().getURI());
}
event = new ResourceDescriptionChangeEvent(deltas);
checkForCancellation(monitor);
updateDeltas(event.getDeltas(), null, subMonitor.newChild(1));
// update the reference
setResourceDescriptionsData(newData, monitor);
// CHECKSTYLE:CHECK-OFF IllegalCatch
} catch (Throwable t) {
// CHECKSTYLE:CHEKC-ON IllegalCatch
if (newData instanceof AbstractResourceDescriptionsData) {
((AbstractResourceDescriptionsData) newData).rollbackChanges();
}
throw t;
}
notifyListeners(event);
return event.getDeltas();
}
use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project dsl-devkit by dsldevkit.
the class MonitoredClusteringBuilderState method platformChanged.
/**
* {@inheritDoc} Schedules a full clean build if the target platform changes.
*/
@Override
public void platformChanged(final IResourceDescriptionsData newPlatform, final Collection<Delta> deltas, final boolean mustRebuild) {
if (newPlatform == null) {
// Hmmm... context deactivated. Events for removing the project from the index will be generated anyway, so no build necessary.
// TODO: check!
setResourceDescriptionsData(new NullResourceDescriptionsData());
return;
}
// Deltas?
if (isLoaded()) {
// AbstractXtextTargetPlatformManager if it was the initial load?
if (newPlatform instanceof AbstractResourceDescriptionsData) {
((AbstractResourceDescriptionsData) newPlatform).beginChanges();
}
setResourceDescriptionsData((ResourceDescriptionsData) newPlatform);
ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(deltas);
notifyListeners(event);
}
if (mustRebuild) {
buildTrigger.scheduleFullBuild();
}
}
use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project dsl-devkit by dsldevkit.
the class MonitoredClusteringBuilderState method update.
@Override
@SuppressWarnings("PMD.AvoidInstanceofChecksInCatchClause")
public synchronized ImmutableList<Delta> update(final BuildData buildData, final IProgressMonitor monitor) {
ensureLoaded();
final SubMonitor subMonitor = SubMonitor.convert(monitor, org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0, 1);
subMonitor.subTask(org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0);
checkForCancellation(monitor);
final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
Collection<IResourceDescription.Delta> result = null;
try {
result = doUpdate(buildData, newData, subMonitor.newChild(1));
// update the reference
setResourceDescriptionsData(newData, monitor);
// CHECKSTYLE:CHECK-OFF IllegalCatch
} catch (Throwable t) {
// CHECKSTYLE:CHECK-ON IllegalCatch
if (!operationCanceledManager.isOperationCanceledException(t)) {
// $NON-NLS-1$
LOGGER.error("Failed to update index. Executing rollback.", t);
}
if (newData instanceof AbstractResourceDescriptionsData) {
((AbstractResourceDescriptionsData) newData).rollbackChanges();
}
throw t;
}
final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
notifyListeners(event);
return event.getDeltas();
}
use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-eclipse by eclipse.
the class DirtyStateAwareResourceDescriptions method dirtyDescriptionsChanged.
public void dirtyDescriptionsChanged(IResourceDescription.Event event) {
if (event instanceof CoarseGrainedChangeEvent) {
notifyListeners(event);
return;
}
ResourceDescriptionChangeEvent changeEvent = new ResourceDescriptionChangeEvent(Iterables.transform(event.getDeltas(), new Function<IResourceDescription.Delta, IResourceDescription.Delta>() {
@Override
public IResourceDescription.Delta apply(IResourceDescription.Delta from) {
IResourceDescription.Delta result = from;
if (from.getNew() == null) {
result = createDelta(from.getOld(), globalDescriptions.getResourceDescription(from.getUri()));
} else if (from.getOld() == null) {
result = createDelta(globalDescriptions.getResourceDescription(from.getUri()), from.getNew());
}
return result;
}
}));
notifyListeners(changeEvent);
}
use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-eclipse by eclipse.
the class DirtyStateManager method notifyListeners.
protected void notifyListeners(final IDirtyResource dirtyResource, boolean managed) {
if (managed) {
IResourceDescription.Delta delta = new IResourceDescription.Delta() {
@Override
public boolean haveEObjectDescriptionsChanged() {
return true;
}
@Override
public IResourceDescription getOld() {
return null;
}
@Override
public IResourceDescription getNew() {
return dirtyResource.getDescription();
}
@Override
public URI getUri() {
return dirtyResource.getURI();
}
};
notifyListeners(new ResourceDescriptionChangeEvent(Collections.singletonList(delta)));
} else {
IResourceDescription.Delta delta = new IResourceDescription.Delta() {
@Override
public boolean haveEObjectDescriptionsChanged() {
return true;
}
@Override
public IResourceDescription getOld() {
return dirtyResource.getDescription();
}
@Override
public IResourceDescription getNew() {
return null;
}
@Override
public URI getUri() {
return dirtyResource.getURI();
}
};
notifyListeners(new ResourceDescriptionChangeEvent(Collections.singletonList(delta)));
}
}
Aggregations