org.eclipse.xtext.resource.ISynchronizable Java Examples

The following examples show how to use org.eclipse.xtext.resource.ISynchronizable. 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: CanLoadFromDescriptionHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a resource in the context of the given resource set. This is only necessary when working with
 * {@link UserDataAwareScope} where we don't use {@link ResourceSet#getResource(URI, boolean) getResource} but
 * {@link ResourceSet#createResource(URI) createResource} to implement a custom semantics with
 * {@link N4JSResource#loadFromDescription(IResourceDescription)}.
 *
 * It is not a generic replacement for all clients of the resource set.
 */
public Resource createResource(ResourceSet resourceSet, URI resourceURI) {
	/*
	 * Implementation note: In LSP we need to redirect the request to create a resource to a well defined resource
	 * set. LSP associates projects to resource sets and we have to make sure that we do not create resources in the
	 * wrong project context. Therefore this method if overridden for LSP.
	 */
	if (resourceSet instanceof ISynchronizable<?>) {
		synchronized (((ISynchronizable<?>) resourceSet).getLock()) {
			Resource resource = resourceSet.getResource(resourceURI, false);
			if (resource == null) {
				resource = resourceSet.createResource(resourceURI);
			}
			return resource;
		}
	} else {
		return resourceSet.createResource(resourceURI);
	}
}
 
Example #2
Source File: BatchLinkableResource.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the lock of the owning {@link ResourceSet}, if it exposes such a lock.
 * Otherwise this resource itself is used as the lock context.
 */
/* @NonNull */
@Override
public Object getLock() {
	ResourceSet resourceSet = getResourceSet();
	if (resourceSet instanceof ISynchronizable<?>) {
		return ((ISynchronizable<?>) resourceSet).getLock();
	}
	return this;
}
 
Example #3
Source File: JavaResource.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the lock of the owning {@link ResourceSet}, if it exposes such a lock. Otherwise this resource itself is
 * used as the lock context.
 */
@Override
public Object getLock() {
	ResourceSet resourceSet = getResourceSet();
	if (resourceSet instanceof ISynchronizable<?>) {
		return ((ISynchronizable<?>) resourceSet).getLock();
	}
	return this;
}
 
Example #4
Source File: TypeResource.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the lock of the owning {@link ResourceSet}, if it exposes such a lock.
 * Otherwise this resource itself is used as the lock context.
 */
/* @NonNull */
@Override
public Object getLock() {
	ResourceSet resourceSet = getResourceSet();
	if (resourceSet instanceof ISynchronizable<?>) {
		return ((ISynchronizable<?>) resourceSet).getLock();
	}
	return this;
}
 
Example #5
Source File: XtextDocument.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private Object getResourceLock(XtextResource r) {
	if (r != null) {
		return (r instanceof ISynchronizable<?>) ? ((ISynchronizable<?>) r).getLock() : r;
	} else {
		return this;
	}
}
 
Example #6
Source File: AbstractN4JSCore.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public TModule loadModuleFromIndex(final ResourceSet resourceSet,
		final IResourceDescription resourceDescription, boolean allowFullLoad) {
	final URI resourceURI = resourceDescription.getURI();
	Resource resource = resourceSet.getResource(resourceURI, false);
	TModule result = loadModuleFromResource(resource);
	if (result != null) {
		return result;
	}
	if (resource == null) {
		if (resourceSet instanceof ISynchronizable<?>) {
			synchronized (((ISynchronizable<?>) resourceSet).getLock()) {
				resource = resourceSet.getResource(resourceURI, false);
				result = loadModuleFromResource(resource);
				if (result != null) {
					return result;
				}
				if (resource == null) {
					resource = resourceSet.createResource(resourceURI);
				}
			}
		} else {
			resource = resourceSet.createResource(resourceURI);
		}
	}
	if (resource instanceof N4JSResource) {
		if (resource.getContents().isEmpty()) {
			final N4JSResource casted = (N4JSResource) resource;
			try {
				if (casted.loadFromDescription(resourceDescription)) {
					casted.performPostProcessing();
					return casted.getModule();
				} else if (allowFullLoad) {
					casted.unload();
					casted.load(resourceSet.getLoadOptions());
					casted.installDerivedState(false);
					return casted.getModule();
				}
			} catch (final Exception e) {
				casted.unload();
				return null;
			}
		}
	}
	return null;
}
 
Example #7
Source File: CachingBatchTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Object getLock() {
	if (resource instanceof ISynchronizable<?>) {
		return ((ISynchronizable<?>) resource).getLock();
	}
	return resource;
}