private boolean hideAutopopupIfMeaningless() {
    if (!myLookup.isLookupDisposed()
        && isAutopopupCompletion()
        && !myLookup.isSelectionTouched()
        && !myLookup.isCalculating()) {
      myLookup.refreshUi(true);
      final List<LookupElement> items = myLookup.getItems();

      for (LookupElement item : items) {
        if (!myLookup.itemPattern(item).equals(item.getLookupString())) {
          return false;
        }

        if (item.isValid()) {
          final LookupElementPresentation presentation = new LookupElementPresentation();
          item.renderElement(presentation);
          if (StringUtil.isNotEmpty(presentation.getTailText())) {
            return false;
          }
        }
      }

      myLookup.hideLookup(false);
      LOG.assertTrue(CompletionServiceImpl.getCompletionService().getCurrentCompletion() == null);
      CompletionServiceImpl.setCompletionPhase(new CompletionPhase.EmptyAutoPopup(this));
      return true;
    }
    return false;
  }
  private boolean updateLookup() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (isOutdated() || !shouldShowLookup()) return false;

    boolean justShown = false;
    if (!myLookup.isShown()) {
      if (hideAutopopupIfMeaningless()) {
        return false;
      }

      if (Registry.is("dump.threads.on.empty.lookup")
          && myLookup.isCalculating()
          && myLookup.getItems().isEmpty()) {
        PerformanceWatcher.getInstance().dumpThreads(true);
      }

      if (StringUtil.isEmpty(myLookup.getAdvertisementText()) && !isAutopopupCompletion()) {
        final String text = DefaultCompletionContributor.getDefaultAdvertisementText(myParameters);
        if (text != null) {
          myLookup.setAdvertisementText(text);
        }
      }

      if (!myLookup.showLookup()) {
        return false;
      }
      justShown = true;
    }
    myLookup.refreshUi(true, justShown);
    hideAutopopupIfMeaningless();
    if (justShown) {
      myLookup.ensureSelectionVisible();
    }
    return true;
  }
  void scheduleAdvertising() {
    if (myLookup.isAvailableToUser()) {
      return;
    }
    final List<CompletionContributor> list = CompletionContributor.forParameters(myParameters);
    for (final CompletionContributor contributor : list) {
      if (myLookup.getAdvertisementText() != null) return;
      if (!myLookup.isCalculating() && !myLookup.isVisible()) return;

      @SuppressWarnings("deprecation")
      String s = contributor.advertise(myParameters);
      if (myLookup.getAdvertisementText() != null) return;

      if (s != null) {
        myLookup.setAdvertisementText(s);
        ApplicationManager.getApplication()
            .invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (isAutopopupCompletion() && !myLookup.isAvailableToUser()) {
                      return;
                    }
                    if (!CompletionServiceImpl.isPhase(
                        CompletionPhase.BgCalculation.class,
                        CompletionPhase.ItemsCalculated.class)) {
                      return;
                    }
                    if (CompletionServiceImpl.getCompletionPhase().indicator
                        != CompletionProgressIndicator.this) {
                      return;
                    }

                    updateLookup();
                  }
                },
                myQueue.getModalityState());
        return;
      }
    }
  }
 private boolean shouldShowLookup() {
   if (isAutopopupCompletion() && myLookup.isCalculating()) {
     return false;
   }
   return true;
 }