From 7e5a4f708c59affed216f9516bbcbcbca018b10f Mon Sep 17 00:00:00 2001 From: Sebastian Zarnekow Date: Wed, 26 Oct 2011 13:24:30 +0200 Subject: [PATCH] [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) --- .../linking/lazy/LazyLinkingResource.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java index ee31f9cbb..75d6b8a63 100644 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java +++ b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java @@ -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 unresolveableProxies = getCache().get("UNRESOLVEABLE_PROXIES", this, -// new Provider>() { -// public Set get() { -// return Sets.newHashSet(); -// } -// }); -// if (unresolveableProxies.contains(uriFragment)) -// return null; + Set unresolveableProxies = getCache().get("UNRESOLVEABLE_PROXIES", this, + new Provider>() { + public Set get() { + return Sets.newHashSet(); + } + }); + if (unresolveableProxies.contains(uriFragment)) + return null; EReference reference = triple.getSecond(); List 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 triple) { + return true; + } + protected EObject handleCyclicResolution(Triple triple) throws AssertionError { throw new AssertionError("Cyclic resolution of lazy links : " + getReferences(triple, resolving)); }