From 391a8bedbaba71abca2930037fdbf7c6da115a0c Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 10 Oct 2011 16:28:57 +0200 Subject: [PATCH] cache gdk methods not only by name, but also by type --- .../lang/resolve/GdkMethodDslProvider.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/GdkMethodDslProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/GdkMethodDslProvider.java index 65030b728a6d..767dc1ddb53f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/GdkMethodDslProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/GdkMethodDslProvider.java @@ -26,6 +26,7 @@ import com.intellij.psi.scope.NameHint; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.*; +import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.dsl.GdslMembersHolderConsumer; @@ -97,7 +98,7 @@ public class GdkMethodDslProvider implements GdslMembersProvider { } private static class GdkMethodHolder { - private final MultiMap originalMethodsByName; + private final ConcurrentFactoryMap> originalMethodsByNameAndType; private final NotNullLazyValue> originalMethodByType; private final boolean myStatic; private final GlobalSearchScope myScope; @@ -114,13 +115,23 @@ public class GdkMethodDslProvider implements GdslMembersProvider { byName.putValue(m.getName(), m); } - this.originalMethodsByName = byName; this.originalMethodByType = new VolatileNotNullLazyValue>() { @NotNull @Override protected MultiMap compute() { MultiMap map = new MultiMap(); - for (PsiMethod method : originalMethodsByName.values()) { + for (PsiMethod method : byName.values()) { + map.putValue(getCategoryTargetType(method).getCanonicalText(), method); + } + return map; + } + }; + + originalMethodsByNameAndType = new ConcurrentFactoryMap>() { + @Override + protected MultiMap create(String name) { + MultiMap map = new MultiMap(); + for (PsiMethod method : byName.get(name)) { map.putValue(getCategoryTargetType(method).getCanonicalText(), method); } return map; @@ -139,20 +150,13 @@ public class GdkMethodDslProvider implements GdslMembersProvider { NameHint nameHint = processor.getHint(NameHint.KEY); String name = nameHint == null ? null : nameHint.getName(state); - if (name != null) { - for (PsiMethod method : originalMethodsByName.get(name)) { - if (getCategoryTargetType(method).isAssignableFrom(psiType)) { - if (!processor.execute(GrGdkMethodImpl.createGdkMethod(method, myStatic), state)) { - return false; - } - } - } - + final MultiMap map = name != null ? originalMethodsByNameAndType.get(name) : originalMethodByType.getValue(); + if (map.isEmpty()) { return true; } for (String superType : ResolveUtil.getAllSuperTypes(psiType, descriptor.getProject()).keySet()) { - for (PsiMethod method : originalMethodByType.getValue().get(superType)) { + for (PsiMethod method : map.get(superType)) { if (!processor.execute(GrGdkMethodImpl.createGdkMethod(method, myStatic), state)) { return false; }