From 6eb412713f995c733e4594f8d24ee1ce4d3342d8 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 14 May 2014 19:50:32 +0400 Subject: [PATCH] fixed PY-11909 problem with extract variable --- .../refactoring/introduce/IntroduceHandler.java | 12 ++++++++++++ .../introduceVariable/generatorParameter.after.py | 2 ++ .../introduceVariable/generatorParameter.py | 1 + .../python/refactoring/PyIntroduceVariableTest.java | 4 ++++ 4 files changed, 19 insertions(+) create mode 100644 python/testData/refactoring/introduceVariable/generatorParameter.after.py create mode 100644 python/testData/refactoring/introduceVariable/generatorParameter.py diff --git a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java index f479d104765e..0941df45702f 100644 --- a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java +++ b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java @@ -44,6 +44,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.util.Function; import com.jetbrains.python.PyBundle; import com.jetbrains.python.PyNames; +import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.PythonStringUtil; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; import com.jetbrains.python.psi.*; @@ -549,6 +550,17 @@ abstract public class IntroduceHandler implements RefactoringActionHandler { } } + @Override + public void visitPyGeneratorExpression(PyGeneratorExpression node) { + final PsiElement firstChild = node.getFirstChild(); + if (firstChild != null && firstChild.getNode().getElementType() != PyTokenTypes.LPAR) { + myResult.append("(").append(node.getText()).append(")"); + } + else { + super.visitPyGeneratorExpression(node); + } + } + @Override public void visitElement(PsiElement element) { if (element.getChildren().length == 0) { diff --git a/python/testData/refactoring/introduceVariable/generatorParameter.after.py b/python/testData/refactoring/introduceVariable/generatorParameter.after.py new file mode 100644 index 000000000000..0070465ccc35 --- /dev/null +++ b/python/testData/refactoring/introduceVariable/generatorParameter.after.py @@ -0,0 +1,2 @@ +a = (row for row in [123] if row == "beetle") +any(a) \ No newline at end of file diff --git a/python/testData/refactoring/introduceVariable/generatorParameter.py b/python/testData/refactoring/introduceVariable/generatorParameter.py new file mode 100644 index 000000000000..938c22ab0ed1 --- /dev/null +++ b/python/testData/refactoring/introduceVariable/generatorParameter.py @@ -0,0 +1 @@ +any(row for row in [123] if row == "beetle") \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java index 5899104b9490..f2117977cbf3 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java @@ -224,6 +224,10 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase { doTest(); } + public void testGeneratorParameter() { + doTest(); + } + // PY-10964 public void testMultiReference() { myFixture.configureByFile(getTestName(true) + ".py");