void (@NotNull PsiSwitchBlock switchBlock, @NotNull ModPsiUpdater updater) { PsiCodeBlock body = switchBlock.getBody(); if (body == null) return; if (SwitchUtils.calculateBranchCount(switchBlock) < 0) { // Default already present for some reason return; } PsiExpression switchExpression = switchBlock.getExpression(); if (switchExpression == null) return; boolean isRuleBasedFormat = SwitchUtils.isRuleFormatSwitch(switchBlock); PsiElement bodyElement = body.getFirstBodyElement(); if (bodyElement instanceof PsiWhiteSpace && bodyElement == body.getLastBodyElement()) { bodyElement.delete(); } PsiElement anchor = body.getRBrace(); if (anchor == null) return; PsiElement parent = anchor.getParent(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(anchor.getProject()); generateStatements(switchBlock, isRuleBasedFormat, updater).stream() .map(text -> factory.createStatementFromText(text, parent)) .forEach(statement -> parent.addBefore(statement, anchor)); PsiStatement lastStatement = ArrayUtil.getLastElement(body.getStatements()); startTemplateOnStatement(lastStatement, updater); }