@Override
  public void handleInsert(@NotNull InsertionContext context) {
    SmartPsiElementPointer<PsiElement> pointer = null;
    if (getObject() instanceof PsiElement psiElement) {
      pointer = SmartPointerManager.getInstance(context.getProject()).createSmartPsiElementPointer(psiElement);
    }
    myImportFixer.handleInsert(context, this);
    // restore PSI element tucked in this.myObject and possibly made invalid by import fixer
    if (pointer != null) {
      setObject(pointer.getElement());
    }

    PsiElement position = context.getFile().findElementAt(context.getStartOffset());
    boolean insideVarDeclaration = false;
    if (position != null) {
      insideVarDeclaration = position.getParent() instanceof PsiTypeElement typeElement &&
                             typeElement.getParent() instanceof PsiVariable;
      int genericsStart = context.getTailOffset();
      context.getDocument().insertString(genericsStart, JavaCompletionUtil.escapeXmlIfNeeded(context, calcGenerics(position, context)));
      JavaCompletionUtil.shortenReference(context.getFile(), genericsStart - 1);
    }

    int targetOffset = context.getTailOffset();
    String braces = StringUtil.repeat("[]", getBracketsCount());
    Editor editor = context.getEditor();
    if (!braces.isEmpty()) {
      if (myAddArrayInitializer) {
        context.getDocument().insertString(targetOffset, braces + "{}");
        targetOffset += braces.length() + 1;
      } else {
        context.getDocument().insertString(targetOffset, braces);
        targetOffset += insideVarDeclaration ? braces.length() : 1;
        if (context.getCompletionChar() == '[') {
          context.setAddCompletionChar(false);
        }
      }
      TabOutScopesTracker.getInstance().registerEmptyScope(editor, targetOffset);
    }
    editor.getCaretModel().moveToOffset(targetOffset);
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);

    InsertHandler handler = getInsertHandler();
    if (handler != null) {
      //noinspection unchecked
      handler.handleInsert(context, this);
    }
  }
@Override
  public void handleInsert(@NotNull InsertionContext context)