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;
  }
  @Override
  public void renderElement(LookupElementPresentation presentation) {
    final Object object = getObject();
    if (object instanceof PsiClass) {
      JavaPsiClassReferenceElement.renderClassItem(
          presentation, this, (PsiClass) object, myDiamond, myLocationString, mySubstitutor);
    } else {
      assert object instanceof PsiType;

      if (!(object instanceof PsiPrimitiveType)) {
        presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal()));
      }

      presentation.setItemText(((PsiType) object).getCanonicalText());
      presentation.setItemTextBold(object instanceof PsiPrimitiveType);
      if (isAddArrayInitializer()) {
        presentation.setTailText("{...}");
      }
    }
    if (myBracketsCount > 0) {
      presentation.setTailText(
          StringUtil.repeat("[]", myBracketsCount)
              + StringUtil.notNullize(presentation.getTailText()),
          true);
    }
  }
  public boolean addItem(LookupElement item, PrefixMatcher matcher) {
    LookupElementPresentation presentation = renderItemApproximately(item);
    if (containsDummyIdentifier(presentation.getItemText())
        || containsDummyIdentifier(presentation.getTailText())
        || containsDummyIdentifier(presentation.getTypeText())) {
      return false;
    }

    myMatchers.put(item, matcher);
    updateLookupWidth(item, presentation);
    synchronized (myList) {
      myArranger.addElement(this, item, presentation);
    }
    return true;
  }
  @Override
  public void renderElement(LookupElementPresentation presentation) {
    super.renderElement(presentation);
    final LookupElementPresentation qualifierPresentation = new LookupElementPresentation();
    myQualifier.renderElement(qualifierPresentation);
    String name = maybeAddParentheses(qualifierPresentation.getItemText());
    final String qualifierText =
        myQualifier.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null
            ? "(" + name + ")"
            : name;
    presentation.setItemText(qualifierText + "." + presentation.getItemText());

    if (myQualifier instanceof LookupItem && getQualifierObject() instanceof PsiClass) {
      String locationString =
          JavaPsiClassReferenceElement.getLocationString((LookupItem) myQualifier);
      presentation.setTailText(StringUtil.notNullize(presentation.getTailText()) + locationString);
    }
  }
 @NotNull
 private static String getTailTextOrSpace(LookupElementPresentation presentation) {
   String tailText = presentation.getTailText();
   return tailText == null || tailText.isEmpty() ? " " : tailText;
 }