diff --git a/python/python-psi-api/src/com/jetbrains/python/inspections/PyInspectionExtension.java b/python/python-psi-api/src/com/jetbrains/python/inspections/PyInspectionExtension.java index 2e7740f2caf7..83c492b78712 100644 --- a/python/python-psi-api/src/com/jetbrains/python/inspections/PyInspectionExtension.java +++ b/python/python-psi-api/src/com/jetbrains/python/inspections/PyInspectionExtension.java @@ -113,4 +113,9 @@ public abstract class PyInspectionExtension { public boolean ignoreInterpreterWarnings(@NotNull PyFile file) { return false; } + + /** + * @return Do not report "unused import" + */ + public boolean unusedImportShouldBeSkipped(@NotNull PyImportedNameDefiner importNameDefiner) {return false;} } diff --git a/python/src/META-INF/python-core-common.xml b/python/src/META-INF/python-core-common.xml index 6995d8df9a73..2a3a8b79677e 100644 --- a/python/src/META-INF/python-core-common.xml +++ b/python/src/META-INF/python-core-common.xml @@ -644,7 +644,6 @@ - diff --git a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferenceSkipperExtPoint.java b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferenceSkipperExtPoint.java deleted file mode 100644 index 8a9f4b0aaa24..000000000000 --- a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferenceSkipperExtPoint.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jetbrains.python.inspections.unresolvedReference; - -import com.intellij.openapi.extensions.ExtensionPointName; -import com.jetbrains.python.psi.PyImportedNameDefiner; -import org.jetbrains.annotations.NotNull; - -/** - * Inject this point to ask "unused reference" inspection to skip some unused references. - * For example in Django you may import "I18N" to your "settings.py". It is not used in "settings.py", but used by Django - * and should not be marked as "unused". - * - * @author Ilya.Kazakevich - */ -@Deprecated -//TODO: switch to PyInspectionExtension -public interface PyUnresolvedReferenceSkipperExtPoint { - @NotNull - ExtensionPointName EP_NAME = ExtensionPointName.create("Pythonid.unresolvedReferenceSkipper"); - - /** - * Checks if some unused import should be skipped - * - * @param importNameDefiner unused import - * @return true if should be skipped - */ - boolean unusedImportShouldBeSkipped(@NotNull PyImportedNameDefiner importNameDefiner); -} diff --git a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java index f1f47c19db10..40ed45155914 100644 --- a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java +++ b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java @@ -1086,7 +1086,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { // Remove those unsed, that are reported to be skipped by extension points final Set unusedImportToSkip = new HashSet<>(); for (final PyImportedNameDefiner unusedImport : unusedImports) { - if (importShouldBeSkippedByExtPoint(unusedImport)) { // Pass to extension points + if (PyInspectionExtension.EP_NAME.getExtensionList().stream().anyMatch(o -> o.unusedImportShouldBeSkipped(unusedImport))) { unusedImportToSkip.add(unusedImport); } } @@ -1198,19 +1198,4 @@ public class PyUnresolvedReferencesInspection extends PyInspection { } } } - - /** - * Checks if one or more extension points ask unused import to be skipped - * - * @param importNameDefiner unused import - * @return true of one or more asks - */ - private static boolean importShouldBeSkippedByExtPoint(@NotNull final PyImportedNameDefiner importNameDefiner) { - for (final PyUnresolvedReferenceSkipperExtPoint skipper : PyUnresolvedReferenceSkipperExtPoint.EP_NAME.getExtensions()) { - if (skipper.unusedImportShouldBeSkipped(importNameDefiner)) { - return true; - } - } - return false; - } }