void (PsiJavaToken token) { final PsiIfStatement parentStatement = (PsiIfStatement)token.getParent(); final PsiIfStatement childStatement = (PsiIfStatement)PsiTreeUtil.skipWhitespacesForward(parentStatement); assert childStatement != null; final PsiExpression childCondition = childStatement.getCondition(); if (childCondition == null) { return; } CommentTracker parentTracker = new CommentTracker(); CommentTracker childTracker = new CommentTracker(); final String childConditionText = childTracker.text(childCondition, ParenthesesUtils.OR_PRECEDENCE); final PsiExpression condition = parentStatement.getCondition(); if (condition == null) { return; } final String parentConditionText = parentTracker.text(condition, ParenthesesUtils.OR_PRECEDENCE); final PsiStatement parentThenBranch = parentStatement.getThenBranch(); if (parentThenBranch == null) { return; } final StringBuilder newStatement = new StringBuilder(); newStatement.append("if("); newStatement.append(parentConditionText); newStatement.append("||"); newStatement.append(childConditionText); newStatement.append(')'); newStatement.append(parentTracker.text(parentThenBranch)); final PsiStatement childElseBranch = childStatement.getElseBranch(); if (childElseBranch != null) { newStatement.append("\nelse "); newStatement.append(childTracker.text(childElseBranch)); } PsiReplacementUtil.replaceStatement(parentStatement, newStatement.toString(), parentTracker); childTracker.deleteAndRestoreComments(childStatement); }