convert `ShowQuickDocInfoAction` to kt
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Fri, 30 Jul 2021 14:57:25 +0000 (16:57 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 3 Aug 2021 15:12:03 +0000 (15:12 +0000)
GitOrigin-RevId: 113d4d43d4cfb74036e9dec1ce28d42b9d89dc77

platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowQuickDocInfoAction.kt

index 6bae3603d77932ef9ee20293eedf479e11173c3b..870ecf696ad53c812f47be17351386872660c36b 100644 (file)
@@ -1,92 +1,79 @@
 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package com.intellij.codeInsight.documentation.actions;
+package com.intellij.codeInsight.documentation.actions
 
-import com.intellij.codeInsight.documentation.DocumentationManager;
-import com.intellij.codeInsight.hint.HintManagerImpl;
-import com.intellij.codeInsight.lookup.LookupManager;
-import com.intellij.featureStatistics.FeatureUsageTracker;
-import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorGutter;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.popup.JBPopup;
-import com.intellij.psi.PsiDocumentManager;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.util.PsiUtilBase;
-import org.jetbrains.annotations.NotNull;
+import com.intellij.codeInsight.documentation.DocumentationManager
+import com.intellij.codeInsight.hint.HintManagerImpl.ActionToIgnore
+import com.intellij.codeInsight.lookup.LookupManager
+import com.intellij.featureStatistics.FeatureUsageTracker
+import com.intellij.openapi.actionSystem.*
+import com.intellij.openapi.editor.EditorGutter
+import com.intellij.openapi.project.DumbAware
+import com.intellij.psi.PsiDocumentManager
+import com.intellij.psi.util.PsiUtilBase
 
-public class ShowQuickDocInfoAction extends AnAction implements HintManagerImpl.ActionToIgnore, DumbAware, PopupAction,
-                                                                UpdateInBackground, PerformWithDocumentsCommitted {
-  @SuppressWarnings("SpellCheckingInspection")
-  public static final String CODEASSISTS_QUICKJAVADOC_FEATURE = "codeassists.quickjavadoc";
-  @SuppressWarnings("SpellCheckingInspection")
-  public static final String CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE = "codeassists.quickjavadoc.lookup";
-  @SuppressWarnings("SpellCheckingInspection")
-  public static final String CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE = "codeassists.quickjavadoc.ctrln";
+open class ShowQuickDocInfoAction : AnAction(),
+                                    ActionToIgnore,
+                                    DumbAware,
+                                    PopupAction,
+                                    UpdateInBackground,
+                                    PerformWithDocumentsCommitted {
 
-  public ShowQuickDocInfoAction() {
-    setEnabledInModalContext(true);
-    setInjectedContext(true);
+  init {
+    isEnabledInModalContext = true
+    @Suppress("LeakingThis")
+    setInjectedContext(true)
   }
 
-  @Override
-  public void update(@NotNull AnActionEvent e) {
-    Presentation presentation = e.getPresentation();
-    DataContext dataContext = e.getDataContext();
-    presentation.setEnabled(false);
-
-    Project project = CommonDataKeys.PROJECT.getData(dataContext);
-    if (project == null) return;
-
-    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
-    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
-    if (editor == null && element == null) return;
-
-    if (LookupManager.getInstance(project).getActiveLookup() != null) {
-      presentation.setEnabled(true);
+  override fun update(e: AnActionEvent) {
+    val presentation = e.presentation
+    val dataContext = e.dataContext
+    presentation.isEnabled = false
+    val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return
+    val editor = CommonDataKeys.EDITOR.getData(dataContext)
+    val element = CommonDataKeys.PSI_ELEMENT.getData(dataContext)
+    if (editor == null && element == null) return
+    if (LookupManager.getInstance(project).activeLookup != null) {
+      presentation.isEnabled = true
     }
     else {
       if (editor != null) {
-        if (e.getData(EditorGutter.KEY) != null) return;
-
-        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
-        if (file == null && element == null) return;
+        if (e.getData(EditorGutter.KEY) != null) return
+        val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document)
+        if (file == null && element == null) return
       }
-      presentation.setEnabled(true);
+      presentation.isEnabled = true
     }
   }
 
-  @Override
-  public void actionPerformed(@NotNull AnActionEvent e) {
-    DataContext dataContext = e.getDataContext();
-    Project project = CommonDataKeys.PROJECT.getData(dataContext);
-    if (project == null) {
-      return;
-    }
-
-    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
+  override fun actionPerformed(e: AnActionEvent) {
+    val dataContext = e.dataContext
+    val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return
+    val editor = CommonDataKeys.EDITOR.getData(dataContext)
     if (editor != null) {
-      FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_FEATURE);
-      var activeLookup = LookupManager.getActiveLookup(editor);
+      FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_FEATURE)
+      val activeLookup = LookupManager.getActiveLookup(editor)
       if (activeLookup != null) {
-        FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE);
+        FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE)
       }
-      PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
-      if (psiFile == null) return;
-      DocumentationManager documentationManager = DocumentationManager.getInstance(project);
-      JBPopup hint = documentationManager.getDocInfoHint();
-      documentationManager.showJavaDocInfo(editor, psiFile, hint != null || activeLookup == null);
-      return;
+      val psiFile = PsiUtilBase.getPsiFileInEditor(editor, project) ?: return
+      val documentationManager = DocumentationManager.getInstance(project)
+      val hint = documentationManager.docInfoHint
+      documentationManager.showJavaDocInfo(editor, psiFile, hint != null || activeLookup == null)
+      return
     }
-
-    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
+    val element = CommonDataKeys.PSI_ELEMENT.getData(dataContext)
     if (element != null) {
-      FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE);
-      DocumentationManager documentationManager = DocumentationManager.getInstance(project);
-      JBPopup hint = documentationManager.getDocInfoHint();
-      documentationManager.showJavaDocInfo(element, null, hint != null, null);
+      FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE)
+      val documentationManager = DocumentationManager.getInstance(project)
+      val hint = documentationManager.docInfoHint
+      documentationManager.showJavaDocInfo(element, null, hint != null, null)
     }
   }
+
+  @Suppress("SpellCheckingInspection")
+  companion object {
+    const val CODEASSISTS_QUICKJAVADOC_FEATURE = "codeassists.quickjavadoc"
+    const val CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE = "codeassists.quickjavadoc.lookup"
+    const val CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE = "codeassists.quickjavadoc.ctrln"
+  }
 }