From 0bf5ad7a76de713b9ac6d18550abd480259bdc68 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Tue, 25 Aug 2015 18:58:18 +0300 Subject: [PATCH] don't show warning message in Quick Doc popup if javadoc was generated from sources (following IDEA-143699) --- .../javadoc/JavaDocInfoGenerator.java | 55 ++++++++++++---- ...JdkClassWhenExternalDocIsNotAvailable.html | 64 +++++++++++++++++++ .../javadoc/JavaDocInfoGeneratorTest.java | 14 +++- 3 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/javadocIG/documentationForJdkClassWhenExternalDocIsNotAvailable.html diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index afb99f98519d..9176e09dbc09 100644 --- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -29,6 +29,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.PackageIndex; +import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; @@ -383,23 +385,52 @@ public class JavaDocInfoGenerator { return null; if (docURLs != null) { - if (buffer.length() == 0) { - buffer.append(""); + if (elementHasSourceCode()) { + LOG.debug("Documentation for " + myElement + " was generated from source code, it wasn't found at following URLs: ", docURLs); + } + else { + if (buffer.length() == 0) { + buffer.append(""); + } + String errorSection = "

Following external urls were checked:
   " + + StringUtil.join(docURLs, new Function() { + @Override + public String fun(String url) { + return XmlStringUtil.escapeString(url); + } + }, "
   ") + + "
The documentation for this element is not found. Please add all the needed paths to API docs in " + + "Project Settings.

"; + buffer.insert(buffer.indexOf(""), errorSection); } - String errorSection = "

Following external urls were checked:
   " + - StringUtil.join(docURLs, new Function() { - @Override - public String fun(String url) { - return XmlStringUtil.escapeString(url); - } - }, "
   ") + - "
The documentation for this element is not found. Please add all the needed paths to API docs in " + - "Project Settings.

"; - buffer.insert(buffer.indexOf(""), errorSection); } return fixupDoc(buffer); } + private boolean elementHasSourceCode() { + VirtualFile[] files; + if (myElement instanceof PsiDirectory) { + final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)myElement); + if (aPackage == null) return false; + files = PackageIndex.getInstance(myProject).getDirectoriesByPackageName(aPackage.getQualifiedName(), true); + } + else if (myElement instanceof PsiPackage) { + files = PackageIndex.getInstance(myProject).getDirectoriesByPackageName(((PsiPackage)myElement).getQualifiedName(), true); + } + else { + PsiFile containingFile = myElement.getNavigationElement().getContainingFile(); + if (containingFile == null) return false; + VirtualFile virtualFile = containingFile.getVirtualFile(); + if (virtualFile == null) return false; + files = new VirtualFile[] {virtualFile}; + } + ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject); + for (VirtualFile file : files) { + if (projectFileIndex.isInSource(file)) return true; + } + return false; + } + private void generateClassJavaDoc(@NonNls StringBuilder buffer, PsiClass aClass, boolean generatePrologueAndEpilogue) { if (aClass instanceof PsiAnonymousClass) return; if (generatePrologueAndEpilogue) diff --git a/java/java-tests/testData/codeInsight/javadocIG/documentationForJdkClassWhenExternalDocIsNotAvailable.html b/java/java-tests/testData/codeInsight/javadocIG/documentationForJdkClassWhenExternalDocIsNotAvailable.html new file mode 100644 index 000000000000..f601876a818d --- /dev/null +++ b/java/java-tests/testData/codeInsight/javadocIG/documentationForJdkClassWhenExternalDocIsNotAvailable.html @@ -0,0 +1,64 @@ + java.lang
public final class String
+extends java.lang.Object
+implements java.io.Serializable, java.lang.Comparable<String>, java.lang.CharSequence
+ The String class represents character strings. All + string literals in Java programs, such as "abc", are + implemented as instances of this class. +

+ Strings are constant; their values cannot be changed after they + are created. String buffers support mutable strings. + Because String objects are immutable they can be shared. For example: +

+       String str = "abc";
+   

+ is equivalent to: +

+       char data[] = {'a', 'b', 'c'};
+       String str = new String(data);
+   

+ Here are some more examples of how strings can be used: +

+       System.out.println("abc");
+       String cde = "cde";
+       System.out.println("abc" + cde);
+       String c = "abc".substring(2,3);
+       String d = cde.substring(1, 2);
+   
+

+ The class String includes methods for examining + individual characters of the sequence, for comparing strings, for + searching strings, for extracting substrings, and for creating a + copy of a string with all characters translated to uppercase or to + lowercase. Case mapping is based on the Unicode Standard version + specified by the Character class. +

+ The Java language provides special support for the string + concatenation operator ( + ), and for conversion of + other objects to strings. String concatenation is implemented + through the StringBuilder(or StringBuffer) + class and its append method. + String conversions are implemented through the method + toString, defined by Object and + inherited by all classes in Java. For additional information on + string concatenation and conversion, see Gosling, Joy, and Steele, + The Java Language Specification. + +

Unless otherwise noted, passing a null argument to a constructor + or method in this class will cause a NullPointerException to be + thrown. + +

A String represents a string in the UTF-16 format + in which supplementary characters are represented by surrogate + pairs (see the section Unicode + Character Representations in the Character class for + more information). + Index values refer to char code units, so a supplementary + character uses two positions in a String. +

The String class provides methods for dealing with + Unicode code points (i.e., characters), in addition to those for + dealing with Unicode code units (i.e., char values). + +

Since:
JDK1.0
See Also:
Object.toString(), +StringBuffer, +StringBuilder, +java.nio.charset.Charset
\ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java index 6e5f94a36540..e12a8e628eda 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java @@ -29,6 +29,8 @@ import com.intellij.testFramework.PsiTestUtil; import java.io.File; import java.io.IOException; +import java.util.Collections; +import java.util.List; /** * @author yole @@ -220,7 +222,11 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { } private void verifyJavaDoc(final PsiElement field) throws IOException { - String docInfo = new JavaDocInfoGenerator(getProject(), field).generateDocInfo(null); + verifyJavaDoc(field, null); + } + + private void verifyJavaDoc(final PsiElement field, List docUrls) throws IOException { + String docInfo = new JavaDocInfoGenerator(getProject(), field).generateDocInfo(docUrls); assertNotNull(docInfo); assertEquals(exampleHtmlFileText(getTestName(true)), replaceEnvironmentDependentContent(docInfo)); } @@ -291,6 +297,12 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { PsiMethod method = psiClass.getMethods()[0]; verifyJavaDoc(method); } + + public void testDocumentationForJdkClassWhenExternalDocIsNotAvailable() throws Exception { + PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass("java.lang.String", GlobalSearchScope.allScope(myProject)); + assertNotNull(aClass); + verifyJavaDoc(aClass, Collections.singletonList("dummyUrl")); + } @Override protected String getTestDataPath() {