properly cache result for different adapters in CompilerReferenceServiceImpl (IDEA...
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 6 Oct 2016 12:11:02 +0000 (15:11 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 6 Oct 2016 12:11:02 +0000 (15:11 +0300)
java/compiler/impl/src/com/intellij/compiler/CompilerReferenceServiceImpl.java

index fcb121d18861feedc07707bd8aa0d42fe1713f05..997d5b18f4101e55579bb3c93f008d0d1a03c728 100644 (file)
@@ -27,7 +27,11 @@ import com.intellij.openapi.vfs.*;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.util.*;
+import com.intellij.psi.util.CachedValueProvider;
+import com.intellij.psi.util.CachedValuesManager;
+import com.intellij.psi.util.ParameterizedCachedValue;
+import com.intellij.psi.util.PsiModificationTracker;
+import com.intellij.util.containers.ConcurrentFactoryMap;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.indexing.FileBasedIndex;
 import gnu.trove.THashSet;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.indexing.FileBasedIndex;
 import gnu.trove.THashSet;
@@ -143,19 +147,15 @@ public class CompilerReferenceServiceImpl extends CompilerReferenceService {
   public GlobalSearchScope getScopeWithoutCodeReferences(@NotNull PsiElement element, @NotNull CompilerSearchAdapter adapter) {
     if (!isServiceEnabled()) return null;
 
   public GlobalSearchScope getScopeWithoutCodeReferences(@NotNull PsiElement element, @NotNull CompilerSearchAdapter adapter) {
     if (!isServiceEnabled()) return null;
 
-    final ParameterizedCachedValueProvider<GlobalSearchScope, CompilerSearchAdapter> cachedValueProvider =
-      new ParameterizedCachedValueProvider<GlobalSearchScope, CompilerSearchAdapter>() {
-        @Nullable
-        @Override
-        public CachedValueProvider.Result<GlobalSearchScope> compute(CompilerSearchAdapter param) {
-          return CachedValueProvider.Result.create(calculateScopeWithoutReferences(element, param), PsiModificationTracker.MODIFICATION_COUNT);
-        }
-      };
-    return CachedValuesManager.getManager(myProject).getParameterizedCachedValue(element,
-                                                                                 CACHE_KEY,
-                                                                                 cachedValueProvider,
-                                                                                 false,
-                                                                                 adapter);
+    return CachedValuesManager.getCachedValue(element,
+                                              () -> CachedValueProvider.Result.create(new ConcurrentFactoryMap<CompilerSearchAdapter, GlobalSearchScope>() {
+                                                  @Nullable
+                                                  @Override
+                                                  protected GlobalSearchScope create(CompilerSearchAdapter key) {
+                                                    return calculateScopeWithoutReferences(element, key);
+                                                  }
+                                              },
+                                              PsiModificationTracker.MODIFICATION_COUNT)).get(adapter);
   }
 
   private boolean isServiceEnabled() {
   }
 
   private boolean isServiceEnabled() {