PsiStatement (@NotNull PsiIfStatement outerIf, @NotNull PsiPolyadicExpression andChain, @NotNull PsiExpression lOperands, @NotNull PsiExpression rOperands, @NotNull Project project, @NotNull PsiElementFactory factory) { PsiBlockStatement newThenBranch = (PsiBlockStatement)factory.createStatementFromText("{if(true);}", outerIf); PsiStatement thenBranch = Objects.requireNonNull(outerIf.getThenBranch()); Objects.requireNonNull(((PsiIfStatement)newThenBranch.getCodeBlock().getStatements()[0]).getThenBranch()).replace(thenBranch); newThenBranch = (PsiBlockStatement)thenBranch.replace(newThenBranch); PsiIfStatement innerIf = (PsiIfStatement)CodeStyleManager.getInstance(project).reformat(newThenBranch.getCodeBlock().getStatements()[0]); Objects.requireNonNull(innerIf.getCondition()).replace(rOperands); andChain.replace(lOperands); return innerIf; }