void (@NotNull Project project, @NotNull PsiElement ifKeyword, @NotNull ModPsiUpdater updater) { final PsiIfStatement ifStatement = (PsiIfStatement)ifKeyword.getParent(); if (ifStatement == null) { return; } final PsiStatement elseBranch = ifStatement.getElseBranch(); if (elseBranch == null) { return; } PsiElement anchor = ifStatement; PsiElement parent = anchor.getParent(); while (parent instanceof PsiIfStatement) { anchor = parent; parent = anchor.getParent(); } if (elseBranch instanceof PsiBlockStatement elseBlock) { final PsiCodeBlock block = elseBlock.getCodeBlock(); final PsiElement[] children = block.getChildren(); if (children.length > 2) { parent.addRangeAfter(children[1], children[children.length - 2], anchor); } } else { parent.addAfter(elseBranch, anchor); } elseBranch.delete(); }