Search in sources :

Example 6 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-community by JetBrains.

the class FixDocCommentAction method generateOrFixComment.

/**
   * Generates comment if it's not exist or try to fix if exists
   *
   * @param element     target element for which a comment should be generated
   * @param project     current project
   * @param editor      target editor
   */
public static void generateOrFixComment(@NotNull final PsiElement element, @NotNull final Project project, @NotNull final Editor editor) {
    Language language = element.getLanguage();
    final CodeDocumentationProvider docProvider;
    final DocumentationProvider langDocumentationProvider = LanguageDocumentation.INSTANCE.forLanguage(language);
    if (langDocumentationProvider instanceof CompositeDocumentationProvider) {
        docProvider = ((CompositeDocumentationProvider) langDocumentationProvider).getFirstCodeDocumentationProvider();
    } else if (langDocumentationProvider instanceof CodeDocumentationProvider) {
        docProvider = (CodeDocumentationProvider) langDocumentationProvider;
    } else {
        docProvider = null;
    }
    if (docProvider == null) {
        return;
    }
    final Pair<PsiElement, PsiComment> pair = docProvider.parseContext(element);
    if (pair == null) {
        return;
    }
    Commenter c = LanguageCommenters.INSTANCE.forLanguage(language);
    if (!(c instanceof CodeDocumentationAwareCommenter)) {
        return;
    }
    final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter) c;
    final Runnable task;
    if (pair.second == null || pair.second.getTextRange().isEmpty()) {
        task = () -> generateComment(pair.first, editor, docProvider, commenter, project);
    } else {
        final DocCommentFixer fixer = DocCommentFixer.EXTENSION.forLanguage(language);
        if (fixer == null) {
            return;
        } else {
            task = () -> fixer.fixComment(project, editor, pair.second);
        }
    }
    final Runnable command = () -> ApplicationManager.getApplication().runWriteAction(task);
    CommandProcessor.getInstance().executeCommand(project, command, "Fix documentation", null);
}
Also used : CodeDocumentationProvider(com.intellij.lang.documentation.CodeDocumentationProvider) CompositeDocumentationProvider(com.intellij.lang.documentation.CompositeDocumentationProvider) DocCommentFixer(com.intellij.codeInsight.documentation.DocCommentFixer) CodeDocumentationProvider(com.intellij.lang.documentation.CodeDocumentationProvider) CompositeDocumentationProvider(com.intellij.lang.documentation.CompositeDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 7 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-plugins by JetBrains.

the class FlexDocumentationTest method testFlexCssProperty.

@JSTestOptions({ JSTestOption.WithCssSupportLoader, JSTestOption.WithFlexFacet })
public void testFlexCssProperty() throws Exception {
    DocumentationProvider cssDocumentationProvider = new CssDocumentationProvider();
    PsiElement docElement = getDocElementForLookupItem(cssDocumentationProvider, getTestName(false) + ".css");
    assertInstanceOf(docElement, JSAttributeNameValuePair.class);
}
Also used : PsiElement(com.intellij.psi.PsiElement) CssDocumentationProvider(com.intellij.psi.css.impl.util.CssDocumentationProvider) FlexDocumentationProvider(com.intellij.javascript.flex.FlexDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) JSDocumentationProvider(com.intellij.lang.javascript.documentation.JSDocumentationProvider) CssDocumentationProvider(com.intellij.psi.css.impl.util.CssDocumentationProvider) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 8 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-plugins by JetBrains.

the class FlexDocumentationTest method testFlexCssPropertyMultiDocumentationInLookup.

@JSTestOptions({ JSTestOption.WithCssSupportLoader, JSTestOption.WithFlexFacet })
public void testFlexCssPropertyMultiDocumentationInLookup() throws Exception {
    DocumentationProvider cssDocProvider = new CssDocumentationProvider();
    String doc = testOne(cssDocProvider, getTestName(false) + ".css", new CssPropertyDescriptorStub("borderColor"));
    assertNotNull(doc);
    assertTrue("Container's borderColor property missing", doc.indexOf("Container") >= 0);
    assertTrue("Button's borderColor property missing", doc.indexOf("Button") >= 0);
    assertTrue("UIComponent's borderColor property missing", doc.indexOf("UIComponent") >= 0);
}
Also used : CssPropertyDescriptorStub(com.intellij.psi.css.descriptor.CssPropertyDescriptorStub) CssDocumentationProvider(com.intellij.psi.css.impl.util.CssDocumentationProvider) FlexDocumentationProvider(com.intellij.javascript.flex.FlexDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) JSDocumentationProvider(com.intellij.lang.javascript.documentation.JSDocumentationProvider) CssDocumentationProvider(com.intellij.psi.css.impl.util.CssDocumentationProvider) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 9 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-plugins by JetBrains.

the class DocumentationTest method assertDocumentation.

private void assertDocumentation(@NotNull PsiElement docElement, @NotNull PsiElement context) {
    DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(docElement);
    String inlineDoc = documentationProvider.generateDoc(docElement, context);
    assertNotNull("inline help is null", inlineDoc);
    List<String> urlFor = documentationProvider.getUrlFor(docElement, context);
    assertNotNull("external help is null", urlFor);
    assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".txt", inlineDoc + "\n---\n" + StringUtil.join(urlFor, "\n"));
}
Also used : DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 10 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project android by JetBrains.

the class AndroidJavaDocRendererTest method checkJavadoc.

/**
     * Test that the project can fetch documentation at the caret point (which is expected to be set
     * explicitly in the contents of {@code fileName}). {@code javadocConsumer} will be triggered with
     * the actual documentation returned and will be responsible for asserting expected values.
     */
private void checkJavadoc(String fileName, String targetName, Consumer<String> javadocConsumer) {
    final VirtualFile f = myFixture.copyFileToProject(getTestDataPath() + fileName, targetName);
    myFixture.configureFromExistingVirtualFile(f);
    PsiElement originalElement = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    assert originalElement != null;
    final PsiElement docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    assert docTargetElement != null;
    DocumentationProvider provider = DocumentationManager.getProviderFromElement(docTargetElement);
    javadocConsumer.consume(provider.generateDoc(docTargetElement, originalElement));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiElement(com.intellij.psi.PsiElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Aggregations

DocumentationProvider (com.intellij.lang.documentation.DocumentationProvider)24 PsiElement (com.intellij.psi.PsiElement)15 FlexDocumentationProvider (com.intellij.javascript.flex.FlexDocumentationProvider)3 ExternalDocumentationProvider (com.intellij.lang.documentation.ExternalDocumentationProvider)3 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3 JSDocumentationProvider (com.intellij.lang.javascript.documentation.JSDocumentationProvider)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 CssDocumentationProvider (com.intellij.psi.css.impl.util.CssDocumentationProvider)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 DocCommentFixer (com.intellij.codeInsight.documentation.DocCommentFixer)1 LookupEx (com.intellij.codeInsight.lookup.LookupEx)1 CodeDocumentationProvider (com.intellij.lang.documentation.CodeDocumentationProvider)1 CompositeDocumentationProvider (com.intellij.lang.documentation.CompositeDocumentationProvider)1 ExternalDocumentationHandler (com.intellij.lang.documentation.ExternalDocumentationHandler)1 ModuleUtilCore.findModuleForPsiElement (com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)1 Project (com.intellij.openapi.project.Project)1 PopupStep (com.intellij.openapi.ui.popup.PopupStep)1