IDEA-172119 Quick doc is unavailable in dumb mode

This commit is contained in:
Dmitry Batrak
2017-05-02 20:01:27 +03:00
parent 9968ca7c79
commit 145bfafa84
5 changed files with 112 additions and 25 deletions
@@ -26,6 +26,7 @@ import com.intellij.lang.ASTNode;
import com.intellij.lang.LangBundle;
import com.intellij.lang.java.JavaDocumentationProvider;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
@@ -908,7 +909,15 @@ public class JavaDocInfoGenerator {
for (PsiAnnotation annotation : annotations) {
final PsiJavaCodeReferenceElement nameReferenceElement = annotation.getNameReferenceElement();
if (nameReferenceElement == null) continue;
final PsiElement resolved = nameReferenceElement.resolve();
PsiElement resolved = null;
boolean resolveNotPossible = false;
try {
resolved = nameReferenceElement.resolve();
}
catch (IndexNotReadyException e) {
LOG.debug(e);
resolveNotPossible = true;
}
if (isNonDocumentedAnnotation(annotation, resolved)) continue;
boolean inferred = AnnotationUtil.isInferredAnnotation(annotation);
@@ -933,7 +942,7 @@ public class JavaDocInfoGenerator {
if (inferred) buffer.append("</i>");
buffer.append("&nbsp;");
}
else if (external) {
else if (external || resolveNotPossible) {
if (inferred) buffer.append("<i>");
String annoText = inferred ? "@" + annotation.getNameReferenceElement().getReferenceName() + annotation.getParameterList().getText()
: annotation.getText();
@@ -995,7 +1004,13 @@ public class JavaDocInfoGenerator {
boolean generateLink) {
if (generateLink && memberValue instanceof PsiQualifiedReferenceElement) {
String text = ((PsiQualifiedReferenceElement)memberValue).getCanonicalText();
PsiElement resolve = ((PsiQualifiedReferenceElement)memberValue).resolve();
PsiElement resolve = null;
try {
resolve = ((PsiQualifiedReferenceElement)memberValue).resolve();
}
catch (IndexNotReadyException e) {
LOG.debug(e);
}
if (resolve instanceof PsiField) {
PsiField field = (PsiField)resolve;
@@ -1467,7 +1482,13 @@ public class JavaDocInfoGenerator {
if (text.indexOf('#') == -1) {
text = "#" + text;
}
PsiElement target = JavaDocUtil.findReferenceTarget(PsiManager.getInstance(myProject), text, myElement);
PsiElement target = null;
try {
target = JavaDocUtil.findReferenceTarget(PsiManager.getInstance(myProject), text, myElement);
}
catch (IndexNotReadyException e) {
LOG.debug(e);
}
if (target instanceof PsiField) {
valueField = (PsiField) target;
}
@@ -1846,8 +1867,19 @@ public class JavaDocInfoGenerator {
label = JavaDocUtil.getLabelText(manager.getProject(), manager, refText, context);
}
LOG.assertTrue(refText != null, "refText appears to be null.");
PsiElement target = JavaDocUtil.findReferenceTarget(context.getManager(), refText, context);
if (target == null) {
PsiElement target = null;
boolean resolveNotPossible = false;
try {
target = JavaDocUtil.findReferenceTarget(context.getManager(), refText, context);
}
catch (IndexNotReadyException e) {
LOG.debug(e);
resolveNotPossible = true;
}
if (resolveNotPossible) {
buffer.append(label);
}
else if (target == null) {
buffer.append("<font color=red>").append(label).append("</font>");
}
else {
@@ -1911,7 +1943,16 @@ public class JavaDocInfoGenerator {
}
if (type instanceof PsiClassType) {
PsiClassType.ClassResolveResult result = ((PsiClassType)type).resolveGenerics();
PsiClassType.ClassResolveResult result;
try {
result = ((PsiClassType)type).resolveGenerics();
}
catch (IndexNotReadyException e) {
LOG.debug(e);
String text = ((PsiClassType)type).getClassName();
buffer.append(StringUtil.escapeXml(text));
return text.length();
}
PsiClass psiClass = result.getElement();
PsiSubstitutor psiSubst = result.getSubstitutor();
@@ -2080,24 +2121,28 @@ public class JavaDocInfoGenerator {
PsiMethod method,
DocTagLocator<T> loc,
Set<PsiClass> visitedClasses) {
for (PsiClassType superType : supers) {
PsiClass aSuper = superType.resolve();
if (aSuper != null) {
Pair<T, InheritDocProvider<T>> tag = searchDocTagInOverriddenMethod(method, aSuper, loc);
if (tag != null) return tag;
try {
for (PsiClassType superType : supers) {
PsiClass aSuper = superType.resolve();
if (aSuper != null) {
Pair<T, InheritDocProvider<T>> tag = searchDocTagInOverriddenMethod(method, aSuper, loc);
if (tag != null) return tag;
}
}
}
for (PsiClassType superType : supers) {
PsiClass aSuper = superType.resolve();
if (aSuper != null && visitedClasses.add(aSuper)) {
Pair<T, InheritDocProvider<T>> tag = findInheritDocTagInClass(method, aSuper, loc, visitedClasses);
if (tag != null) {
return tag;
for (PsiClassType superType : supers) {
PsiClass aSuper = superType.resolve();
if (aSuper != null && visitedClasses.add(aSuper)) {
Pair<T, InheritDocProvider<T>> tag = findInheritDocTagInClass(method, aSuper, loc, visitedClasses);
if (tag != null) {
return tag;
}
}
}
}
catch (IndexNotReadyException e) {
LOG.debug(e);
}
return null;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.javadoc;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
@@ -269,13 +270,26 @@ public class JavaDocUtil {
if (qName == null) return shortName;
final PsiManager manager = aClass.getManager();
return manager.areElementsEquivalent(aClass, JavaPsiFacade.getInstance(manager.getProject()).getResolveHelper().resolveReferencedClass(shortName, context))
PsiClass resolvedClass = null;
try {
resolvedClass = JavaPsiFacade.getInstance(manager.getProject()).getResolveHelper().resolveReferencedClass(shortName, context);
}
catch (IndexNotReadyException e) {
LOG.debug(e);
}
return manager.areElementsEquivalent(aClass, resolvedClass)
? shortName
: StringUtil.trimStart(qName, "java.lang.");
}
public static String getLabelText(Project project, PsiManager manager, String refText, PsiElement context) {
PsiElement refElement = findReferenceTarget(manager, refText, context, false);
PsiElement refElement = null;
try {
refElement = findReferenceTarget(manager, refText, context, false);
}
catch (IndexNotReadyException e) {
LOG.debug(e);
}
if (refElement == null) {
return refText.replaceFirst("^#", "").replaceAll("#", ".");
}
@@ -304,7 +318,13 @@ public class JavaDocUtil {
String memberText = refText.substring(poundIndex + 1);
String memberLabel = getMemberLabelText(project, manager, memberText, context);
if (!classRef.isEmpty()) {
PsiElement refClass = findReferenceTarget(manager, classRef, context);
PsiElement refClass = null;
try {
refClass = findReferenceTarget(manager, classRef, context);
}
catch (IndexNotReadyException e) {
LOG.debug(e);
}
if (refClass instanceof PsiClass) {
PsiElement scope = context;
while (true) {
@@ -0,0 +1,5 @@
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><PRE>class <b>C</b>
extends java.lang.Object</PRE>
some text
<DD><DL><DT><b>See Also:</b><DD>System.out</DD></DL></DD></body></html>
@@ -0,0 +1,6 @@
/**
* some text
*
* @see System#out
*/
class <caret>C {}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import com.intellij.lang.java.JavaDocumentationProvider;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModificator;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
@@ -400,6 +401,16 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
doTestAtCaret();
}
public void testDumbMode() throws Exception {
DumbServiceImpl.getInstance(myProject).setDumb(true);
try {
doTestAtCaret();
}
finally {
DumbServiceImpl.getInstance(myProject).setDumb(false);
}
}
private void doTestAtCaret() throws Exception {
configureByFile();
String docInfo = JavaExternalDocumentationTest.getDocumentationText(myFile, myEditor.getCaretModel().getOffset());