void (@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) { final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)startElement; final PsiExpression thenExpression = conditionalExpression.getThenExpression(); if (thenExpression == null) { return; } final EquivalenceChecker.Match match = EquivalenceChecker.getCanonicalPsiEquivalence().expressionsMatch(thenExpression, conditionalExpression.getElseExpression()); if (!match.isPartialMatch()) { return; } final PsiElement leftDiff = match.getLeftDiff(); final PsiElement rightDiff = match.getRightDiff(); final String expression = "(" + conditionalExpression.getCondition().getText() + " ? " + leftDiff.getText() + " : " + rightDiff.getText() + ")"; final PsiExpression newConditionalExpression = JavaPsiFacade.getElementFactory(project).createExpressionFromText(expression, conditionalExpression); final PsiElement replacedConditionalExpression = leftDiff.replace(newConditionalExpression); ParenthesesUtils.removeParentheses((PsiExpression)replacedConditionalExpression, false); CommentTracker commentTracker = new CommentTracker(); commentTracker.markUnchanged(conditionalExpression.getCondition()); commentTracker.replaceAndRestoreComments(conditionalExpression, thenExpression); }