From f475408aaaa915e2bf8778ffd108da98dde4d68d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 7 Aug 2012 15:42:20 +0200 Subject: [PATCH] don't suggest keywords as names in introduce refactoring (PY-6605) --- .../refactoring/introduce/IntroduceHandler.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java index 72f9416fd1d2..6bd8bcc2cd50 100644 --- a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java +++ b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java @@ -26,6 +26,7 @@ import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; 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.psi.*; import com.jetbrains.python.psi.impl.PyPsiUtils; import com.jetbrains.python.psi.resolve.PyResolveContext; @@ -156,7 +157,15 @@ abstract public class IntroduceHandler implements RefactoringActionHandler { } protected Collection generateSuggestedNames(PyExpression expression) { - Collection candidates = new LinkedHashSet(); + Collection candidates = new LinkedHashSet() { + @Override + public boolean add(String s) { + if (PyNames.isReserved(s)) { + return false; + } + return super.add(s); + } + }; String text = expression.getText(); if (expression instanceof PyCallExpression) { final PyExpression callee = ((PyCallExpression)expression).getCallee();