fixed EDU-429 Import inspection doesn't work in PE-142.4424
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Thu, 3 Sep 2015 11:49:11 +0000 (14:49 +0300)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Thu, 3 Sep 2015 12:53:51 +0000 (15:53 +0300)
python/edu/interactive-learning-python/resources/META-INF/plugin.xml
python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/highlighting/PyStudyInspectionExtension.java [new file with mode: 0644]
python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/highlighting/PyStudyVisitorFilter.java [deleted file]

index 99cd52d452cc238862dde2bd95d0056b126b9c44..3fe9801d8ea43fa32e4fc9e0d9ec42f572c85bc6 100644 (file)
@@ -22,7 +22,7 @@
     <directoryProjectGenerator implementation="com.jetbrains.edu.learning.PyStudyDirectoryProjectGenerator"/>
   </extensions>
   <extensions defaultExtensionNs="Pythonid">
-    <visitorFilter language="Python" implementationClass="com.jetbrains.edu.learning.highlighting.PyStudyVisitorFilter"/>
+    <inspectionExtension implementation="com.jetbrains.edu.learning.highlighting.PyStudyInspectionExtension"/>
     <pyReferenceResolveProvider implementation="com.jetbrains.edu.learning.PyStudyReferenceResolveProvider"/>
   </extensions>
   <extensions defaultExtensionNs="Edu">
diff --git a/python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/highlighting/PyStudyInspectionExtension.java b/python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/highlighting/PyStudyInspectionExtension.java
new file mode 100644 (file)
index 0000000..112b052
--- /dev/null
@@ -0,0 +1,26 @@
+package com.jetbrains.edu.learning.highlighting;
+
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.jetbrains.edu.learning.StudyTaskManager;
+import com.jetbrains.python.inspections.PyInspectionExtension;
+import com.jetbrains.python.psi.PyElement;
+import com.jetbrains.python.psi.PyImportStatement;
+import org.jetbrains.annotations.NotNull;
+
+public class PyStudyInspectionExtension extends PyInspectionExtension {
+
+  @Override
+  public boolean ignoreUnresolvedReference(@NotNull PyElement element, @NotNull PsiReference reference) {
+    final PsiFile file = element.getContainingFile();
+    if (StudyTaskManager.getInstance(file.getProject()).getCourse() != null) {
+      if (PsiTreeUtil.getParentOfType(element, PyImportStatement.class) != null) {
+        return false;
+      }
+      return true;
+    }
+    return false;
+  }
+
+}
diff --git a/python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/highlighting/PyStudyVisitorFilter.java b/python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/highlighting/PyStudyVisitorFilter.java
deleted file mode 100644 (file)
index 4b849da..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.jetbrains.edu.learning.highlighting;
-
-import com.intellij.psi.PsiFile;
-import com.jetbrains.edu.learning.StudyTaskManager;
-import com.jetbrains.python.inspections.PythonVisitorFilter;
-import com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesInspection;
-import org.jetbrains.annotations.NotNull;
-
-public class PyStudyVisitorFilter implements PythonVisitorFilter {
-  @Override
-  public boolean isSupported(@NotNull final Class visitorClass, @NotNull final PsiFile file) {
-    if (StudyTaskManager.getInstance(file.getProject()).getCourse() == null) return true;
-    if (visitorClass == PyUnresolvedReferencesInspection.class) {
-      return false;
-    }
-    return true;
-  }
-}