From 6dd9be576f6fc15edd957ad7ee1f81b00ffc448b Mon Sep 17 00:00:00 2001 From: Vladimir Koshelev Date: Tue, 1 Oct 2019 19:00:55 +0300 Subject: [PATCH] IDEA-CR-53106: add a method to PyInspectionExtension for ignoring PyInterpreterInspection the method is suitable for ignoring the warning in multi-psi files (cherry picked from commit 7a73e4ab0b1c26d0e99e66371cf0e35a41b0ccd8) GitOrigin-RevId: 72ca3d99f71df14f2618c6eed7fb118f1fc54fe6 --- .../inspections/PyInspectionExtension.java | 12 +++++++++- .../inspections/PyInterpreterInspection.java | 22 +++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) 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 531adaf4cfe5..412d68cfd006 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 @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.inspections; import com.intellij.openapi.extensions.ExtensionPointName; @@ -103,4 +103,14 @@ public abstract class PyInspectionExtension { public boolean ignoreTrailingSemicolon(@NotNull PyStatement statement) { return false; } + + /** + * Checks whether Python interpreter is required for the python file. + * + * @param file file being analyzed + * @return true if missing Python interpreter should be ignored + */ + public boolean ignoreMissingInterpreter(@NotNull PyFile file) { + return false; + } } diff --git a/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java b/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java index e3f384d78b76..e5044de451ae 100644 --- a/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.inspections; import com.intellij.codeInspection.LocalInspectionToolSession; @@ -68,7 +54,7 @@ public class PyInterpreterInspection extends PyInspection { @Override public void visitPyFile(PyFile node) { final Module module = ModuleUtilCore.findModuleForPsiElement(node); - if (module == null) return; + if (module == null || isFileIgnored(node)) return; final Sdk sdk = PythonSdkUtil.findPythonSdk(module); final boolean pyCharm = PlatformUtils.isPyCharm(); @@ -115,6 +101,10 @@ public class PyInterpreterInspection extends PyInspection { } } + private static boolean isFileIgnored(@NotNull PyFile pyFile) { + return PyInspectionExtension.EP_NAME.getExtensionList().stream().anyMatch(ep -> ep.ignoreMissingInterpreter(pyFile)); + } + public static final class ConfigureInterpreterFix implements LocalQuickFix { @NotNull @Override