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);
}
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);
}
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);
}
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"));
}
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));
}
Aggregations