void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiElement toReplace; List<PsiElement> toDelete = new ArrayList<>(); CompareInfo info; if (element instanceof PsiConditionalExpression) { toReplace = element; info = fromTernary((PsiConditionalExpression)element); } else { PsiElement parent = element.getParent(); if (parent instanceof PsiIfStatement) { toReplace = parent; info = fromIf((PsiIfStatement)parent); PsiStatement elseIf = getElse((PsiIfStatement)parent); toDelete.add(elseIf); if(elseIf instanceof PsiIfStatement) { toDelete.add(getElse((PsiIfStatement)elseIf)); } } else { PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class); info = fromCall(call); toReplace = call; } } if (info == null) return; CommentTracker ct = new CommentTracker(); PsiElement result = info.replace(toReplace, ct); StreamEx.of(toDelete).nonNull().filter(PsiElement::isValid).forEach(e -> new CommentTracker().deleteAndRestoreComments(e)); SimplifiableIfStatementInspection.tryJoinDeclaration(result); }