PY-6637 Hide Python refactorings in library sources
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Tue, 29 Sep 2015 15:11:40 +0000 (18:11 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 5 Oct 2015 10:09:01 +0000 (13:09 +0300)
python/src/com/jetbrains/python/refactoring/PyBaseRefactoringAction.java
python/src/com/jetbrains/python/refactoring/convertTopLevelFunction/PyConvertLocalFunctionToTopLevelFunctionAction.java

index 836f0b6abe23466536b162dc59a1ae76d8f25c48..60d076dc1586c977e411e51eef8f38912fbc36b1 100644 (file)
@@ -18,6 +18,8 @@ package com.jetbrains.python.refactoring;
 import com.intellij.lang.Language;
 import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.refactoring.actions.BaseRefactoringAction;
@@ -56,6 +58,14 @@ public abstract class PyBaseRefactoringAction extends BaseRefactoringAction {
 
   @Override
   protected boolean isAvailableForFile(PsiFile file) {
-    return isAvailableForLanguage(file.getLanguage());
+    return isAvailableForLanguage(file.getLanguage()) && !isLibraryFile(file);
+  }
+
+  private static boolean isLibraryFile(@NotNull PsiFile file) {
+    final VirtualFile virtualFile = file.getVirtualFile();
+    if (virtualFile != null && ProjectRootManager.getInstance(file.getProject()).getFileIndex().isInLibraryClasses(virtualFile)) {
+      return true;
+    }
+    return false;
   }
 }
index eb71a4de52cb666f11bd012b6962af0be98d9f14..c990839fc06fc6c2eff9bb5526ce193fb0ee5799 100644 (file)
@@ -90,12 +90,6 @@ public class PyConvertLocalFunctionToTopLevelFunctionAction extends PyBaseRefact
         result = (PyFunction)resolved;
       }
     }
-    //if (result != null) {
-    //  final VirtualFile virtualFile = result.getContainingFile().getVirtualFile();
-    //  if (virtualFile != null && ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInLibraryClasses(virtualFile)) {
-    //    return null;
-    //  }
-    //}
     return result;
   }