Search in sources :

Example 6 with ResourceDescriptionChangeEvent

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();
}
Also used : IResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.IResourceDescriptionsData) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) NullResourceDescriptionsData(com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) SubMonitor(org.eclipse.core.runtime.SubMonitor) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) URI(org.eclipse.emf.common.util.URI) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 7 with ResourceDescriptionChangeEvent

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();
    }
}
Also used : AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) NullResourceDescriptionsData(com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 8 with ResourceDescriptionChangeEvent

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();
}
Also used : IResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.IResourceDescriptionsData) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) NullResourceDescriptionsData(com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) SubMonitor(org.eclipse.core.runtime.SubMonitor) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 9 with ResourceDescriptionChangeEvent

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);
}
Also used : CoarseGrainedChangeEvent(org.eclipse.xtext.resource.impl.CoarseGrainedChangeEvent) Function(com.google.common.base.Function) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) ChangedResourceDescriptionDelta(org.eclipse.xtext.resource.impl.ChangedResourceDescriptionDelta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 10 with ResourceDescriptionChangeEvent

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)));
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Aggregations

ResourceDescriptionChangeEvent (org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)10 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)4 DefaultResourceDescriptionDelta (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta)4 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)4 NullResourceDescriptionsData (com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData)3 AbstractResourceDescriptionsData (com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData)3 ChangedResourceDescriptionDelta (org.eclipse.xtext.resource.impl.ChangedResourceDescriptionDelta)3 IResourceDescriptionsData (com.avaloq.tools.ddk.xtext.extensions.IResourceDescriptionsData)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 URI (org.eclipse.emf.common.util.URI)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 CoarseGrainedChangeEvent (org.eclipse.xtext.resource.impl.CoarseGrainedChangeEvent)1 ResourceDescriptionsBasedContainerTest (org.eclipse.xtext.resource.impl.ResourceDescriptionsBasedContainerTest)1 Test (org.junit.Test)1