Fix usages of broken PythonSdkType.getSdk method, which didn't take in account a...
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 14 Feb 2017 14:32:59 +0000 (15:32 +0100)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 14 Feb 2017 14:34:27 +0000 (15:34 +0100)
python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonBaseProjectGenerator.java
python/src/com/jetbrains/python/codeInsight/userSkeletons/PyUserSkeletonsUtil.java
python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java
python/src/com/jetbrains/python/psi/resolve/PyResolveImportUtil.kt
python/src/com/jetbrains/python/sdk/PySdkUtil.java
python/src/com/jetbrains/python/sdk/PythonSdkType.java

index d2c9d565e367badc512c5509018c9e7274101ad3..e3db007e52fc3736519c5d0c460b594aeb7b7716 100644 (file)
@@ -74,7 +74,7 @@ public class PythonBaseProjectGenerator extends PythonProjectGenerator<PyNewProj
   @NotNull
   @Override
   public ValidationResult validate(@NotNull String baseDirPath) {
-    /*if (PythonSdkType.isRemote(myProjectAction.getSdk())) {
+    /*if (PythonSdkType.isRemote(myProjectAction.findPythonSdk())) {
       if (PythonRemoteInterpreterManager.getInstance() == null) {
         return new ValidationResult(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED);
       }
index 59993e6646e29937cdcc9d5ffe9c13dd89fbb814..baf0bdfdbe2e52ba7024d23dc0359ea3cd2717d6 100644 (file)
@@ -118,7 +118,7 @@ public class PyUserSkeletonsUtil {
 
   @Nullable
   public static PyFile getUserSkeletonForModuleQName(@NotNull String qName, @NotNull PsiElement foothold) {
-    final Sdk sdk = PythonSdkType.getSdk(foothold);
+    final Sdk sdk = PythonSdkType.findPythonSdk(foothold);
     if (sdk != null) {
       final Project project = foothold.getProject();
       final PythonSdkPathCache cache = PythonSdkPathCache.getInstance(project, sdk);
index a13f4bb95895598c4f09a39c6d226492eae28c74..5bcec2e4273fafddc9aff750158cfe78318dad81 100644 (file)
@@ -149,7 +149,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
           myIsEnabled = false;
         }
         else if (isPyCharm) {
-          myIsEnabled = PythonSdkType.getSdk(anchor) != null || PyUtil.isInScratchFile(anchor);
+          myIsEnabled = PythonSdkType.findPythonSdk(anchor) != null || PyUtil.isInScratchFile(anchor);
         }
         else {
           myIsEnabled = true;
index f09c182811a2bc2116b22e47318436348e252a45..302b8d3a121a753c4458605de71d8c671e56d11f 100644 (file)
@@ -166,7 +166,7 @@ private fun relativeResultsFromSkeletons(name: QualifiedName, context: PyQualifi
       val containingName = QualifiedNameFinder.findCanonicalImportPath(containingDirectory, null)
       if (containingName != null && containingName.componentCount > 0) {
         val absoluteName = containingName.append(name)
-        val sdk = PythonSdkType.getSdk(footholdFile) ?: return emptyList()
+        val sdk = PythonSdkType.findPythonSdk(footholdFile) ?: return emptyList()
         val skeletonsVirtualFile = PySdkUtil.findSkeletonsDir(sdk) ?: return emptyList()
         val skeletonsDir = context.psiManager.findDirectory(skeletonsVirtualFile)
         return resolveModuleAt(absoluteName, skeletonsDir, context)
index 0c362badc0c85d0df8e018231c0527dba2d5afc3..48210bbd82e7634d58591b523f406d51ecb36359 100644 (file)
@@ -199,7 +199,7 @@ public class PySdkUtil {
     if (file != null) {
       final VirtualFile virtualFile = file.getVirtualFile();
       if (virtualFile != null) {
-        final Sdk sdk = PythonSdkType.getSdk(element);
+        final Sdk sdk = PythonSdkType.findPythonSdk(element);
         if (sdk != null) {
           final VirtualFile skeletonsDir = findSkeletonsDir(sdk);
           if (skeletonsDir != null && VfsUtilCore.isAncestor(skeletonsDir, virtualFile, false)) {
index ad437e20a644b6c7af2399b56ac34be95af2708c..173e4c8861d8ff5df963e7788e66955febdcf080 100644 (file)
@@ -692,6 +692,11 @@ public final class PythonSdkType extends SdkType {
     return null;
   }
 
+  @Nullable
+  public static Sdk findPythonSdk(@NotNull final PsiElement element) {
+    return findPythonSdk(ModuleUtilCore.findModuleForPsiElement(element));
+  }
+
   @Nullable
   public static Sdk findSdkByPath(@Nullable String path) {
     if (path != null) {
@@ -901,13 +906,10 @@ public final class PythonSdkType extends SdkType {
     return false;
   }
 
+  @Deprecated
   @Nullable
   public static Sdk getSdk(@NotNull final PsiElement element) {
-    Module module = ModuleUtilCore.findModuleForPsiElement(element);
-    if (module == null) {
-      return null;
-    }
-    return ModuleRootManager.getInstance(module).getSdk();
+    return findPythonSdk(element);
   }
 
   @NotNull