private static boolean insertTail(InsertionContext context, LookupElement item, TailType tailType, boolean hasTail) {
    TailType toInsert = tailType;
    LookupItem<?> lookupItem = item.as(LookupItem.CLASS_CONDITION_KEY);
    if (toInsert == EqTailType.INSTANCE) {
      toInsert = TailTypes.unknownType();
    }
    if (lookupItem == null || lookupItem.getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailTypes.unknownType()) {
      if (!hasTail && item.getObject() instanceof PsiMethod && PsiTypes.voidType().equals(((PsiMethod)item.getObject()).getReturnType())) {
        PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
        if (psiElement().beforeLeaf(psiElement().withText(".")).accepts(context.getFile().findElementAt(context.getTailOffset() - 1))) {
          return false;
        }

        boolean insertAdditionalSemicolon = true;
        PsiElement leaf = context.getFile().findElementAt(context.getStartOffset());
        PsiElement composite = leaf == null ? null : leaf.getParent();
        if (composite instanceof PsiReferenceExpression) {
          PsiElement parent = composite.getParent();
          if (parent instanceof PsiMethodCallExpression) {
            parent = parent.getParent();
          }
          if (parent instanceof PsiLambdaExpression && !LambdaHighlightingUtil.insertSemicolonAfter((PsiLambdaExpression)parent)) {
            insertAdditionalSemicolon = false;
          }
          if (parent instanceof PsiExpressionStatement && parent.getParent() instanceof PsiForStatement forStatement &&
              forStatement.getUpdate() == parent) {
            insertAdditionalSemicolon = false;
          }
        }
        if (insertAdditionalSemicolon) {
          toInsert = TailTypes.semicolonType();
        }

      }
    }
    Editor editor = context.getEditor();
    int tailOffset = context.getTailOffset();
    int afterTailOffset = toInsert.processTail(editor, tailOffset);
    int caretOffset = editor.getCaretModel().getOffset();
    if (afterTailOffset > tailOffset &&
        tailOffset > caretOffset &&
        TabOutScopesTracker.getInstance().removeScopeEndingAt(editor, caretOffset) > 0) {
      TabOutScopesTracker.getInstance().registerEmptyScope(editor, caretOffset, afterTailOffset);
    }
    return true;
  }
private static boolean insertTail(InsertionContext context, LookupElement item, TailType tailType, boolean hasTail)