boolean (@NotNull PsiElement left, @NotNull PsiElement right) { if (left instanceof PsiVariable leftVariable && right instanceof PsiVariable rightVariable) { if (left instanceof PsiParameter || right instanceof PsiParameter) return false; if (left instanceof PsiRecordComponent || right instanceof PsiRecordComponent) return false; if (left instanceof PsiEnumConstant && ErrorUtil.containsDeepError(left) || right instanceof PsiEnumConstant && ErrorUtil.containsDeepError(right)) { return false; } // flips multiple variables in a single declaration final PsiIdentifier leftIdentifier = leftVariable.getNameIdentifier(); assert leftIdentifier != null; final PsiIdentifier rightIdentifier = rightVariable.getNameIdentifier(); assert rightIdentifier != null; PsiElement leftLast = leftVariable.getLastChild(); leftLast = PsiUtil.isJavaToken(leftLast, JavaTokenType.SEMICOLON) ? leftLast.getPrevSibling() : leftLast; PsiElement rightLast = rightVariable.getLastChild(); rightLast = PsiUtil.isJavaToken(rightLast, JavaTokenType.SEMICOLON) ? rightLast.getPrevSibling() : rightLast; left.addRangeBefore(rightIdentifier, rightLast, leftIdentifier); right.addRangeBefore(leftIdentifier, leftLast, rightIdentifier); left.deleteChildRange(leftIdentifier, leftLast); right.deleteChildRange(rightIdentifier, rightLast); return true; } return false; }