Merge remote-tracking branch 'origin/master'
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Mon, 1 Sep 2014 12:54:29 +0000 (16:54 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Mon, 1 Sep 2014 12:54:29 +0000 (16:54 +0400)
python/src/com/jetbrains/python/inspections/quickfix/PyDefaultArgumentQuickFix.java
python/src/com/jetbrains/python/inspections/quickfix/StatementEffectFunctionCallQuickFix.java
python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java
python/src/com/jetbrains/python/sdk/flavors/WinPythonSdkFlavor.java
python/testData/inspections/DefaultArgumentEmptyList.py
python/testData/inspections/DefaultArgumentEmptyList_after.py

index db47f17f8ea8f9ffdbfd35ace94c9d313d6b05bf..6e0d5c465d0e91c69eb940c4b47aca0f70838f9d 100644 (file)
@@ -61,7 +61,7 @@ public class PyDefaultArgumentQuickFix implements LocalQuickFix {
       PyStatementList list = function.getStatementList();
       PyParameterList paramList = function.getParameterList();
 
-      final StringBuilder functionText = new StringBuilder("def foo(");
+      final StringBuilder functionText = new StringBuilder("def " + function.getName() + "(");
       int size = paramList.getParameters().length;
       for (int i = 0; i != size; ++i) {
         PyParameter p = paramList.getParameters()[i];
index 43f4f039401579ebf08afeebc1285248f1e94b5d..017bf1a1af297269cce25f981cd4e78736b0626d 100644 (file)
@@ -88,7 +88,13 @@ public class StatementEffectFunctionCallQuickFix implements LocalQuickFix {
     if (next instanceof PyExpressionStatement) {
       final PyExpression expr = ((PyExpressionStatement)next).getExpression();
       if (expr instanceof PyBinaryExpression) {
-        addInArguments(stringBuilder, (PyBinaryExpression)expr);
+        final PsiElement operator = ((PyBinaryExpression)expr).getPsiOperator();
+        if (operator instanceof LeafPsiElement && ((LeafPsiElement)operator).getElementType() == PyTokenTypes.IN_KEYWORD) {
+          addInArguments(stringBuilder, (PyBinaryExpression)expr);
+        }
+        else {
+          stringBuilder.append(next.getText());
+        }
       }
       else if (expr instanceof PyTupleExpression) {
         final PyExpression[] elements = ((PyTupleExpression)expr).getElements();
@@ -114,14 +120,11 @@ public class StatementEffectFunctionCallQuickFix implements LocalQuickFix {
   }
 
   private static void addInArguments(@NotNull final StringBuilder stringBuilder, @NotNull final PyBinaryExpression binaryExpression) {
-    final PsiElement operator = binaryExpression.getPsiOperator();
-    if (operator instanceof LeafPsiElement && ((LeafPsiElement)operator).getElementType() == PyTokenTypes.IN_KEYWORD) {
-      stringBuilder.append(binaryExpression.getLeftExpression().getText());
-      stringBuilder.append(", ");
-      final PyExpression rightExpression = binaryExpression.getRightExpression();
-      if (rightExpression != null)
-        stringBuilder.append(rightExpression.getText());
-    }
+    stringBuilder.append(binaryExpression.getLeftExpression().getText());
+    stringBuilder.append(", ");
+    final PyExpression rightExpression = binaryExpression.getRightExpression();
+    if (rightExpression != null)
+      stringBuilder.append(rightExpression.getText());
   }
 
   private static void replacePrint(@NotNull final PsiElement expression) {
index 7e15cab6ffda52fd5f69e7fc4308cd00a209ef50..af767684643e5682feafc6d49f89b517903bf9d8 100644 (file)
@@ -19,7 +19,9 @@ import com.intellij.facet.Facet;
 import com.intellij.facet.FacetManager;
 import com.intellij.openapi.application.Application;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.fileTypes.FileTypeManager;
+import com.intellij.openapi.fileTypes.FileTypeRegistry;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.module.ModuleType;
@@ -163,7 +165,8 @@ public class PythonLanguageLevelPusher implements FilePropertyPusher<LanguageLev
     oStream.close();
 
     for (VirtualFile child : fileOrDir.getChildren()) {
-      if (!child.isDirectory() && PythonFileType.INSTANCE.equals(child.getFileType())) {
+      final FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(child.getName());
+      if (!child.isDirectory() && PythonFileType.INSTANCE.equals(fileType)) {
         PushedFilePropertiesUpdater.getInstance(project).filePropertiesChanged(child);
       }
     }
index 9d22af8c03bf1887a1913b6802bb861ade291845..3a9ac951509d6e2db3fed0d98c8f4b5b0832713e 100644 (file)
@@ -37,6 +37,8 @@ public class WinPythonSdkFlavor extends CPythonSdkFlavor {
                     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Python\\PythonCore", "python.exe",
                     "HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython", "ipy.exe");
 
+  private static Set<String> ourRegistryCache;
+
   private WinPythonSdkFlavor() {
   }
 
@@ -78,18 +80,25 @@ public class WinPythonSdkFlavor extends CPythonSdkFlavor {
   }
 
   public static void findInRegistry(Collection<String> candidates) {
-    for (Map.Entry<String, String> entry : ourRegistryMap.entrySet()) {
-      final String prefix = entry.getKey();
-      final String exePath = entry.getValue();
-      List<String> strings = WindowsRegistryUtil.readRegistryBranch(prefix);
-      for (String string : strings) {
-        final String path =
-          WindowsRegistryUtil.readRegistryDefault(prefix + "\\" + string +
-                                                  "\\InstallPath");
-        if (path != null) {
-          File f = new File(path, exePath);
-          if (f.exists()) {
-            candidates.add(FileUtil.toSystemDependentName(f.getPath()));
+    fillRegistryCache();
+    candidates.addAll(ourRegistryCache);
+  }
+
+  private static void fillRegistryCache() {
+    if (ourRegistryCache == null) {
+      ourRegistryCache = new HashSet<String>();
+      for (Map.Entry<String, String> entry : ourRegistryMap.entrySet()) {
+        final String prefix = entry.getKey();
+        final String exePath = entry.getValue();
+        List<String> strings = WindowsRegistryUtil.readRegistryBranch(prefix);
+        for (String string : strings) {
+          final String path = WindowsRegistryUtil.readRegistryDefault(prefix + "\\" + string +
+                                                                      "\\InstallPath");
+          if (path != null) {
+            File f = new File(path, exePath);
+            if (f.exists()) {
+              ourRegistryCache.add(FileUtil.toSystemDependentName(f.getPath()));
+            }
           }
         }
       }
index 55748eb449d555e7712f4067f3c70a2045be010e..a351c5134c90d83b9d22c2a6e4d3562ac7cb46cd 100644 (file)
@@ -1 +1 @@
-def foo(args=<warning descr="Default argument value is mutable">[<caret>]</warning>):<EOLError descr="Indent expected"></EOLError>
\ No newline at end of file
+def bar(args=<warning descr="Default argument value is mutable">[<caret>]</warning>):<EOLError descr="Indent expected"></EOLError>
\ No newline at end of file
index 2de1bb88ef9250100b3d0ed43c27f91701ca0e38..ada9baaa78657d268f7673eeb6cf431b4915aea3 100644 (file)
@@ -1,3 +1,3 @@
-def foo(args=None):
+def bar(args=None):
     if not args:
         args = []
\ No newline at end of file