Refactored to actually compare sdk instead of weight providing
authorKiryl Chetyrbak <kirylchetyrbak@gmail.com>
Wed, 12 Apr 2017 21:36:40 +0000 (17:36 -0400)
committerKiryl Chetyrbak <kirylchetyrbak@gmail.com>
Wed, 12 Apr 2017 21:36:40 +0000 (17:36 -0400)
python/src/META-INF/python-core-common.xml
python/src/com/jetbrains/python/sdk/PreferredSdkComparator.java
python/src/com/jetbrains/python/sdk/PySdkComparator.java [moved from python/src/com/jetbrains/python/sdk/PySdkWeightProvider.java with 81% similarity]

index 677150ca366068663689dc0fb57f5d2cc89ab131..ea45045544ba6b49f58515f5c25830e9ddef37c2 100644 (file)
     <extensionPoint qualifiedName="Pythonid.pythonFlavorProvider" interface="com.jetbrains.python.sdk.flavors.PythonFlavorProvider"/>
     <extensionPoint qualifiedName="Pythonid.debugSessionFactory" interface="com.jetbrains.python.debugger.PyDebugSessionFactory"/>
     <extensionPoint qualifiedName="Pythonid.customPackageIdentifier" interface="com.jetbrains.python.psi.PyCustomPackageIdentifier"/>
-    <extensionPoint qualifiedName="Pythonid.pythonSdkWeightProvider" interface="com.jetbrains.python.sdk.PySdkWeightProvider" />
+    <extensionPoint qualifiedName="Pythonid.pythonSdkComparator" interface="com.jetbrains.python.sdk.PySdkComparator" />
   </extensionPoints>
 
   <extensions defaultExtensionNs="Pythonid">
index 6de0c34e5d515c7422fae998ca22eb1ada17d8e5..c6478a16d594cc90e2e25c9f7338622ac1711bac 100644 (file)
@@ -32,11 +32,10 @@ public class PreferredSdkComparator implements Comparator<Sdk> {
 
   @Override
   public int compare(Sdk o1, Sdk o2) {
-    for (PySdkWeightProvider provider : Extensions.getExtensions(PySdkWeightProvider.EP_NAME)) {
-      int weight1 = provider.getWeight(o1);
-      int weight2 = provider.getWeight(o2);
-      if(weight1 != weight2) {
-        return weight2 - weight1;
+    for (PySdkComparator comparator : Extensions.getExtensions(PySdkComparator.EP_NAME)) {
+      int result = comparator.compare(o1, o2);
+      if(result != 0) {
+        return result;
       }
     }
 
similarity index 81%
rename from python/src/com/jetbrains/python/sdk/PySdkWeightProvider.java
rename to python/src/com/jetbrains/python/sdk/PySdkComparator.java
index b319aa7326557d37d2e5e264490bed480b686fcb..1e792c3c22614a99c85dfbdcd42d81ed6d3a0961 100644 (file)
@@ -21,8 +21,8 @@ import com.intellij.openapi.projectRoots.Sdk;
 /**
  * Created by kirylch on 3/29/2017.
  */
-public interface PySdkWeightProvider {
-  ExtensionPointName<PySdkWeightProvider> EP_NAME = ExtensionPointName.create("Pythonid.pythonSdkWeightProvider");
+public interface PySdkComparator {
+  ExtensionPointName<PySdkComparator> EP_NAME = ExtensionPointName.create("Pythonid.pythonSdkComparator");
 
-  int getWeight(Sdk sdk);
+  int compare(Sdk sdk1, Sdk sdk2);
 }