Java Code Examples for org.eclipse.xtext.resource.IResourceDescription#Event

The following examples show how to use org.eclipse.xtext.resource.IResourceDescription#Event . 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: 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 2
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 3
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isReparseRequired(XtextResource resource, IResourceDescription.Event event) {
	IResourceDescription.Manager resourceDescriptionManager = resource.getResourceServiceProvider().getResourceDescriptionManager();
	IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
	if (resourceDescriptionManager.isAffected(event.getDeltas(), description, resourceDescriptions)) {
		return true;
	}
	if (!isDirty() && !dirtyStateManager.hasContent(resource.getURI())) {
		IResourceDescription originalDescription = resourceDescriptions.getResourceDescription(resource.getURI());
		if (originalDescription != null && descriptionUtils != null) {
			Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(originalDescription);
			for(IResourceDescription.Delta delta: event.getDeltas()) {
				if (delta.haveEObjectDescriptionsChanged() && outgoingReferences.contains(delta.getUri()))
					return true;
			}
		}
	}
	return false;
}
 
Example 4
Source File: ResourceDescriptionsBasedContainer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void descriptionsChanged(IResourceDescription.Event event) {
	if (uriToDescription != null) {
		for(IResourceDescription.Delta delta: event.getDeltas()) {
			URI uri = delta.getUri();
			if (hasResourceDescription(uri) || uriToDescription.get(uri) != null) {
				if (delta.getNew() != null)
					uriToDescription.put(uri, delta.getNew());
				else
					uriToDescription.remove(uri);
			}
		}
	}
}
 
Example 5
Source File: AbstractResourceDescriptionChangeEventSource.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.5
 */
@Override
public void notifyListeners(IResourceDescription.Event event) {
	if (event == null)
		throw new IllegalArgumentException("event may not be null");
	for(IResourceDescription.Event.Listener listener: listenerList) {
		listener.descriptionsChanged(event);
	}
}
 
Example 6
Source File: XtendEditorChangingClasspathTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public IResourceDescription.Event waitForChangeEvent(final Procedure0 producer) {
  try {
    IResourceDescription.Event _xblockexpression = null;
    {
      final ArrayList<IResourceDescription.Event> event = CollectionLiterals.<IResourceDescription.Event>newArrayList();
      final ArrayList<Boolean> listenToEvent = CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(true));
      final IResourceDescription.Event.Listener _function = new IResourceDescription.Event.Listener() {
        @Override
        public void descriptionsChanged(final IResourceDescription.Event e) {
          Boolean _head = IterableExtensions.<Boolean>head(listenToEvent);
          if ((boolean) _head) {
            listenToEvent.set(0, Boolean.valueOf(false));
            event.add(e);
            XtendEditorChangingClasspathTest.this.stateChangeEventBroker.removeListener(this);
          }
        }
      };
      this.stateChangeEventBroker.addListener(_function);
      producer.apply();
      final int maxAttempts = 5;
      int attempt = 0;
      while (((IterableExtensions.<Boolean>head(listenToEvent)).booleanValue() && (attempt < maxAttempts))) {
        {
          Thread.sleep(50);
          attempt = (attempt + 1);
        }
      }
      _xblockexpression = IterableExtensions.<IResourceDescription.Event>head(event);
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: XtendEditorChangingClasspathTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public IResourceDescription.Event waitForCoarseGrainedEvent(final Procedure0 producer) {
  try {
    IResourceDescription.Event _xblockexpression = null;
    {
      final ArrayList<IResourceDescription.Event> event = CollectionLiterals.<IResourceDescription.Event>newArrayList();
      final ArrayList<Boolean> listenToEvent = CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(true));
      final IResourceDescription.Event.Listener _function = new IResourceDescription.Event.Listener() {
        @Override
        public void descriptionsChanged(final IResourceDescription.Event e) {
          if (((IterableExtensions.<Boolean>head(listenToEvent)).booleanValue() && (e instanceof IResourceDescription.CoarseGrainedEvent))) {
            listenToEvent.set(0, Boolean.valueOf(false));
            event.add(e);
            XtendEditorChangingClasspathTest.this.stateChangeEventBroker.removeListener(this);
          }
        }
      };
      this.stateChangeEventBroker.addListener(_function);
      producer.apply();
      final int maxAttempts = 5;
      int attempt = 0;
      while (((IterableExtensions.<Boolean>head(listenToEvent)).booleanValue() && (attempt < maxAttempts))) {
        {
          Thread.sleep(50);
          attempt = (attempt + 1);
        }
      }
      _xblockexpression = IterableExtensions.<IResourceDescription.Event>head(event);
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
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 9
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Collection<Resource> collectAffectedResources(XtextResource resource, IResourceDescription.Event event) {
	List<Resource> result = Lists.newArrayListWithExpectedSize(4);
	for(IResourceDescription.Delta delta: event.getDeltas()) {
		processDelta(delta, resource, result);
	}
	return result;
}
 
Example 10
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void scheduleUpdateEditorJob(final IResourceDescription.Event event) {
	UpdateEditorStateJob job = updateEditorStateJob;
	if (job == null) {
		job = createUpdateEditorJob();
		updateEditorStateJob = job;
	}
	job.scheduleFor(event); 
}
 
Example 11
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void descriptionsChanged(final IResourceDescription.Event event) {
	DocumentBasedDirtyResource resource = getDirtyResource();
	IResourceDescription description;
	synchronized(resource) {
		if (!resource.isInitialized())
			return;
		description = resource.getDescription();
	}
	for(IResourceDescription.Delta delta: event.getDeltas()) {
		if (delta.getOld() == description || delta.getNew() == description)
			return;
	}
	scheduleUpdateEditorJob(event);
}
 
Example 12
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void scheduleFor(IResourceDescription.Event event) {
	cancel();
	if (event instanceof IResourceDescription.CoarseGrainedEvent)
		coarseGrainedChanges.incrementAndGet();
	else
		pendingChanges.addAll(event.getDeltas());
	schedule(getDelay());
}
 
Example 13
Source File: TypeResourceUnloaderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void descriptionsChanged(IResourceDescription.Event event) {
	if (this.event != null && subsequentEvents != null) {
		subsequentEvents.add(event);
	}
	this.event = event;
}
 
Example 14
Source File: DirtyStateAwareResourceDescriptions2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void descriptionsChanged(final IResourceDescription.Event event) {
  for (Delta delta : event.getDeltas()) {
    IResourceDescription newDesc = delta.getNew();
    if (newDesc == null) {
      dirtyResources.remove(delta.getUri());
    } else {
      dirtyResources.add(delta.getUri());
    }
  }
  dirtyDescriptionsChanged(event);
}
 
Example 15
Source File: StateChangeEventBroker.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void descriptionsChanged(IResourceDescription.Event event) {
	notifyListeners(event);
}
 
Example 16
Source File: DirtyStateAwareResourceDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void descriptionsChanged(IResourceDescription.Event event) {
	dirtyDescriptionsChanged(event);
}
 
Example 17
Source File: DirtyStateAwareResourceDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void descriptionsChanged(IResourceDescription.Event event) {
	globalDescriptionsChanged(event);
}
 
Example 18
Source File: TypeResourceUnloader.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
	IResourceDescription.Event resourceDescriptionEvent = getAsResourceDescriptionChange(event.getDelta());
	if (resourceDescriptionEvent != null)
		notifyListeners(resourceDescriptionEvent);
}
 
Example 19
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);
}
 
Example 20
Source File: N4JSDirtyStateEditorSupport.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void scheduleFor(IResourceDescription.Event event) {
	super.scheduleFor(event);
}