boolean (@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) { myDirection = Direction.Same; if (!(file instanceof JsonFile) || !super.checkAvailable(editor, file, info, down)) { return false; } Pair<PsiElement, PsiElement> movedElementRange = getElementRange(editor, file, info.toMove); if (!isValidElementRange(movedElementRange)) { return false; } // Tweak range to move if it's necessary movedElementRange = expandCommentsInRange(movedElementRange); PsiElement movedSecond = movedElementRange.getSecond(); PsiElement movedFirst = movedElementRange.getFirst(); info.toMove = new LineRange(movedFirst, movedSecond); // Adjust destination range to prevent illegal offsets final int lineCount = editor.getDocument().getLineCount(); if (down) { info.toMove2 = new LineRange(info.toMove.endLine, Math.min(info.toMove.endLine + 1, lineCount)); } else { info.toMove2 = new LineRange(Math.max(info.toMove.startLine - 1, 0), info.toMove.startLine); } if (movedFirst instanceof PsiComment && movedSecond instanceof PsiComment) { return true; } // Check whether additional comma is needed final Pair<PsiElement, PsiElement> destElementRange = getElementRange(editor, file, info.toMove2); if (destElementRange != null) { PsiElement destFirst = destElementRange.getFirst(); PsiElement destSecond = destElementRange.getSecond(); if (destFirst == destSecond && !(destFirst instanceof JsonProperty) && !(destFirst instanceof JsonValue)) { PsiElement parent = destFirst.getParent(); if (((JsonFile)parent.getContainingFile()).getTopLevelValue() == parent) { info.prohibitMove(); return true; } } PsiElement firstParent = destFirst.getParent(); PsiElement secondParent = destSecond.getParent(); JsonValue firstParentParent = PsiTreeUtil.getParentOfType(firstParent, JsonObject.class, JsonArray.class); if (firstParentParent == secondParent) { myDirection = down ? Direction.Outside : Direction.Inside; } JsonValue secondParentParent = PsiTreeUtil.getParentOfType(secondParent, JsonObject.class, JsonArray.class); if (firstParent == secondParentParent) { myDirection = down ? Direction.Inside : Direction.Outside; } } return true; }