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