mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[xbase] Enabled caching of unresolvable references to JvmTypes
This improves the performance vastly for resources with a lot of unknown type references (e.g. copy'n'paste code from a bugzilla without import statements)
This commit is contained in:
parent
56c7f5c35e
commit
7e5a4f708c
1 changed files with 19 additions and 11 deletions
|
@ -14,6 +14,7 @@ import java.util.Collections;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.emf.common.util.TreeIterator;
|
||||
|
@ -41,6 +42,7 @@ import org.eclipse.xtext.util.Triple;
|
|||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -161,19 +163,20 @@ public class LazyLinkingResource extends XtextResource {
|
|||
try {
|
||||
if (!resolving.add(triple))
|
||||
return handleCyclicResolution(triple);
|
||||
// Set<String> unresolveableProxies = getCache().get("UNRESOLVEABLE_PROXIES", this,
|
||||
// new Provider<Set<String>>() {
|
||||
// public Set<String> get() {
|
||||
// return Sets.newHashSet();
|
||||
// }
|
||||
// });
|
||||
// if (unresolveableProxies.contains(uriFragment))
|
||||
// return null;
|
||||
Set<String> unresolveableProxies = getCache().get("UNRESOLVEABLE_PROXIES", this,
|
||||
new Provider<Set<String>>() {
|
||||
public Set<String> get() {
|
||||
return Sets.newHashSet();
|
||||
}
|
||||
});
|
||||
if (unresolveableProxies.contains(uriFragment))
|
||||
return null;
|
||||
EReference reference = triple.getSecond();
|
||||
List<EObject> linkedObjects = getLinkingService().getLinkedObjects(triple.getFirst(), reference,
|
||||
triple.getThird());
|
||||
if (linkedObjects.isEmpty()) {
|
||||
// unresolveableProxies.add(uriFragment);
|
||||
if (isUnresolveableProxyCacheable(triple))
|
||||
unresolveableProxies.add(uriFragment);
|
||||
createAndAddDiagnostic(triple);
|
||||
return null;
|
||||
}
|
||||
|
@ -185,12 +188,13 @@ public class LazyLinkingResource extends XtextResource {
|
|||
log.error("An element of type " + result.getClass().getName()
|
||||
+ " is not assignable to the reference " + reference.getEContainingClass().getName()
|
||||
+ "." + reference.getName());
|
||||
// unresolveableProxies.add(uriFragment);
|
||||
if (isUnresolveableProxyCacheable(triple))
|
||||
unresolveableProxies.add(uriFragment);
|
||||
createAndAddDiagnostic(triple);
|
||||
return null;
|
||||
}
|
||||
// remove previously added error markers, since everything should be fine now
|
||||
// unresolveableProxies.remove(uriFragment);
|
||||
unresolveableProxies.remove(uriFragment);
|
||||
removeDiagnostic(triple);
|
||||
return result;
|
||||
} finally {
|
||||
|
@ -207,6 +211,10 @@ public class LazyLinkingResource extends XtextResource {
|
|||
return super.getEObject(uriFragment);
|
||||
}
|
||||
|
||||
protected boolean isUnresolveableProxyCacheable(Triple<EObject, EReference, INode> triple) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected EObject handleCyclicResolution(Triple<EObject, EReference, INode> triple) throws AssertionError {
|
||||
throw new AssertionError("Cyclic resolution of lazy links : " + getReferences(triple, resolving));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue