EDU-377 NPE in pure python project
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Fri, 24 Jul 2015 12:50:31 +0000 (15:50 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Fri, 24 Jul 2015 12:50:31 +0000 (15:50 +0300)
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRenameTaskFileAction.java

index 6f1ca90a9a3fe7c71302a3d8a4c4f98352dd695d..9ece19124cc293e41e823bfca3c2d68b073e9c19 100644 (file)
@@ -2,7 +2,9 @@ package com.jetbrains.edu.learning.actions;
 
 import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
 import com.intellij.refactoring.actions.RenameElementAction;
 import com.jetbrains.edu.learning.StudyUtils;
 import org.jetbrains.annotations.NotNull;
@@ -15,8 +17,11 @@ public class StudyRenameTaskFileAction extends RenameElementAction {
   }
 
   private static boolean isTaskFile(PsiElement element) {
-    return element != null && StudyUtils.getTaskFile(element.getProject(),
-                                  element.getContainingFile().getVirtualFile()) != null;
+    if (element == null || element instanceof PsiDirectory) {
+      return false;
+    }
+    PsiFile file = element.getContainingFile();
+    return file != null && StudyUtils.getTaskFile(element.getProject(), file.getVirtualFile()) != null;
   }
 
   @Override