package com.jetbrains.python.actions;

import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PythonLanguage;
import com.jetbrains.python.psi.PyElementGenerator;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.psi.PyParenthesizedExpression;
import org.jetbrains.annotations.NotNull;

/**
 * Created by IntelliJ IDEA.
 * User: Alexey.Ivanov
 * Date: 12.02.2010
 * Time: 18:15:24
 */
public class ReplaceListComprehensionsQuickFix implements LocalQuickFix {
  @NotNull
  public String getName() {
    return PyBundle.message("QFIX.replace.list.comprehensions");
  }

  @NotNull
  public String getFamilyName() {
    return PyBundle.message("INSP.GROUP.python");
  }

  public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PyExpression expression = (PyExpression) descriptor.getPsiElement();
    PyElementGenerator elementGenerator = PythonLanguage.getInstance().getElementGenerator();
    expression.replace(elementGenerator.createFromText(project, PyParenthesizedExpression.class, "(" + expression.getText() + ")"));
  }
}

@@ -395,29 +395,16 @@
 n.psi.Py
-Parenthesized
 Expressi
@@ -397,32 +397,41 @@
 psi.PyExpression
+Statement
 ;%0Aimport org.jet
@@ -1101,17 +1101,19 @@
 ();%0A    
-e
+PyE
 xpressio
@@ -1117,17 +1117,30 @@
 sion
-.replace(
+Statement statement = 
 elem
@@ -1182,71 +1182,187 @@
 , Py
-ParenthesizedExpression.class, %22(%22 + expression.getText() + %22)%22
+ExpressionStatement.class,%0A                                                                      %22(%22 + expression.getText() + %22)%22);%0A    expression.replace(statement.getExpression(
 ));%0A

test fix