Search in sources :

Example 1 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager in project intellij-community by JetBrains.

the class ShowJavadoc method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent component = new DocumentationComponent(documentationManager);
    final Property property = myTable.getSelectionProperty();
    if (property == null) {
        return;
    }
    PsiElement javadocElement = property.getJavadocElement();
    ActionCallback callback;
    if (javadocElement == null) {
        callback = new ActionCallback();
        component.setText(property.getJavadocText(), null, true);
    } else {
        callback = documentationManager.queueFetchDocInfo(javadocElement, component);
    }
    callback.doWhenProcessed(() -> {
        JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(DesignerBundle.message("designer.properties.javadoc.title", property.getName())).setCancelCallback(() -> {
            Disposer.dispose(component);
            return Boolean.TRUE;
        }).createPopup();
        component.setHint(hint);
        Disposer.register(hint, component);
        hint.show(new RelativePoint(myTable.getParent(), new Point(0, 0)));
    });
    if (javadocElement == null) {
        callback.setDone();
    }
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) ActionCallback(com.intellij.openapi.util.ActionCallback) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Property(com.intellij.designer.model.Property) PsiElement(com.intellij.psi.PsiElement)

Example 2 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager in project kotlin by JetBrains.

the class AbstractQuickDocProviderTest method doTest.

public void doTest(@NotNull String path) throws Exception {
    IdeaTestUtilsKt.configureWithExtraFileAbs(myFixture, path, "_Data");
    PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    assertNotNull("Can't find element at caret in file: " + path, element);
    DocumentationManager documentationManager = DocumentationManager.getInstance(myFixture.getProject());
    PsiElement targetElement = documentationManager.findTargetElement(myFixture.getEditor(), myFixture.getFile());
    PsiElement originalElement = DocumentationManager.getOriginalElement(targetElement);
    String info = DocumentationManager.getProviderFromElement(targetElement).generateDoc(targetElement, originalElement);
    if (info != null) {
        info = StringUtil.convertLineSeparators(info);
    }
    if (info != null && !info.endsWith("\n")) {
        info += "\n";
    }
    File testDataFile = new File(path);
    String textData = FileUtil.loadFile(testDataFile, true);
    List<String> directives = InTextDirectivesUtils.findLinesWithPrefixesRemoved(textData, false, "INFO:");
    if (directives.isEmpty()) {
        throw new FileComparisonFailure("'// INFO:' directive was expected", textData, textData + "\n\n//INFO: " + info, testDataFile.getAbsolutePath());
    } else {
        StringBuilder expectedInfoBuilder = new StringBuilder();
        for (String directive : directives) {
            expectedInfoBuilder.append(directive).append("\n");
        }
        String expectedInfo = expectedInfoBuilder.toString();
        if (expectedInfo.endsWith("...\n")) {
            if (!info.startsWith(StringUtil.trimEnd(expectedInfo, "...\n"))) {
                wrapToFileComparisonFailure(info, path, textData);
            }
        } else if (!expectedInfo.equals(info)) {
            wrapToFileComparisonFailure(info, path, textData);
        }
    }
}
Also used : DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 3 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager in project intellij-community by JetBrains.

the class JavaExternalDocumentationTest method getDocumentationText.

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, project);
    try {
        if (caretPosition >= 0) {
            editor.getCaretModel().moveToOffset(caretPosition);
        }
        DocumentationManager documentationManager = DocumentationManager.getInstance(project);
        MockDocumentationComponent documentationComponent = new MockDocumentationComponent(documentationManager);
        try {
            documentationManager.setDocumentationComponent(documentationComponent);
            documentationManager.showJavaDocInfo(editor, psiFile, false);
            waitTillDone(documentationManager.getLastAction());
            return documentationComponent.getText();
        } finally {
            JBPopup hint = documentationComponent.getHint();
            if (hint != null)
                Disposer.dispose(hint);
            Disposer.dispose(documentationComponent);
        }
    } finally {
        EditorFactory.getInstance().releaseEditor(editor);
    }
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 4 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager in project intellij-community by JetBrains.

the class CtrlMouseHandler method getInfoAt.

@Nullable
private static Info getInfoAt(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file, int offset, @NotNull BrowseMode browseMode) {
    PsiElement targetElement = null;
    if (browseMode == BrowseMode.TypeDeclaration) {
        try {
            targetElement = GotoTypeDeclarationAction.findSymbolType(editor, offset);
        } catch (IndexNotReadyException e) {
            showDumbModeNotification(project);
        }
    } else if (browseMode == BrowseMode.Declaration) {
        final PsiReference ref = TargetElementUtil.findReference(editor, offset);
        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);
        final PsiElement elementAtPointer = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), offset));
        if (targetElements != null) {
            if (targetElements.length == 0) {
                return null;
            } else if (targetElements.length == 1) {
                if (targetElements[0] != resolvedElement && elementAtPointer != null && targetElements[0].isPhysical()) {
                    return ref != null ? new InfoSingle(ref, targetElements[0]) : new InfoSingle(elementAtPointer, targetElements[0]);
                }
            } else {
                return elementAtPointer != null ? new InfoMultiple(elementAtPointer) : null;
            }
        }
        if (resolvedElements.size() == 1) {
            return new InfoSingle(ref, resolvedElements.get(0));
        }
        if (resolvedElements.size() > 1) {
            return elementAtPointer != null ? new InfoMultiple(elementAtPointer, ref) : null;
        }
    } else if (browseMode == BrowseMode.Implementation) {
        final PsiElement element = TargetElementUtil.getInstance().findTargetElement(editor, ImplementationSearcher.getFlags(), offset);
        PsiElement[] targetElements = new ImplementationSearcher() {

            @Override
            @NotNull
            protected PsiElement[] searchDefinitions(final PsiElement element, Editor editor) {
                final List<PsiElement> found = new ArrayList<>(2);
                DefinitionsScopedSearch.search(element, getSearchScope(element, editor)).forEach(psiElement -> {
                    found.add(psiElement);
                    return found.size() != 2;
                });
                return PsiUtilCore.toPsiElementArray(found);
            }
        }.searchImplementations(editor, element, offset);
        if (targetElements == null) {
            return null;
        }
        if (targetElements.length > 1) {
            PsiElement elementAtPointer = file.findElementAt(offset);
            if (elementAtPointer != null) {
                return new InfoMultiple(elementAtPointer);
            }
            return null;
        }
        if (targetElements.length == 1) {
            Navigatable descriptor = EditSourceUtil.getDescriptor(targetElements[0]);
            if (descriptor == null || !descriptor.canNavigate()) {
                return null;
            }
            targetElement = targetElements[0];
        }
    }
    if (targetElement != null && targetElement.isPhysical()) {
        PsiElement elementAtPointer = file.findElementAt(offset);
        if (elementAtPointer != null) {
            return new InfoSingle(elementAtPointer, targetElement);
        }
    }
    final PsiElement element = GotoDeclarationAction.findElementToShowUsagesOf(editor, offset);
    if (element instanceof PsiNameIdentifierOwner) {
        PsiElement identifier = ((PsiNameIdentifierOwner) element).getNameIdentifier();
        if (identifier != null && identifier.isValid()) {
            return new Info(identifier) {

                @Override
                public void showDocInfo(@NotNull DocumentationManager docManager) {
                }

                @NotNull
                @Override
                public DocInfo getInfo() {
                    String name = UsageViewUtil.getType(element) + " '" + UsageViewUtil.getShortName(element) + "'";
                    return new DocInfo("Show usages of " + name, null, element);
                }

                @Override
                public boolean isValid(@NotNull Document document) {
                    return element.isValid();
                }

                @Override
                public boolean isNavigatable() {
                    return true;
                }
            };
        }
    }
    return null;
}
Also used : DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) UIUtil(com.intellij.util.ui.UIUtil) PresentationFactory(com.intellij.openapi.actionSystem.impl.PresentationFactory) ReadTask(com.intellij.openapi.progress.util.ReadTask) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) UsageViewShortNameLocation(com.intellij.usageView.UsageViewShortNameLocation) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) DefinitionsScopedSearch(com.intellij.psi.search.searches.DefinitionsScopedSearch) Keymap(com.intellij.openapi.keymap.Keymap) GotoDeclarationAction(com.intellij.codeInsight.navigation.actions.GotoDeclarationAction) IdeActions(com.intellij.openapi.actionSystem.IdeActions) EventObject(java.util.EventObject) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) UsageViewTypeLocation(com.intellij.usageView.UsageViewTypeLocation) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Logger(com.intellij.openapi.diagnostic.Logger) TIntArrayList(gnu.trove.TIntArrayList) HintUtil(com.intellij.codeInsight.hint.HintUtil) DumbService(com.intellij.openapi.project.DumbService) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) ScreenUtil(com.intellij.ui.ScreenUtil) DocumentationManagerProtocol(com.intellij.codeInsight.documentation.DocumentationManagerProtocol) TextRange(com.intellij.openapi.util.TextRange) com.intellij.openapi.editor.event(com.intellij.openapi.editor.event) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) HighlighterTargetArea(com.intellij.openapi.editor.markup.HighlighterTargetArea) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) java.awt.event(java.awt.event) EditSourceUtil(com.intellij.ide.util.EditSourceUtil) EditorFactory(com.intellij.openapi.editor.EditorFactory) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) HintListener(com.intellij.ui.HintListener) LightweightHint(com.intellij.ui.LightweightHint) Consumer(com.intellij.util.Consumer) NavigationItem(com.intellij.navigation.NavigationItem) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) IdeTooltipManager(com.intellij.ide.IdeTooltipManager) KeymapManager(com.intellij.openapi.keymap.KeymapManager) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) ArrayList(java.util.ArrayList) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) ItemPresentation(com.intellij.navigation.ItemPresentation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Comparing(com.intellij.openapi.util.Comparing) StartupManager(com.intellij.openapi.startup.StartupManager) HighlighterLayer(com.intellij.openapi.editor.markup.HighlighterLayer) Project(com.intellij.openapi.project.Project) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) JdkConstants(org.intellij.lang.annotations.JdkConstants) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) HyperlinkListener(javax.swing.event.HyperlinkListener) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) StringUtil(com.intellij.openapi.util.text.StringUtil) Editor(com.intellij.openapi.editor.Editor) UsageViewUtil(com.intellij.usageView.UsageViewUtil) AbstractProjectComponent(com.intellij.openapi.components.AbstractProjectComponent) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) EditorColors(com.intellij.openapi.editor.colors.EditorColors) HintManagerImpl(com.intellij.codeInsight.hint.HintManagerImpl) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) GotoTypeDeclarationAction(com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction) Navigatable(com.intellij.pom.Navigatable) HintManager(com.intellij.codeInsight.hint.HintManager) Collections(java.util.Collections) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Navigatable(com.intellij.pom.Navigatable) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TIntArrayList(gnu.trove.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager in project intellij-community by JetBrains.

the class ShowQuickDocAtPinnedWindowFromTooltipAction method doActionPerformed.

@Override
protected void doActionPerformed(@NotNull DataContext context, @NotNull PsiElement docAnchor, @NotNull PsiElement originalElement) {
    Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
        return;
    }
    DocumentationManager docManager = DocumentationManager.getInstance(project);
    docManager.setAllowContentUpdateFromContext(false);
    docManager.showJavaDocInfoAtToolWindow(docAnchor, originalElement);
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager)

Aggregations

DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)8 Project (com.intellij.openapi.project.Project)6 JBPopup (com.intellij.openapi.ui.popup.JBPopup)5 DocumentationComponent (com.intellij.codeInsight.documentation.DocumentationComponent)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)1 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 DocumentationManagerProtocol (com.intellij.codeInsight.documentation.DocumentationManagerProtocol)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 HintManagerImpl (com.intellij.codeInsight.hint.HintManagerImpl)1 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 GotoDeclarationAction (com.intellij.codeInsight.navigation.actions.GotoDeclarationAction)1 GotoTypeDeclarationAction (com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction)1 Property (com.intellij.designer.model.Property)1 IdeTooltipManager (com.intellij.ide.IdeTooltipManager)1