cache cls navigation elements that are not so cheap to calculate each time
authorpeter <peter@jetbrains.com>
Fri, 20 Dec 2013 15:25:45 +0000 (16:25 +0100)
committerpeter <peter@jetbrains.com>
Fri, 20 Dec 2013 15:26:43 +0000 (16:26 +0100)
java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java
java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMethodImpl.java
platform/core-api/src/com/intellij/openapi/roots/FileIndexFacade.java
platform/core-impl/src/com/intellij/mock/MockFileIndexFacade.java
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultFileIndexFacade.java

index b35a97e201aed81aaa51110ea443da74ef8e7719..e858b347a816231e94433644c3f3a139446a68c4 100644 (file)
@@ -27,6 +27,7 @@ import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.progress.NonCancelableSection;
 import com.intellij.openapi.progress.ProgressIndicatorProvider;
+import com.intellij.openapi.roots.FileIndexFacade;
 import com.intellij.openapi.ui.Queryable;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.pom.java.LanguageLevel;
@@ -44,12 +45,15 @@ import com.intellij.psi.impl.source.tree.JavaElementType;
 import com.intellij.psi.impl.source.tree.TreeElement;
 import com.intellij.psi.search.PsiElementProcessor;
 import com.intellij.psi.stubs.*;
+import com.intellij.psi.util.CachedValueProvider;
+import com.intellij.psi.util.CachedValuesManager;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.reference.SoftReference;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.Collections;
 import java.util.List;
@@ -263,6 +267,16 @@ public class ClsFileImpl extends ClsRepositoryPsiElement<PsiClassHolderFileStub>
   @Override
   @NotNull
   public PsiElement getNavigationElement() {
+    return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiElement>() {
+      @Nullable
+      @Override
+      public Result<PsiElement> compute() {
+        return Result.create(calcNavigationElement(), ClsFileImpl.this, FileIndexFacade.getInstance(getProject()).getRootModificationTracker());
+      }
+    });
+  }
+
+  private PsiElement calcNavigationElement() {
     for (ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) {
       if (customNavigationPolicy instanceof ClsCustomNavigationPolicyEx) {
         PsiFile navigationElement = ((ClsCustomNavigationPolicyEx)customNavigationPolicy).getFileNavigationElement(this);
index d1e9ff6ed01d68e5185d5d4d190c9af1a73aebea..4c548f505083ce6bf5051f068b21a8569ba02ac4 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.compiled;
 import com.intellij.navigation.ItemPresentation;
 import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.roots.FileIndexFacade;
 import com.intellij.openapi.util.AtomicNotNullLazyValue;
 import com.intellij.openapi.util.NotNullLazyValue;
 import com.intellij.openapi.util.text.StringUtil;
@@ -34,9 +35,7 @@ import com.intellij.psi.impl.source.tree.TreeElement;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.scope.util.PsiScopesUtil;
 import com.intellij.psi.search.SearchScope;
-import com.intellij.psi.util.MethodSignature;
-import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
-import com.intellij.psi.util.MethodSignatureUtil;
+import com.intellij.psi.util.*;
 import com.intellij.ui.RowIcon;
 import com.intellij.util.PlatformIcons;
 import org.jetbrains.annotations.NotNull;
@@ -280,6 +279,16 @@ public class ClsMethodImpl extends ClsMemberImpl<PsiMethodStub> implements PsiAn
 
   @Nullable
   public PsiMethod getSourceMirrorMethod() {
+    return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiMethod>() {
+      @Nullable
+      @Override
+      public Result<PsiMethod> compute() {
+        return Result.create(calcSourceMirrorMethod(), getContainingFile(), FileIndexFacade.getInstance(getProject()).getRootModificationTracker());
+      }
+    });
+  }
+
+  private PsiMethod calcSourceMirrorMethod() {
     PsiClass sourceClassMirror = ((ClsClassImpl)getParent()).getSourceMirrorClass();
     if (sourceClassMirror == null) return null;
     for (PsiMethod sourceMethod : sourceClassMirror.findMethodsByName(getName(), false)) {
index 0fef333922180b51aafbc073f4936b706e05a524..cc7dddd3c848b3d819c4d96872d6f52838b79de0 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.openapi.roots;
 import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.ModificationTracker;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.search.GlobalSearchScope;
 import org.jetbrains.annotations.NotNull;
@@ -61,4 +62,6 @@ public abstract class FileIndexFacade {
   public boolean shouldBeFound(GlobalSearchScope scope, VirtualFile virtualFile) {
     return (scope.isSearchOutsideRootModel() || isInContent(virtualFile) || isInLibrarySource(virtualFile)) && !virtualFile.getFileType().isBinary();
   }
+
+  @NotNull public abstract ModificationTracker getRootModificationTracker();
 }
index ee0f2bb453448f605ad0cda4f162c9c8ffb65026..dd6d73f11b992155a1511ea14967fdae69ec72c6 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.mock;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.FileIndexFacade;
+import com.intellij.openapi.util.ModificationTracker;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.jetbrains.annotations.NotNull;
@@ -82,6 +83,12 @@ public class MockFileIndexFacade extends FileIndexFacade {
     return VfsUtilCore.isAncestor(baseDir, child, false);
   }
 
+  @NotNull
+  @Override
+  public ModificationTracker getRootModificationTracker() {
+    return ModificationTracker.NEVER_CHANGED;
+  }
+
   public void addLibraryRoot(VirtualFile file) {
     myLibraryRoots.add(file);
   }
index 25d9b5b11170c35ba31228206a00ec4b75d30c3b..057f6b0760708473a063a68c4bc0fdb334a2523f 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.FileIndexFacade;
 import com.intellij.openapi.roots.ProjectFileIndex;
 import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.util.ModificationTracker;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -86,4 +87,10 @@ public class ProjectFileIndexFacade extends FileIndexFacade {
       childDir = childDir.getParent();
     }
   }
+
+  @NotNull
+  @Override
+  public ModificationTracker getRootModificationTracker() {
+    return ProjectRootManager.getInstance(myProject);
+  }
 }
index beeb05718573505e889390ceb9778a0d3dc37a97..a63bbdbf0a690936b9fa1122c14af0fa04cb4dbd 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.openapi.vcs.impl;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.FileIndexFacade;
+import com.intellij.openapi.util.ModificationTracker;
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.platform.ProjectBaseDirectory;
@@ -73,6 +74,12 @@ public class DefaultFileIndexFacade extends FileIndexFacade {
     return VfsUtil.isAncestor(baseDir, childDir, false);
   }
 
+  @NotNull
+  @Override
+  public ModificationTracker getRootModificationTracker() {
+    return ModificationTracker.NEVER_CHANGED;
+  }
+
   private VirtualFile getBaseDir() {
     return ProjectBaseDirectory.getInstance(myProject).getBaseDir(myBaseDir);
   }