void (@NotNull ActionContext context, @NotNull PsiSwitchLabeledRuleStatement ruleStatement, @NotNull ModPsiUpdater updater) { if (!ruleStatement.isValid()) return; PsiCodeBlock parent = ObjectUtils.tryCast(ruleStatement.getParent(), PsiCodeBlock.class); if (parent == null) return; PsiJavaToken rBrace = parent.getRBrace(); PsiElement[] children = parent.getChildren(); int index = ArrayUtil.indexOf(children, ruleStatement); assert index >= 0; int nextIndex = index + 1; while (nextIndex < children.length && !(children[nextIndex] instanceof PsiSwitchLabelStatementBase) && children[nextIndex] != rBrace) { nextIndex++; } if (children[nextIndex - 1] instanceof PsiWhiteSpace) { nextIndex--; } PsiElement oldBody = null; if (ruleStatement.getBody() != null) { oldBody = ruleStatement.getBody().copy(); ruleStatement.getBody().delete(); } for (PsiElement lastChild = ruleStatement.getLastChild(); lastChild != null; lastChild = lastChild.getPrevSibling()) { if (PsiUtil.isJavaToken(lastChild, JavaTokenType.SEMICOLON)) { lastChild.delete(); break; } } PsiSwitchLabeledRuleStatement newRule = (PsiSwitchLabeledRuleStatement)JavaPsiFacade.getElementFactory(context.project()) .createStatementFromText(ruleStatement.getText() + "{}", ruleStatement); PsiCodeBlock block = ((PsiBlockStatement)Objects.requireNonNull(newRule.getBody())).getCodeBlock(); if (oldBody != null) { block.add(oldBody); } if (nextIndex > index + 1) { PsiElement first = children[index + 1]; PsiElement last = children[nextIndex - 1]; block.addRange(first, last); parent.deleteChildRange(first, last); } ruleStatement.replace(newRule); }