void (@NotNull PsiSwitchExpression switchExpression) { PsiExpression expression = getOnlyExpression(switchExpression); if (expression == null) return; PsiExpression selector = switchExpression.getExpression(); CommentTracker tracker = new CommentTracker(); if (selector != null) { List<PsiExpression> expressions = SideEffectChecker.extractSideEffectExpressions(selector); if (!expressions.isEmpty()) { expressions.forEach(tracker::markUnchanged); PsiStatement[] sideEffects = StatementExtractor.generateStatements(expressions, selector); CodeBlockSurrounder surrounder = CodeBlockSurrounder.forExpression(switchExpression); if (surrounder != null) { CodeBlockSurrounder.SurroundResult result = surrounder.surround(); PsiStatement anchor = result.getAnchor(); for (PsiStatement effect : sideEffects) { anchor.getParent().addBefore(effect, anchor); } switchExpression = (PsiSwitchExpression)result.getExpression(); } } } tracker.replaceAndRestoreComments(switchExpression, expression); }