void (PsiMethod method, boolean replaceWithContinue) { PsiCodeBlock block = Objects.requireNonNull(method.getBody()); PsiReturnStatement[] returnStatements = PsiUtil.findReturnStatements(method); for (PsiReturnStatement returnStatement : returnStatements) { final PsiExpression returnValue = returnStatement.getReturnValue(); if (returnValue != null) { List<PsiExpression> sideEffects = !singleReturnMethod(method) || !PsiUtil.isStatement(returnValue) ? SideEffectChecker.extractSideEffectExpressions(returnValue) : Collections.singletonList(returnValue); CommentTracker ct = new CommentTracker(); sideEffects.forEach(ct::markUnchanged); PsiStatement[] statements = StatementExtractor.generateStatements(sideEffects, returnValue); ct.delete(returnValue); if (statements.length > 0) { PsiStatement lastAdded = BlockUtils.addBefore(returnStatement, statements); // Could be wrapped into {}, so returnStatement might be non-physical anymore returnStatement = Objects.requireNonNull(PsiTreeUtil.getNextSiblingOfType(lastAdded, PsiReturnStatement.class)); } ct.insertCommentsBefore(returnStatement); } if (ControlFlowUtils.blockCompletesWithStatement(block, returnStatement)) { new CommentTracker().deleteAndRestoreComments(returnStatement); } else if (replaceWithContinue) { new CommentTracker().replaceAndRestoreComments(returnStatement, "continue;"); } } }