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
This commit is contained in:
Vladimir Koshelev
2019-10-01 17:02:43 +00:00
committed by intellij-monorepo-bot
parent e615593cd5
commit 6dd9be576f
2 changed files with 17 additions and 17 deletions
@@ -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;
}
}
@@ -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