mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-15348 Do not include non-trivial target expressions in the "Move Module Members" dialog
This commit is contained in:
@@ -53,12 +53,17 @@ public class PyMoveModuleMembersHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all top-level variables, classes and functions (in this order) as returned by {@link PyFile#getTopLevelAttributes()},
|
||||
* {@link PyFile#getTopLevelClasses()} and {@link PyFile#getTopLevelFunctions()}.
|
||||
* Collects all movable top-level variables, classes and functions (in this order) as returned by {@link PyFile#getTopLevelAttributes()},
|
||||
* {@link PyFile#getTopLevelClasses()} and {@link PyFile#getTopLevelFunctions()}. Target expression are filtered with
|
||||
* {@link #isTargetOfSimpleAssignment(PsiElement)}.
|
||||
*/
|
||||
public static List<PyElement> getTopLevelModuleMembers(@NotNull PyFile pyFile) {
|
||||
final List<PyElement> result = new ArrayList<PyElement>();
|
||||
result.addAll(pyFile.getTopLevelAttributes());
|
||||
for (PyTargetExpression attr : pyFile.getTopLevelAttributes()) {
|
||||
if (isTargetOfSimpleAssignment(attr)) {
|
||||
result.add(attr);
|
||||
}
|
||||
}
|
||||
result.addAll(pyFile.getTopLevelClasses());
|
||||
result.addAll(pyFile.getTopLevelFunctions());
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
from module import symbol as alias
|
||||
|
||||
CONST = 42
|
||||
|
||||
|
||||
# x is visible externally in Python 2
|
||||
[x for x in range(3)]
|
||||
|
||||
for i in range(3):
|
||||
pass
|
||||
|
||||
if True:
|
||||
class C:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def method(self):
|
||||
pass
|
||||
|
||||
|
||||
def outer_func():
|
||||
def inner_func():
|
||||
pass
|
||||
@@ -30,19 +30,18 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.PythonTestUtil;
|
||||
import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyTargetExpression;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.stubs.PyClassNameIndex;
|
||||
import com.jetbrains.python.psi.stubs.PyFunctionNameIndex;
|
||||
import com.jetbrains.python.psi.stubs.PyVariableNameIndex;
|
||||
import com.jetbrains.python.refactoring.move.PyMoveModuleMembersHelper;
|
||||
import com.jetbrains.python.refactoring.move.PyMoveModuleMembersProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static com.jetbrains.python.refactoring.move.PyMoveModuleMembersHelper.isMovableModuleMember;
|
||||
|
||||
@@ -87,6 +86,19 @@ public class PyMoveTest extends PyTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
// PY-15348
|
||||
public void testCollectMovableModuleMembers() {
|
||||
myFixture.configureByFile("/refactoring/move/" + getTestName(true) + ".py");
|
||||
final List<PyElement> members = PyMoveModuleMembersHelper.getTopLevelModuleMembers((PyFile)myFixture.getFile());
|
||||
final List<String> names = ContainerUtil.map(members, new Function<PyElement, String>() {
|
||||
@Override
|
||||
public String fun(PyElement element) {
|
||||
return element.getName();
|
||||
}
|
||||
});
|
||||
assertSameElements(names, "CONST", "C", "outer_func");
|
||||
}
|
||||
|
||||
// PY-3929
|
||||
// PY-4095
|
||||
public void testImportAs() {
|
||||
|
||||
Reference in New Issue
Block a user