mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[xbase][typesystem] Guard against concurrent resolution
Should prevent dead locks and other surprises.
This commit is contained in:
parent
d802e2cc88
commit
2d15d4e65a
2 changed files with 39 additions and 1 deletions
|
@ -10,11 +10,14 @@ import org.eclipse.emf.common.util.AbstractEList;
|
|||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
public class SynchronizedXtextResourceSet extends XtextResourceSet {
|
||||
public class SynchronizedXtextResourceSet extends XtextResourceSet implements ISynchronizable<SynchronizedXtextResourceSet> {
|
||||
private final Object lock = new Object();
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +39,27 @@ public class SynchronizedXtextResourceSet extends XtextResourceSet {
|
|||
public EList<Resource> getResources() {
|
||||
return super.getResources();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronization lock that works for the complete resource set.
|
||||
* @since 2.4
|
||||
*/
|
||||
@NonNull
|
||||
public Object getLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public <Result> Result execute(IUnitOfWork<Result, ? super SynchronizedXtextResourceSet> unit) throws Exception {
|
||||
synchronized (getLock()) {
|
||||
return unit.exec(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.4
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.emf.common.util.TreeIterator;
|
|||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.xtext.Constants;
|
||||
import org.eclipse.xtext.diagnostics.Severity;
|
||||
|
@ -285,6 +286,19 @@ public class XtextResource extends ResourceImpl {
|
|||
|
||||
@Override
|
||||
public EObject getEObject(String uriFragment) {
|
||||
return basicGetEObject(uriFragment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a fragment to an {@link EObject}. The returned object is not necessarily
|
||||
* contained in this resource. It may resolve to a different one, instead.
|
||||
* The result may be <code>null</code>.
|
||||
*
|
||||
* @see ResourceImpl#getEObject(String)
|
||||
* @see IFragmentProvider
|
||||
* @since 2.4
|
||||
*/
|
||||
protected EObject basicGetEObject(@NonNull String uriFragment) {
|
||||
if (fragmentProvider != null) {
|
||||
EObject result = fragmentProvider.getEObject(this, uriFragment, fragmentProviderFallback);
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue