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

The following examples show how to use org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent. 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: DirtyStateManager.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.22
 */
protected void notifyListeners(IResourceDescription prevDirtyDescription, IDirtyResource dirtyResource) {
	IResourceDescription.Delta delta = new IResourceDescription.Delta() {
		@Override
		public boolean haveEObjectDescriptionsChanged() {
			return true;
		}
		
		@Override
		public IResourceDescription getOld() {
			return prevDirtyDescription;
		}
		
		@Override
		public IResourceDescription getNew() {
			return dirtyResource.getDescription();
		}

		@Override
		public URI getUri() {
			return dirtyResource.getURI();
		}
	};
	notifyListeners(new ResourceDescriptionChangeEvent(Collections.singletonList(delta)));
}
 
Example #2
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected Pair<IResourceDescription.Event, Integer> mergePendingDeltas() {
	Map<URI, IResourceDescription.Delta> uriToDelta = Maps.newLinkedHashMap();
	Iterator<IResourceDescription.Delta> iter = pendingChanges.iterator();
	int size = 0;
	while(iter.hasNext()) {
		IResourceDescription.Delta delta = iter.next();
		URI uri = delta.getUri();
		IResourceDescription.Delta prev = uriToDelta.get(uri);
		if (prev == null) {
			uriToDelta.put(uri, delta);
		} else if (prev.getOld() != delta.getNew()){
			uriToDelta.put(uri, createDelta(delta, prev));
		} else {
			uriToDelta.remove(uri);
		}
		size++;
	}
	IResourceDescription.Event event = new ResourceDescriptionChangeEvent(uriToDelta.values());
	return Tuples.create(event, size);
}
 
Example #3
Source File: DirtyStateAwareResourceDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: AbstractBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public synchronized ImmutableList<IResourceDescription.Delta> update(BuildData buildData, IProgressMonitor monitor) {
	ensureLoaded();
	final SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.AbstractBuilderState_0, 1);
	subMonitor.subTask(Messages.AbstractBuilderState_0);
	if (buildData.isEmpty())
		return ImmutableList.of();
	if (monitor.isCanceled())
		throw new OperationCanceledException();

	final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
	final Collection<IResourceDescription.Delta> result = doUpdate(buildData, newData, subMonitor.split(1));

	if (monitor.isCanceled())
		throw new OperationCanceledException();
	final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
	// update the reference
	setResourceDescriptionsData(newData);
	notifyListeners(event);
	return event.getDeltas();
}
 
Example #5
Source File: DirtyStateAwareResourceDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void globalDescriptionsChanged(IResourceDescription.Event event) {
	ResourceDescriptionChangeEvent changeEvent = new ResourceDescriptionChangeEvent(
			Iterables.filter(event.getDeltas(), new Predicate<IResourceDescription.Delta>() {
				@Override
				public boolean apply(Delta input) {
					URI uri = input.getUri();
					return !dirtyStateManager.hasContent(uri);
				}
			}));
	notifyListeners(changeEvent);
}
 
Example #6
Source File: StateBasedContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Test public void testBug352214() {
	container.getResourceDescriptions(); // initialize uri map
	ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(Collections.<IResourceDescription.Delta>singletonList(
			new ChangedResourceDescriptionDelta(resourceDescription, null)));
	simulateEmpty = true;
	container.descriptionsChanged(event);
	assertEquals(0, container.getResourceDescriptionCount());
	assertTrue(Iterables.all(container.getResourceDescriptions(), Predicates.notNull()));
	assertFalse(container.hasResourceDescription(uri)); 
	assertNull(container.getResourceDescription(uri));
}
 
Example #7
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@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)) {
      LOGGER.error("Failed to update index. Executing rollback.", t); //$NON-NLS-1$
    }
    if (newData instanceof AbstractResourceDescriptionsData) {
      ((AbstractResourceDescriptionsData) newData).rollbackChanges();
    }
    throw t;
  }

  final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
  notifyListeners(event);
  return event.getDeltas();
}
 
Example #8
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@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();

  checkForCancellation(monitor);
  try {
    for (IResourceDescription.Delta delta : deltas) {
      newData.removeDescription(delta.getOld().getURI());
    }
    ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(deltas);
    checkForCancellation(monitor);
    updateDeltas(event.getDeltas(), null, subMonitor.newChild(1));
    // update the reference
    setResourceDescriptionsData(newData, monitor);
    // CHECKSTYLE:CHECK-OFF IllegalCatch
    notifyListeners(event);
    return event.getDeltas();
  } catch (Throwable t) {
    // CHECKSTYLE:CHECK-ON IllegalCatch
    if (newData instanceof AbstractResourceDescriptionsData) {
      ((AbstractResourceDescriptionsData) newData).rollbackChanges();
    }
    throw t;
  }
}
 
Example #9
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc} Schedules a full clean build if the target platform changes.
 */
@Override
public void platformChanged(final IXtextTargetPlatform 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!
    setDerivedObjectAssociationsStore(null);
    setResourceDescriptionsData(new NullResourceDescriptionsData());
    isBinaryModelStorageAvailable = false;
    return;
  }
  // Deltas?
  if (isLoaded()) {
    // If we're not loaded yet, then this event is due to the initial loading of the platform in super.load. In this case,
    // we are in a build anyway, aren't we?
    // TODO: this is pretty convoluted. We should try to disentangle this OO spaghetti code. Is it good enough to simply not notify listeners in
    // AbstractXtextTargetPlatformManager if it was the initial load?
    ResourceDescriptionsData data = (ResourceDescriptionsData) newPlatform.getIResourceDescriptionsData();
    if (data instanceof AbstractResourceDescriptionsData) {
      ((AbstractResourceDescriptionsData) data).beginChanges();
    }
    setDerivedObjectAssociationsStore(newPlatform.getAssociationsStore());
    setResourceDescriptionsData(data);
    updateBinaryStorageAvailability(newPlatform);
    ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(deltas);
    notifyListeners(event);
  }
  if (mustRebuild) {
    buildTrigger.scheduleFullBuild();
  }
}
 
Example #10
Source File: PrevStateAwareDirtyStateManager.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private void notifyListeners(IResourceDescription.Delta delta) {
	notifyListeners(new ResourceDescriptionChangeEvent(Collections.singletonList(delta)));
}
 
Example #11
Source File: TypeResourceUnloader.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private IResourceDescription.Event getAsResourceDescriptionChange(IJavaElementDelta delta) {
	List<IResourceDescription.Delta> deltas = deltaConverter.convert(delta);
	if (deltas == null || deltas.isEmpty())
		return null;
	return new ResourceDescriptionChangeEvent(deltas);
}