void (@NotNull PsiExpression initializer, List<PsiExpression> sideEffects) { if (initializer.getParent() instanceof PsiAssignmentExpression assignment) { if (assignment.getParent() instanceof PsiExpressionList list) { for (PsiExpression effect : sideEffects) { list.addBefore(effect, assignment); } assignment.delete(); } if (assignment.getParent() instanceof PsiExpressionStatement statement && statement.getParent() instanceof PsiForStatement) { if (sideEffects.size() == 1) { assignment.replace(sideEffects.get(0)); } else { PsiExpressionListStatement listStatement = (PsiExpressionListStatement)JavaPsiFacade.getElementFactory(statement.getProject()) .createStatementFromText("a,b", null); PsiExpressionList list = listStatement.getExpressionList(); PsiExpression[] mockExpressions = list.getExpressions(); PsiExpression first = mockExpressions[0]; for (PsiExpression effect : sideEffects) { list.addBefore(effect, first); } for (PsiExpression expression : mockExpressions) { expression.delete(); } statement.replace(listStatement); } } } }