void (PsiStatement body, PsiYieldStatement yieldStatement) { PsiExpression valueExpression = yieldStatement.getExpression(); if (valueExpression != null) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(body.getProject()); PsiExpressionStatement statement = (PsiExpressionStatement)factory.createStatementFromText("x=1;", body); statement.getExpression().replace(valueExpression); CommentTracker tracker = new CommentTracker(); // replaceAndRestoreComments() will work with a copy of the expression, so it won't see the original comments tracker.markUnchanged(valueExpression); tracker.replaceAndRestoreComments(body, statement); } }