don't load quick doc for invalid elements (EA-90969 - PIEAE: PsiInvalidElementAccessE...
authorpeter <peter@jetbrains.com>
Fri, 4 Nov 2016 14:33:58 +0000 (15:33 +0100)
committerpeter <peter@jetbrains.com>
Fri, 4 Nov 2016 15:01:30 +0000 (16:01 +0100)
platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java

index f258dc2bb3b24c2223beb4c778ae36dab85c44af..f7954fda143766bf2b6e427c963e7db96a46466a 100644 (file)
@@ -34,6 +34,7 @@ import com.intellij.openapi.actionSystem.IdeActions;
 import com.intellij.openapi.actionSystem.impl.ActionButton;
 import com.intellij.openapi.actionSystem.impl.PresentationFactory;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
 import com.intellij.openapi.components.AbstractProjectComponent;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
@@ -66,7 +67,6 @@ import com.intellij.openapi.project.IndexNotReadyException;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.startup.StartupManager;
 import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
@@ -444,16 +444,15 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
     @Override
     @NotNull
     public DocInfo getInfo() {
-      return ApplicationManager.getApplication().runReadAction(new Computable<DocInfo>() {
-        @Override
-        public DocInfo compute() {
-          try {
-            return generateInfo(myTargetElement, myElementAtPointer, isNavigatable());
-          }
-          catch (IndexNotReadyException e) {
-            showDumbModeNotification(myTargetElement.getProject());
-            return DocInfo.EMPTY;
-          }
+      return ReadAction.compute(() -> {
+        if (!myTargetElement.isValid() || !myElementAtPointer.isValid()) return DocInfo.EMPTY;
+
+        try {
+          return generateInfo(myTargetElement, myElementAtPointer, isNavigatable());
+        }
+        catch (IndexNotReadyException e) {
+          showDumbModeNotification(myTargetElement.getProject());
+          return DocInfo.EMPTY;
         }
       });
     }
@@ -529,7 +528,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
     }
     else if (browseMode == BrowseMode.Declaration) {
       final PsiReference ref = TargetElementUtil.findReference(editor, offset);
-      final List<PsiElement> resolvedElements = ref == null ? Collections.<PsiElement>emptyList() : resolve(ref);
+      final List<PsiElement> resolvedElements = ref == null ? Collections.emptyList() : resolve(ref);
       final PsiElement resolvedElement = resolvedElements.size() == 1 ? resolvedElements.get(0) : null;
 
       final PsiElement[] targetElements = GotoDeclarationAction.findTargetElementsNoVS(project, editor, offset, false);
@@ -642,7 +641,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
       }
       return result;
     }
-    return resolvedElement == null ? Collections.<PsiElement>emptyList() : Collections.singletonList(resolvedElement);
+    return resolvedElement == null ? Collections.emptyList() : Collections.singletonList(resolvedElement);
   }
 
   private void disposeHighlighter() {