PsiStatement (@NotNull Project project, @NotNull PsiElementFactory factory) { PsiBlockStatement block = (PsiBlockStatement)factory.createStatementFromText("{yield x;}", myStatement); PsiExpression newExpression = Objects.requireNonNull(((PsiYieldStatement)block.getCodeBlock().getStatements()[0]).getExpression()); newExpression.replace(myStatement.getExpression()); block = (PsiBlockStatement)myStatement.replace(block); return block.getCodeBlock().getStatements()[0]; }