@Override
  public boolean showHint(@NotNull Editor editor) {
    if (suggestions.isEmpty()) {
      return false;
    }

    final Project project = editor.getProject();
    if (project == null) {
      return false;
    }

    if (HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) {
      return false;
    }

    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      String hintText =
          ShowAutoImportPass.getMessage(
              suggestions.size() > 1, suggestions.iterator().next().getFqName());

      HintManager.getInstance()
          .showQuestionHint(
              editor,
              hintText,
              element.getTextOffset(),
              element.getTextRange().getEndOffset(),
              createAction(project, editor));
    }

    return true;
  }
Beispiel #2
0
  private ImportClassFixBase.Result doFix(Editor editor) {
    if (!CodeInsightSettings.getInstance().ADD_MEMBER_IMPORTS_ON_THE_FLY) {
      return ImportClassFixBase.Result.POPUP_NOT_SHOWN;
    }
    final List<T> candidates = getMembersToImport(true);
    if (candidates.isEmpty()) {
      return ImportClassFixBase.Result.POPUP_NOT_SHOWN;
    }

    final PsiElement element = getElement();
    if (element == null) {
      return ImportClassFixBase.Result.POPUP_NOT_SHOWN;
    }

    final QuestionAction action = createQuestionAction(candidates, element.getProject(), editor);
    /* PsiFile psiFile = element.getContainingFile();
       if (candidates.size() == 1 &&
            ImportClassFixBase.isAddUnambiguousImportsOnTheFlyEnabled(psiFile) &&
            (ApplicationManager.getApplication().isUnitTestMode() || DaemonListeners.canChangeFileSilently(psiFile)) &&
            !LaterInvocator.isInModalContext()) {
          CommandProcessor.getInstance().runUndoTransparentAction(() -> action.execute());
          return ImportClassFixBase.Result.CLASS_AUTO_IMPORTED;
        }
    */
    String hintText =
        ShowAutoImportPass.getMessage(
            candidates.size() > 1, getMemberPresentableText(candidates.get(0)));
    if (!ApplicationManager.getApplication().isUnitTestMode()
        && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) {
      final TextRange textRange = element.getTextRange();
      HintManager.getInstance()
          .showQuestionHint(
              editor, hintText, textRange.getStartOffset(), textRange.getEndOffset(), action);
    }
    return ImportClassFixBase.Result.POPUP_SHOWN;
  }