PsiCodeBlock (PsiStatement currentContext, PsiIfStatement ifStatement, boolean inThen, PsiCodeBlock ifParent) { PsiElement[] tail = extractTail(currentContext, ifParent); if (!ContainerUtil.exists(tail, PsiStatement.class::isInstance)) return null; PsiBlockStatement blockForTail = getBlockFromIf(ifStatement, inThen); PsiCodeBlock codeBlock = blockForTail.getCodeBlock(); PsiJavaToken brace = requireNonNull(codeBlock.getRBrace()); for (PsiElement element : tail) { if (element.isValid()) { codeBlock.addBefore(element, brace); element.delete(); } } return codeBlock; }