mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote branch 'origin/master'
This commit is contained in:
@@ -43,31 +43,8 @@ setProperty("pluginFilter", [
|
||||
"python-remote-interpreter"
|
||||
])
|
||||
|
||||
private List platformImplementationModules() {
|
||||
return [
|
||||
"core-impl",
|
||||
"RegExpSupport",
|
||||
"license_common",
|
||||
"platform-ultimate",
|
||||
"platform-impl",
|
||||
"vcs-impl",
|
||||
"lang-impl",
|
||||
"testRunner",
|
||||
"smRunner",
|
||||
"xdebugger-impl",
|
||||
"xml",
|
||||
"relaxng",
|
||||
"lvcs-impl",
|
||||
"images",
|
||||
"spellchecker",
|
||||
"dom-impl",
|
||||
"yaml",
|
||||
"coverage-common"
|
||||
]
|
||||
}
|
||||
|
||||
private List<String> platformApiModules() {
|
||||
return ["core-api", "platform-api", "lvcs-api", "lang-api", "vcs-api", "usageView", "xdebugger-api", "xml-openapi", "dom-openapi", "webide-api"]
|
||||
private List pycharmImplementationModules() {
|
||||
return ["yaml", "coverage-common", "python", "python-ide"]
|
||||
}
|
||||
|
||||
class Paths {
|
||||
@@ -99,7 +76,7 @@ setProperty("buildName", "PY-$buildNumber")
|
||||
|
||||
target('default': "Build artifacts") {
|
||||
def modules = [
|
||||
"python", "python-ide", "python-pydev", "colorSchemes", platformApiModules(), platformImplementationModules(), pluginFilter
|
||||
"python-pydev", "colorSchemes", platformUltimateApiModules, platformUltimateImplementationModules, pycharmImplementationModules(), pluginFilter
|
||||
].flatten()
|
||||
|
||||
loadProject()
|
||||
@@ -242,8 +219,8 @@ private String appInfoFile() {
|
||||
}
|
||||
|
||||
private layoutFull(Map args, String target, Set usedJars) {
|
||||
def openapiModules = platformApiModules()
|
||||
def implementationModules = [platformImplementationModules(), "python", "python-ide"].flatten()
|
||||
def openapiModules = platformUltimateApiModules
|
||||
def implementationModules = [platformUltimateImplementationModules, pycharmImplementationModules()].flatten()
|
||||
|
||||
def result = layout(target) {
|
||||
dir("lib") {
|
||||
|
||||
@@ -24,7 +24,7 @@ but seemingly no one uses them in C extensions yet anyway.
|
||||
# * re.search-bound, ~30% time, in likes of builtins and _gtk with complex docstrings.
|
||||
# None of this can seemingly be easily helped. Maybe there's a simpler and faster parser library?
|
||||
|
||||
VERSION = "1.105" # Must be a number-dot-number string, updated with each change that affects generated skeletons
|
||||
VERSION = "1.106" # Must be a number-dot-number string, updated with each change that affects generated skeletons
|
||||
# Note: DON'T FORGET TO UPDATE!
|
||||
|
||||
VERSION_CONTROL_HEADER_FORMAT = '# from %s by generator %s'
|
||||
@@ -832,6 +832,12 @@ class ModuleRedeclarator(object):
|
||||
else:
|
||||
bin_collections_name = '_collections' # Win / Lin
|
||||
|
||||
if version[0] < 3:
|
||||
datetime_mod = "datetime"
|
||||
else:
|
||||
datetime_mod = "_datetime"
|
||||
|
||||
|
||||
# NOTE: per-module signature data may be lazily imported
|
||||
# keyed by (module_name, class_name, method_name). PREDEFINED_BUILTIN_SIGS might be a layer of it.
|
||||
# value is ("signature", "return_literal")
|
||||
@@ -857,45 +863,45 @@ class ModuleRedeclarator(object):
|
||||
("_struct", "Struct", "unpack"): ("(self, string)", None),
|
||||
("_struct", "Struct", "unpack_from"): ("(self, buffer, offset=0)", None),
|
||||
|
||||
("datetime", "date", "__new__"): ("(cls, year=None, month=None, day=None)", None),
|
||||
("datetime", "date", "fromordinal"): ("(cls, ordinal)", "date(1,1,1)"),
|
||||
("datetime", "date", "fromtimestamp"): ("(cls, timestamp)", "date(1,1,1)"),
|
||||
("datetime", "date", "isocalendar"): ("(self)", "(1, 1, 1)"),
|
||||
("datetime", "date", "isoformat"): ("(self)", DEFAULT_STR_LIT),
|
||||
("datetime", "date", "isoweekday"): ("(self)", INT_LIT),
|
||||
("datetime", "date", "replace"): ("(self, year=None, month=None, day=None)", "date(1,1,1)"),
|
||||
("datetime", "date", "strftime"): ("(self, format)", DEFAULT_STR_LIT),
|
||||
("datetime", "date", "timetuple"): ("(self)", "(0, 0, 0, 0, 0, 0, 0, 0, 0)"),
|
||||
("datetime", "date", "today"): ("(self)", "date(1, 1, 1)"),
|
||||
("datetime", "date", "toordinal"): ("(self)", INT_LIT),
|
||||
("datetime", "date", "weekday"): ("(self)", INT_LIT),
|
||||
("datetime", "timedelta", "__new__"
|
||||
(datetime_mod, "date", "__new__"): ("(cls, year=None, month=None, day=None)", None),
|
||||
(datetime_mod, "date", "fromordinal"): ("(cls, ordinal)", "date(1,1,1)"),
|
||||
(datetime_mod, "date", "fromtimestamp"): ("(cls, timestamp)", "date(1,1,1)"),
|
||||
(datetime_mod, "date", "isocalendar"): ("(self)", "(1, 1, 1)"),
|
||||
(datetime_mod, "date", "isoformat"): ("(self)", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "date", "isoweekday"): ("(self)", INT_LIT),
|
||||
(datetime_mod, "date", "replace"): ("(self, year=None, month=None, day=None)", "date(1,1,1)"),
|
||||
(datetime_mod, "date", "strftime"): ("(self, format)", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "date", "timetuple"): ("(self)", "(0, 0, 0, 0, 0, 0, 0, 0, 0)"),
|
||||
(datetime_mod, "date", "today"): ("(self)", "date(1, 1, 1)"),
|
||||
(datetime_mod, "date", "toordinal"): ("(self)", INT_LIT),
|
||||
(datetime_mod, "date", "weekday"): ("(self)", INT_LIT),
|
||||
(datetime_mod, "timedelta", "__new__"
|
||||
): ("(cls, days=None, seconds=None, microseconds=None, milliseconds=None, minutes=None, hours=None, weeks=None)", None),
|
||||
("datetime", "datetime", "__new__"
|
||||
(datetime_mod, "datetime", "__new__"
|
||||
): ("(cls, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=None)", None),
|
||||
("datetime", "datetime", "astimezone"): ("(self, tz)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "combine"): ("(cls, date, time)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "date"): ("(self)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "fromtimestamp"): ("(cls, timestamp, tz=None)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "isoformat"): ("(self, sep='T')", DEFAULT_STR_LIT),
|
||||
("datetime", "datetime", "now"): ("(cls, tz=None)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "strptime"): ("(cls, date_string, format)", DEFAULT_STR_LIT),
|
||||
("datetime", "datetime", "replace" ):
|
||||
(datetime_mod, "datetime", "astimezone"): ("(self, tz)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "combine"): ("(cls, date, time)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "date"): ("(self)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "fromtimestamp"): ("(cls, timestamp, tz=None)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "isoformat"): ("(self, sep='T')", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "datetime", "now"): ("(cls, tz=None)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "strptime"): ("(cls, date_string, format)", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "datetime", "replace" ):
|
||||
("(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=None)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "time"): ("(self)", "time(0, 0)"),
|
||||
("datetime", "datetime", "timetuple"): ("(self)", "(0, 0, 0, 0, 0, 0, 0, 0, 0)"),
|
||||
("datetime", "datetime", "timetz"): ("(self)", "time(0, 0)"),
|
||||
("datetime", "datetime", "utcfromtimestamp"): ("(self, timestamp)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "utcnow"): ("(cls)", "datetime(1, 1, 1)"),
|
||||
("datetime", "datetime", "utctimetuple"): ("(self)", "(0, 0, 0, 0, 0, 0, 0, 0, 0)"),
|
||||
("datetime", "time", "__new__"): ("(cls, hour=None, minute=None, second=None, microsecond=None, tzinfo=None)", None),
|
||||
("datetime", "time", "isoformat"): ("(self)", DEFAULT_STR_LIT),
|
||||
("datetime", "time", "replace"): ("(self, hour=None, minute=None, second=None, microsecond=None, tzinfo=None)", "time(0, 0)"),
|
||||
("datetime", "time", "strftime"): ("(self, format)", DEFAULT_STR_LIT),
|
||||
("datetime", "tzinfo", "dst"): ("(self, date_time)", INT_LIT),
|
||||
("datetime", "tzinfo", "fromutc"): ("(self, date_time)", "datetime(1, 1, 1)"),
|
||||
("datetime", "tzinfo", "tzname"): ("(self, date_time)", DEFAULT_STR_LIT),
|
||||
("datetime", "tzinfo", "utcoffset"): ("(self, date_time)", INT_LIT),
|
||||
(datetime_mod, "datetime", "time"): ("(self)", "time(0, 0)"),
|
||||
(datetime_mod, "datetime", "timetuple"): ("(self)", "(0, 0, 0, 0, 0, 0, 0, 0, 0)"),
|
||||
(datetime_mod, "datetime", "timetz"): ("(self)", "time(0, 0)"),
|
||||
(datetime_mod, "datetime", "utcfromtimestamp"): ("(self, timestamp)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "utcnow"): ("(cls)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "datetime", "utctimetuple"): ("(self)", "(0, 0, 0, 0, 0, 0, 0, 0, 0)"),
|
||||
(datetime_mod, "time", "__new__"): ("(cls, hour=None, minute=None, second=None, microsecond=None, tzinfo=None)", None),
|
||||
(datetime_mod, "time", "isoformat"): ("(self)", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "time", "replace"): ("(self, hour=None, minute=None, second=None, microsecond=None, tzinfo=None)", "time(0, 0)"),
|
||||
(datetime_mod, "time", "strftime"): ("(self, format)", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "tzinfo", "dst"): ("(self, date_time)", INT_LIT),
|
||||
(datetime_mod, "tzinfo", "fromutc"): ("(self, date_time)", "datetime(1, 1, 1)"),
|
||||
(datetime_mod, "tzinfo", "tzname"): ("(self, date_time)", DEFAULT_STR_LIT),
|
||||
(datetime_mod, "tzinfo", "utcoffset"): ("(self, date_time)", INT_LIT),
|
||||
|
||||
("_io", None, "open"): ("(name, mode=None, buffering=None)", "file('/dev/null')"),
|
||||
("_io", "FileIO", "read"): ("(self, size=-1)", DEFAULT_STR_LIT),
|
||||
@@ -1064,7 +1070,7 @@ class ModuleRedeclarator(object):
|
||||
("Struct", "size"): ('r', G_INT),
|
||||
("Struct", "format"): ('r', G_STR),
|
||||
},
|
||||
"datetime": {
|
||||
datetime_mod: {
|
||||
("datetime", "hour"): ('r', G_INT),
|
||||
("datetime", "minute"): ('r', G_INT),
|
||||
("datetime", "second"): ('r', G_INT),
|
||||
|
||||
@@ -2,8 +2,9 @@ import sys
|
||||
import traceback
|
||||
|
||||
ERROR_WRONG_USAGE = 1
|
||||
ERROR_NO_PACKAGING_TOOLS = 2
|
||||
ERROR_EXCEPTION = 3
|
||||
ERROR_NO_PIP = 2
|
||||
ERROR_NO_DISTRIBUTE = 3
|
||||
ERROR_EXCEPTION = 4
|
||||
|
||||
def exit(retcode):
|
||||
major, minor, micro, release, serial = sys.version_info
|
||||
@@ -28,14 +29,14 @@ def error(message, retcode):
|
||||
|
||||
|
||||
def error_no_pip():
|
||||
error("Python package management tool 'pip' not found. <a href=\"installPip\">Install 'pip'</a>", ERROR_NO_PACKAGING_TOOLS)
|
||||
error("Python package management tool 'pip' not found", ERROR_NO_PIP)
|
||||
|
||||
|
||||
def do_list():
|
||||
try:
|
||||
import pkg_resources
|
||||
except ImportError:
|
||||
error("Python package management tools not found. <a href=\"installDistribute\">Install 'distribute'</a>", ERROR_NO_PACKAGING_TOOLS)
|
||||
error("Python package management tool 'setuptools' or 'distribute' not found", ERROR_NO_DISTRIBUTE)
|
||||
for pkg in pkg_resources.working_set:
|
||||
requires = ':'.join([str(x) for x in pkg.requires()])
|
||||
sys.stdout.write('\t'.join([pkg.project_name, pkg.version, pkg.location, requires])+chr(10))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
(default) 1.92 # anything not explicitly marked
|
||||
|
||||
(built-in) 1.105 # skeletons of all built-in modules are built together
|
||||
(built-in) 1.106 # skeletons of all built-in modules are built together
|
||||
# Note: modules like itertools, etc are "(built-in)" and are ignored if given separately
|
||||
|
||||
_fileio 1.101
|
||||
@@ -15,6 +15,7 @@ sys 1.101
|
||||
thread 1.102
|
||||
_thread 1.102
|
||||
_struct 1.103
|
||||
datetime 1.106
|
||||
|
||||
PyQt4.Qsci 1.94
|
||||
PyQt4.QtAssistant 1.94
|
||||
|
||||
@@ -651,11 +651,11 @@ remote.debug.redirect.output=Redirect output to console
|
||||
remote.debug.suspend.on.connect=Suspend after connect
|
||||
|
||||
# SDK / skeletons
|
||||
sdk.errorlog.$0.mods.fail.in.$1.sdks={0} modules failed in {1} SDKs. <a href=\"#\">Details...</a>
|
||||
sdk.errorlog.$0.mods.fail.in.$1.sdks.$2.completely={0} modules failed in {1} SDKs, {2} SDKs failed <i>completely</i>. <a href=\"#\">Details...</a>
|
||||
sdk.errorlog.$0.mods.fail.in.$1.sdks={0} modules failed in {1} interpreters. <a href=\"#\">Details...</a>
|
||||
sdk.errorlog.$0.mods.fail.in.$1.sdks.$2.completely={0} modules failed in {1} interpreters, {2} interpreters failed <i>completely</i>. <a href=\"#\">Details...</a>
|
||||
sdk.some.skeletons.failed=Some skeletons failed to generate
|
||||
sdk.error.dialog.problems=Skeleton Generation Problems
|
||||
sdk.error.dialog.failed.sdks=Failed SDKs
|
||||
sdk.error.dialog.failed.sdks=Failed interpreters
|
||||
sdk.error.dialog.failed.modules=Failed modules
|
||||
sdk.error.dialog.were.blacklisted=Generation of skeletons for the modules above will be tried again when the modules are updated or a new version of generator is available.
|
||||
sdk.gen.querying.$0=Querying skeleton generator for {0}...
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class ChainedComparisonsQuickFix implements LocalQuickFix {
|
||||
boolean myIsLeftLeft;
|
||||
boolean myIsRightLeft;
|
||||
Boolean getInnerRight;
|
||||
boolean getInnerRight;
|
||||
|
||||
public ChainedComparisonsQuickFix(boolean isLeft, boolean isRight, boolean getInner) {
|
||||
myIsLeftLeft = isLeft;
|
||||
|
||||
@@ -434,8 +434,9 @@ public class PyPackageRequirementsInspection extends PyInspection {
|
||||
final PyElementGenerator generator = PyElementGenerator.getInstance(project);
|
||||
if (mySetupPyRequires != null) {
|
||||
if (mySetupPyRequires.getContainingFile().isWritable()) {
|
||||
final PyStringLiteralExpression literal = generator.createStringLiteralFromString(myPackageName);
|
||||
mySetupPyRequires.add(literal);
|
||||
final String text = String.format("'%s'", myPackageName);
|
||||
final PyExpression generated = generator.createExpressionFromText(myLanguageLevel, text);
|
||||
mySetupPyRequires.add(generated);
|
||||
}
|
||||
}
|
||||
else if (mySetupArgumentList != null) {
|
||||
|
||||
@@ -51,7 +51,8 @@ import java.util.*;
|
||||
public class PyPackageManager {
|
||||
public static final int OK = 0;
|
||||
public static final int ERROR_WRONG_USAGE = 1;
|
||||
public static final int ERROR_NO_PACKAGING_TOOLS = 2;
|
||||
public static final int ERROR_NO_PIP = 2;
|
||||
public static final int ERROR_NO_DISTRIBUTE = 3;
|
||||
public static final int ERROR_INVALID_SDK = -1;
|
||||
public static final int ERROR_TOOL_NOT_FOUND = -2;
|
||||
public static final int ERROR_TIMEOUT = -3;
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -442,18 +441,26 @@ public class PyPackagesPanel extends JPanel {
|
||||
if (!invalid) {
|
||||
String text = null;
|
||||
if (externalProcessException != null) {
|
||||
text = externalProcessException.getMessage();
|
||||
allowCreateVirtualEnv &=
|
||||
externalProcessException.getRetcode() == PyPackageManager.ERROR_NO_PACKAGING_TOOLS;
|
||||
final int retCode = externalProcessException.getRetcode();
|
||||
if (retCode == PyPackageManager.ERROR_NO_PIP) {
|
||||
myHasPip = false;
|
||||
}
|
||||
else if (retCode == PyPackageManager.ERROR_NO_DISTRIBUTE) {
|
||||
myHasDistribute = false;
|
||||
}
|
||||
else {
|
||||
text = externalProcessException.getMessage();
|
||||
}
|
||||
final boolean hasPackagingTools = myHasPip && myHasDistribute;
|
||||
allowCreateVirtualEnv &= !hasPackagingTools;
|
||||
}
|
||||
else if (!myHasDistribute) {
|
||||
text = "Python package management tools not found. <a href=\"" + INSTALL_DISTRIBUTE + "\">Install 'distribute'</a>";
|
||||
}
|
||||
else if (!myHasPip) {
|
||||
text = "Python packaging tool 'pip' not found. <a href=\"" + INSTALL_PIP + "\">Install 'pip'</a>";
|
||||
}
|
||||
if (StringUtil.isEmptyOrSpaces(text) && externalProcessException != null) {
|
||||
text = "Python packaging tool 'pip' not found. <a href=\"" + INSTALL_PIP + "\">Install 'pip'</a>";
|
||||
if (text == null) {
|
||||
if (!myHasDistribute) {
|
||||
text = "Python package management tools not found. <a href=\"" + INSTALL_DISTRIBUTE + "\">Install 'distribute'</a>";
|
||||
}
|
||||
else if (!myHasPip) {
|
||||
text = "Python packaging tool 'pip' not found. <a href=\"" + INSTALL_PIP + "\">Install 'pip'</a>";
|
||||
}
|
||||
}
|
||||
if (text != null) {
|
||||
if (allowCreateVirtualEnv) {
|
||||
|
||||
@@ -267,7 +267,7 @@ public class PyClassRefactoringUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void rememberNamedReferences(final PsiElement element) {
|
||||
public static void rememberNamedReferences(@NotNull final PsiElement element) {
|
||||
element.acceptChildren(new PyRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitPyReferenceExpression(PyReferenceExpression node) {
|
||||
@@ -284,7 +284,7 @@ public class PyClassRefactoringUtil {
|
||||
});
|
||||
}
|
||||
|
||||
private static void rememberReference(PyReferenceExpression node, PsiElement element) {
|
||||
private static void rememberReference(@NotNull PyReferenceExpression node, @NotNull PsiElement element) {
|
||||
// We will remember reference in deepest node (except for references to PyImportedModules, as we need references to modules, not to
|
||||
// their packages)
|
||||
final PyExpression qualifier = node.getQualifier();
|
||||
@@ -294,7 +294,7 @@ public class PyClassRefactoringUtil {
|
||||
final PsiElement target = resolveExpression(node);
|
||||
if (target instanceof PsiNamedElement && !PsiTreeUtil.isAncestor(element, target, false)) {
|
||||
final PyImportElement importElement = getImportElement(node);
|
||||
if (importElement == null && !(target instanceof PsiFileSystemItem)) {
|
||||
if (!inSameFile(element, target) && importElement == null && !(target instanceof PsiFileSystemItem)) {
|
||||
return;
|
||||
}
|
||||
node.putCopyableUserData(ENCODED_IMPORT, (PsiNamedElement)target);
|
||||
@@ -305,6 +305,15 @@ public class PyClassRefactoringUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean inSameFile(@NotNull PsiElement e1, @NotNull PsiElement e2) {
|
||||
final PsiFile f1 = e1.getContainingFile();
|
||||
final PsiFile f2 = e2.getContainingFile();
|
||||
if (f1 == null || f2 == null) {
|
||||
return false;
|
||||
}
|
||||
return f1 == f2;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PyImportElement getImportElement(PyReferenceExpression expr) {
|
||||
for (ResolveResult result : expr.getReference().multiResolve(false)) {
|
||||
|
||||
@@ -14,8 +14,6 @@ import com.intellij.refactoring.move.MoveHandlerDelegate;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
|
||||
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
@@ -91,7 +89,9 @@ public class PyMoveClassOrFunctionDelegate extends MoveHandlerDelegate {
|
||||
|
||||
@Nullable
|
||||
public static PsiNamedElement getElementToMove(@NotNull PsiElement element) {
|
||||
final ScopeOwner owner = (element instanceof ScopeOwner) ? (ScopeOwner)element : ScopeUtil.getScopeOwner(element);
|
||||
return (owner instanceof PsiNamedElement) ? (PsiNamedElement)owner : null;
|
||||
if (element instanceof PsiNamedElement) {
|
||||
return (PsiNamedElement)element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -21,7 +21,6 @@ import com.jetbrains.python.codeInsight.imports.PyImportOptimizer;
|
||||
import com.jetbrains.python.documentation.DocStringTypeReference;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyQualifiedName;
|
||||
import com.jetbrains.python.psi.impl.PyReferenceExpressionImpl;
|
||||
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
|
||||
import com.jetbrains.python.refactoring.PyRefactoringUtil;
|
||||
import com.jetbrains.python.refactoring.classes.PyClassRefactoringUtil;
|
||||
@@ -171,7 +170,9 @@ public class PyMoveClassOrFunctionProcessor extends BaseRefactoringProcessor {
|
||||
return;
|
||||
}
|
||||
if (expr.getQualifier() != null) {
|
||||
final PsiElement newExpr = expr.replace(new PyReferenceExpressionImpl(expr.getNameElement()));
|
||||
final PyElementGenerator generator = PyElementGenerator.getInstance(expr.getProject());
|
||||
final PyExpression generated = generator.createExpressionFromText(LanguageLevel.forElement(expr), expr.getName());
|
||||
final PsiElement newExpr = expr.replace(generated);
|
||||
PyClassRefactoringUtil.insertImport(newExpr, newElement, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +85,14 @@ public class PyMoveFileHandler extends MoveFileHandler {
|
||||
}
|
||||
else if (element instanceof PyReferenceExpression) {
|
||||
updatedFiles.add(file);
|
||||
final PyQualifiedName newElementName = PyQualifiedName.fromComponents(PyClassRefactoringUtil.getOriginalName(newElement));
|
||||
replaceWithQualifiedExpression(element, newElementName);
|
||||
PyClassRefactoringUtil.insertImport(element, newElement, null);
|
||||
if (((PyReferenceExpression)element).getQualifier() != null) {
|
||||
final PyQualifiedName newQualifiedName = ResolveImportUtil.findCanonicalImportPath(newElement, element);
|
||||
replaceWithQualifiedExpression(element, newQualifiedName);
|
||||
} else {
|
||||
final PyQualifiedName newName = PyQualifiedName.fromComponents(PyClassRefactoringUtil.getOriginalName(newElement));
|
||||
replaceWithQualifiedExpression(element, newName);
|
||||
PyClassRefactoringUtil.insertImport(element, newElement, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from p1 import m1
|
||||
from p1.m1 import foo
|
||||
import p1.m1
|
||||
import p1
|
||||
|
||||
m1.foo
|
||||
p1.m1.foo
|
||||
m1.bar
|
||||
m1
|
||||
foo
|
||||
@@ -1,7 +1,8 @@
|
||||
from nonp3 import m1
|
||||
from nonp3.m1 import foo
|
||||
import nonp3.m1
|
||||
|
||||
m1.foo
|
||||
nonp3.m1.foo
|
||||
m1.bar
|
||||
m1
|
||||
foo
|
||||
@@ -0,0 +1,3 @@
|
||||
def f():
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from a import f
|
||||
|
||||
def use_f():
|
||||
f()
|
||||
@@ -0,0 +1,5 @@
|
||||
def f():
|
||||
pass
|
||||
|
||||
def use_f():
|
||||
f()
|
||||
@@ -56,6 +56,7 @@ public class PythonAllTestsSuite {
|
||||
PyFormatterTest.class,
|
||||
PyRenameTest.class,
|
||||
CythonRenameTest.class,
|
||||
PyMoveTest.class,
|
||||
PyExtractMethodTest.class,
|
||||
PyPullUpTest.class,
|
||||
PyPushDownTest.class,
|
||||
|
||||
@@ -110,6 +110,11 @@ public class PyMoveTest extends PyTestCase {
|
||||
doMoveSymbolTest("f", "b.py");
|
||||
}
|
||||
|
||||
// PY-6465
|
||||
public void testUsageFromFunction() {
|
||||
doMoveSymbolTest("use_f", "b.py");
|
||||
}
|
||||
|
||||
private void doMoveFileTest(String fileName, String toDirName) {
|
||||
Project project = myFixture.getProject();
|
||||
PsiManager manager = PsiManager.getInstance(project);
|
||||
|
||||
Reference in New Issue
Block a user