boolean (@NotNull Ref<Integer> caretOffsetRef, @NotNull PsiElement psiAtOffset, @NotNull Editor editor) { PsiElement nextSibling = psiAtOffset; boolean hasNewlineBefore = false; while (nextSibling instanceof PsiWhiteSpace) { hasNewlineBefore = nextSibling.getText().contains("\n"); nextSibling = nextSibling.getNextSibling(); } LeafPsiElement leafPsiElement = ObjectUtils.tryCast(nextSibling, LeafPsiElement.class); IElementType elementType = leafPsiElement == null ? null : leafPsiElement.getElementType(); if (elementType == JsonElementTypes.COMMA || elementType == JsonElementTypes.R_CURLY) { PsiElement prevSibling = nextSibling.getPrevSibling(); while (prevSibling instanceof PsiWhiteSpace) { prevSibling = prevSibling.getPrevSibling(); } if (prevSibling instanceof JsonProperty && ((JsonProperty)prevSibling).getValue() != null) { int offset = elementType == JsonElementTypes.COMMA ? nextSibling.getTextRange().getEndOffset() : prevSibling.getTextRange().getEndOffset(); if (offset < editor.getDocument().getTextLength()) { if (elementType == JsonElementTypes.R_CURLY && hasNewlineBefore) { editor.getDocument().insertString(offset, ","); offset++; } caretOffsetRef.set(offset); } return true; } return false; } if (nextSibling instanceof JsonProperty) { PsiElement prevSibling = nextSibling.getPrevSibling(); while (prevSibling instanceof PsiWhiteSpace || prevSibling instanceof PsiErrorElement) { prevSibling = prevSibling.getPrevSibling(); } if (prevSibling instanceof JsonProperty) { int offset = prevSibling.getTextRange().getEndOffset(); if (offset < editor.getDocument().getTextLength()) { editor.getDocument().insertString(offset, ","); caretOffsetRef.set(offset + 1); } return true; } } return false; }