void (@NotNull Project project, @NotNull PsiElement ifToken, @NotNull ModPsiUpdater updater) { final PsiIfStatement ifStatement = (PsiIfStatement)ifToken.getParent(); assert ifStatement != null; final PsiStatement elseBranch = ifStatement.getElseBranch(); if (elseBranch == null) { return; } final PsiStatement thenBranch = ifStatement.getThenBranch(); if (thenBranch == null) { return; } final PsiExpression condition = ifStatement.getCondition(); if (condition == null) { return; } CommentTracker tracker = new CommentTracker(); final String negatedCondition = BoolUtils.getNegatedExpressionText(condition, tracker); String elseText = tracker.text(elseBranch); final PsiElement lastChild = elseBranch.getLastChild(); if (lastChild instanceof PsiComment comment) { final IElementType tokenType = comment.getTokenType(); if (JavaTokenType.END_OF_LINE_COMMENT.equals(tokenType)) { elseText += '\n'; } } @NonNls final String newStatement = "if(" + negatedCondition + ')' + elseText + " else " + tracker.text(thenBranch); PsiReplacementUtil.replaceStatement(ifStatement, newStatement, tracker); }