Java Code Examples for org.eclipse.emf.ecore.resource.ResourceSet#eSetDeliver()

The following examples show how to use org.eclipse.emf.ecore.resource.ResourceSet#eSetDeliver() . 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: N4JSResourceSetCleanerUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes all non-N4 resources from the given resource set without sending any notification about the removal. This
 * specific resource set cleaning is required to avoid the accidental removal of the resources holding the built-in
 * types. For more details reference: IDEBUG-491.
 *
 * @param resourceSet
 *            the resource set to clean. Optional, can be {@code null}. If {@code null} this method has no effect.
 */
/* default */static void clearResourceSet(final ResourceSet resourceSet) {
	boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		// iterate backwards to avoid costly shuffling in the underlying list
		EList<Resource> resources = resourceSet.getResources();
		// int originalSize = resources.size();
		for (int i = resources.size() - 1; i >= 0; i--) {
			final Resource resource = resources.get(i);
			final URI uri = resource.getURI();
			if (!isN4Scheme(uri)) {
				resources.remove(i);
			} else {
				LOGGER.info("Intentionally skipping the removal of N4 resource: " + uri);
			}
		}
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}
 
Example 2
Source File: AbstractSmokeTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void doParseAndCheckForSmokeWithoutResourceSet(final String model) throws Exception {
	try {
		LazyLinkingResource resource = createResource(model);
		// simulate closed editor
		ResourceSet resourceSet = resource.getResourceSet();
		resourceSet.eSetDeliver(false);
		resourceSet.getResources().clear();
		resourceSet.eAdapters().clear();
		checkForSmoke(model, resource);
	} catch (Throwable e) {
		e.printStackTrace();
		assertEquals(e.getMessage()+" : Model was : \n\n"+model, model, "");
		// just to make sure we fail for empty model, too
		fail(e.getMessage()+" : Model was : \n\n"+model);
	}
}
 
Example 3
Source File: N4ClusteringBuilderState.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Clears the content of the resource set without sending notifications. This avoids unnecessary, explicit unloads.
 */
protected void clearResourceSet(ResourceSet resourceSet) {
	boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		resourceSet.getResources().clear();
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}
 
Example 4
Source File: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clears the content of the resource set without sending notifications.
 * This avoids unnecessary, explicit unloads.
 */
public void clearResourceSet(ResourceSet resourceSet) {
	boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		resourceSet.getResources().clear();
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}
 
Example 5
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clears the content of the resource set without sending notifications.
 * This avoids unnecessary, explicit unloads.
 */
protected void clearResourceSet(ResourceSet resourceSet) {
    boolean wasDeliver = resourceSet.eDeliver();
    try {
        resourceSet.eSetDeliver(false);
        for (Resource resource : resourceSet.getResources()) {
            resource.eSetDeliver(false);
        }
        resourceSet.getResources().clear();
    } finally {
        resourceSet.eSetDeliver(wasDeliver);
    }
}
 
Example 6
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clears the content of the resource set without sending notifications.
 * This avoids unnecessary, explicit unloads.
 * @since 2.7
 */
protected void clearResourceSet(ResourceSet resourceSet) {
	boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		for (Resource resource : resourceSet.getResources()) {
			resource.eSetDeliver(false);
		}
		resourceSet.getResources().clear();
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}
 
Example 7
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param toBeBuilt
 *            the URIs that will be processed in this build run.
 * @param removedProjects
 *            the projects that are no longer considered by XtextBuilders but are yet to be removed from the index.
 * @param monitor
 *            the progress monitor for the build.
 * @param type
 *            indicates the kind of build that is running.
 * 
 * @since 2.18
 */
protected void doBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor, BuildType type) throws CoreException {
	buildLogger.log("Building " + getProject().getName());
	// return early if there's nothing to do.
	// we reuse the isEmpty() impl from BuildData assuming that it doesnT access the ResourceSet which is still null 
	// and would be expensive to create.
	boolean indexingOnly = type == BuildType.RECOVERY;
	if (new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects).isEmpty())
		return;
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	ResourceSet resourceSet = getResourceSetProvider().get(getProject());
	resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
	BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects);
	ImmutableList<Delta> deltas = builderState.update(buildData, progress.split(1));
	if (participant != null && !indexingOnly) {
		SourceLevelURICache sourceLevelURIs = buildData.getSourceLevelURICache();
		Set<URI> sources = sourceLevelURIs.getSources();
		participant.build(new BuildContext(this, resourceSet, deltas, sources, type),
				progress.split(1));
		try {
			getProject().getWorkspace().checkpoint(false);
		} catch(NoClassDefFoundError e) { // guard against broken Eclipse installations / bogus project configuration
			log.error(e.getMessage(), e);
		}
	} else {
		progress.worked(1);
	}
	resourceSet.eSetDeliver(false);
	for (Resource resource : resourceSet.getResources()) {
		resource.eSetDeliver(false);
	}
	resourceSet.getResources().clear();
	resourceSet.eAdapters().clear();
}
 
Example 8
Source File: EmfResourceSetUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Clear the contents of the given {@link ResourceSet} without sending any notifications to the {@link ResourceSet}'s adapters.
 *
 * @param resourceSet
 *          the {@link ResourceSet} to be cleared, must not be {@code null}
 */
public static void clearResourceSetWithoutNotifications(final ResourceSet resourceSet) {
  boolean wasDeliver = resourceSet.eDeliver();
  try {
    resourceSet.eSetDeliver(false);
    clearResourceSet(resourceSet);
  } finally {
    resourceSet.eSetDeliver(wasDeliver);
  }
}
 
Example 9
Source File: GamlResourceInfoProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
protected void clearResourceSet(final ResourceSet resourceSet) {
	final boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		resourceSet.getResources().clear();
	} catch (final Exception e) {}

	finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}
 
Example 10
Source File: GamlResourceIndexer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void clearResourceSet(final ResourceSet resourceSet) {
	final boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		resourceSet.getResources().clear();
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}