mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-143790 Quick Documentation does not work in package-info.java files when caret is inside doc comment
This commit is contained in:
@@ -27,8 +27,10 @@ import com.intellij.lang.LangBundle;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.lang.documentation.CodeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.CompositeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.DocumentationProviderEx;
|
||||
import com.intellij.lang.documentation.ExternalDocumentationProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
@@ -66,7 +68,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class JavaDocumentationProvider implements CodeDocumentationProvider, ExternalDocumentationProvider {
|
||||
public class JavaDocumentationProvider extends DocumentationProviderEx implements CodeDocumentationProvider, ExternalDocumentationProvider {
|
||||
private static final Logger LOG = Logger.getInstance("#" + JavaDocumentationProvider.class.getName());
|
||||
|
||||
private static final String LINE_SEPARATOR = "\n";
|
||||
@@ -793,6 +795,19 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
public void promptToConfigureDocumentation(PsiElement element) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement) {
|
||||
PsiDocComment docComment = PsiTreeUtil.getParentOfType(contextElement, PsiDocComment.class, false);
|
||||
if (docComment != null && JavaDocUtil.isInsidePackageInfo(docComment)) {
|
||||
PsiDirectory directory = file.getContainingDirectory();
|
||||
if (directory != null) {
|
||||
return JavaDirectoryService.getInstance().getPackage(directory);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String fetchExternalJavadoc(PsiElement element, final Project project, final List<String> docURLs) {
|
||||
return fetchExternalJavadoc(element, docURLs, new JavaDocExternalFilter(project));
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* some text
|
||||
*/
|
||||
package packageInfoFromComment;
|
||||
@@ -0,0 +1,2 @@
|
||||
<html><head> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body>
|
||||
some text</body></html>
|
||||
+11
-4
@@ -25,6 +25,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.JavadocOrderRootType;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
@@ -103,6 +104,7 @@ public class JavaExternalDocumentationTest extends PlatformTestCase {
|
||||
}
|
||||
|
||||
private static void waitTillDone(ActionCallback actionCallback) throws InterruptedException {
|
||||
if (actionCallback == null) return;
|
||||
long start = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - start < 300000) {
|
||||
//noinspection BusyWait
|
||||
@@ -133,14 +135,19 @@ public class JavaExternalDocumentationTest extends PlatformTestCase {
|
||||
sourceEditorText.substring(caretPosition + EditorTestUtil.CARET_TAG.length());
|
||||
}
|
||||
PsiFile psiFile = PsiFileFactory.getInstance(myProject).createFileFromText(JavaLanguage.INSTANCE, sourceEditorText);
|
||||
Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
|
||||
return getDocumentationText(psiFile, caretPosition);
|
||||
}
|
||||
|
||||
public static String getDocumentationText(@NotNull PsiFile psiFile, int caretPosition) throws InterruptedException {
|
||||
Project project = psiFile.getProject();
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
|
||||
assertNotNull(document);
|
||||
Editor editor = EditorFactory.getInstance().createEditor(document, myProject);
|
||||
Editor editor = EditorFactory.getInstance().createEditor(document, project);
|
||||
try {
|
||||
if (caretPosition >= 0) {
|
||||
editor.getCaretModel().moveToOffset(caretPosition);
|
||||
}
|
||||
DocumentationManager documentationManager = DocumentationManager.getInstance(myProject);
|
||||
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
|
||||
MockDocumentationComponent documentationComponent = new MockDocumentationComponent(documentationManager);
|
||||
try {
|
||||
documentationManager.setDocumentationComponent(documentationComponent);
|
||||
@@ -157,7 +164,7 @@ public class JavaExternalDocumentationTest extends PlatformTestCase {
|
||||
finally {
|
||||
EditorFactory.getInstance().releaseEditor(editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
|
||||
+19
-1
@@ -250,6 +250,18 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
assertNotNull(info);
|
||||
assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), replaceEnvironmentDependentContent(info));
|
||||
}
|
||||
|
||||
public void testPackageInfoFromComment() throws Exception {
|
||||
final String rootPath = getTestDataPath() + "/codeInsight/javadocIG/";
|
||||
VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootPath, myFilesToDelete);
|
||||
VirtualFile piFile = root.findFileByRelativePath("packageInfoFromComment/package-info.java");
|
||||
assertNotNull(piFile);
|
||||
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(piFile);
|
||||
assertNotNull(psiFile);
|
||||
final String info = JavaExternalDocumentationTest.getDocumentationText(psiFile, psiFile.getText().indexOf("some"));
|
||||
String htmlText = FileUtil.loadFile(new File(rootPath + getTestName(true) + File.separator + "packageInfo.html"));
|
||||
assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), replaceEnvironmentDependentContent(info));
|
||||
}
|
||||
|
||||
public void testInheritedParameter() throws Exception {
|
||||
configureByFile("/codeInsight/javadocIG/" + getTestName(true) + ".java");
|
||||
@@ -355,6 +367,12 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
private static String replaceEnvironmentDependentContent(String html) {
|
||||
return StringUtil.convertLineSeparators(html.trim()).replaceAll("<base href=\"[^\"]*\">", "<base href=\"placeholder\">");
|
||||
return html == null ? null : StringUtil.convertLineSeparators(html.trim()).replaceAll("<base href=\"[^\"]*\">",
|
||||
"<base href=\"placeholder\">");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user