private static void handleJsonValue(@NotNull JsonValue literal, @NotNull Editor editor, @NotNull Ref<Integer> caretOffsetRef) {
    PsiElement parent = literal.getParent();
    if (!(parent instanceof JsonProperty) || ((JsonProperty)parent).getValue() != literal) {
      return;
    }

    PsiElement nextSibling = parent.getNextSibling();
    while (nextSibling instanceof PsiWhiteSpace || nextSibling instanceof PsiErrorElement) {
      nextSibling = nextSibling.getNextSibling();
    }

    int offset = literal.getTextRange().getEndOffset();

    if (literal instanceof JsonObject || literal instanceof JsonArray) {
      if (nextSibling instanceof LeafPsiElement && ((LeafPsiElement)nextSibling).getElementType() == JsonElementTypes.COMMA
        || !(nextSibling instanceof JsonProperty)) {
        return;
      }
      Document document = editor.getDocument();
      if (offset < document.getTextLength()) {
        document.insertString(offset, ",");
      }
      return;
    }

    if (nextSibling instanceof LeafPsiElement && ((LeafPsiElement)nextSibling).getElementType() == JsonElementTypes.COMMA) {
      offset = nextSibling.getTextRange().getEndOffset();
    }
    else {
      Document document = editor.getDocument();
      if (offset < document.getTextLength()) {
        document.insertString(offset, ",");
      }
      offset++;
    }

    if (offset < editor.getDocument().getTextLength()) {
      caretOffsetRef.set(offset);
    }
  }
private static void handleJsonValue(@NotNull JsonValue literal, @NotNull Editor editor, @NotNull Ref<Integer> caretOffsetRef)