mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't suggest any used names as name candidates for introduce variable (PY-4605)
This commit is contained in:
@@ -104,7 +104,7 @@ public class PyRefactoringUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<String> collectScopeVariables(@Nullable final PsiElement scope) {
|
||||
public static Collection<String> collectUsedNames(@Nullable final PsiElement scope) {
|
||||
if (!(scope instanceof PyClass) && !(scope instanceof PyFile) && !(scope instanceof PyFunction)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -121,18 +121,18 @@ public class PyRefactoringUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyStatement(@NotNull final PyStatement node) {
|
||||
if ((node instanceof PyAssignmentStatement) || (scope instanceof PyFunction)) {
|
||||
node.acceptChildren(this);
|
||||
}
|
||||
public void visitPyReferenceExpression(PyReferenceExpression node) {
|
||||
variables.add(node.getReferencedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyFunction(@NotNull final PyFunction node) {
|
||||
variables.add(node.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyClass(@NotNull final PyClass node) {
|
||||
variables.add(node.getName());
|
||||
}
|
||||
});
|
||||
return variables;
|
||||
|
||||
@@ -51,6 +51,6 @@ public abstract class IntroduceValidator {
|
||||
context = psiElement.getContainingFile();
|
||||
}
|
||||
|
||||
return PyRefactoringUtil.collectScopeVariables(context).contains(name);
|
||||
return PyRefactoringUtil.collectUsedNames(context).contains(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
if myfu<caret>nc() == 3:
|
||||
pass
|
||||
@@ -52,6 +52,12 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase {
|
||||
assertFalse(strings.contains("str"));
|
||||
}
|
||||
|
||||
public void testSuggestNamesNotInScope() { // PY-4605
|
||||
final Collection<String> strings = buildSuggestions(PyExpression.class);
|
||||
assertTrue(strings.contains("myfunc1"));
|
||||
assertFalse(strings.contains("myfunc"));
|
||||
}
|
||||
|
||||
public void testIncorrectSelection() { // PY-4455
|
||||
doTestCannotPerform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user