mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Pass type eval context to PyInspectionExtension.ignoreUnresolvedReference
This commit is contained in:
+3
-2
@@ -4,18 +4,19 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
import com.jetbrains.python.inspections.PyInspectionExtension;
|
||||
import com.jetbrains.python.psi.PyElement;
|
||||
import com.jetbrains.python.psi.PyImportStatementBase;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PyStudyInspectionExtension extends PyInspectionExtension {
|
||||
|
||||
@Override
|
||||
public boolean ignoreUnresolvedReference(@NotNull PyElement element, @NotNull PsiReference reference) {
|
||||
public boolean ignoreUnresolvedReference(@NotNull PyElement element, @NotNull PsiReference reference, @NotNull TypeEvalContext context) {
|
||||
final PsiFile file = element.getContainingFile();
|
||||
final Project project = file.getProject();
|
||||
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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-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.
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
@@ -51,7 +37,28 @@ public abstract class PyInspectionExtension {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if unresolved reference could be ignored.
|
||||
*
|
||||
* @param node element containing reference
|
||||
* @param reference unresolved reference
|
||||
* @return true if the unresolved reference could be ignored
|
||||
* @deprecated Use {@link PyInspectionExtension#ignoreUnresolvedReference(PyElement, PsiReference, TypeEvalContext)} instead.
|
||||
* This method will be remove in 2018.2.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean ignoreUnresolvedReference(@NotNull PyElement node, @NotNull PsiReference reference) {
|
||||
return ignoreUnresolvedReference(node, reference, TypeEvalContext.codeInsightFallback(node.getProject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if unresolved reference could be ignored.
|
||||
*
|
||||
* @param node element containing reference
|
||||
* @param reference unresolved reference
|
||||
* @return true if the unresolved reference could be ignored
|
||||
*/
|
||||
public boolean ignoreUnresolvedReference(@NotNull PyElement node, @NotNull PsiReference reference, @NotNull TypeEvalContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ class PyStdlibInspectionExtension : PyInspectionExtension() {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun ignoreUnresolvedReference(node: PyElement, reference: PsiReference): Boolean {
|
||||
override fun ignoreUnresolvedReference(node: PyElement, reference: PsiReference, context: TypeEvalContext): Boolean {
|
||||
if (node is PyReferenceExpression && node.isQualified) {
|
||||
val qualifier = node.qualifier
|
||||
if (qualifier is PyReferenceExpression) {
|
||||
return PyStdlibClassMembersProvider.referenceToMockPatch(qualifier, TypeEvalContext.codeInsightFallback(qualifier.project)) &&
|
||||
return PyStdlibClassMembersProvider.referenceToMockPatch(qualifier, context) &&
|
||||
PyStdlibClassMembersProvider.MOCK_PATCH_MEMBERS.find { it.name == node.name } != null
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -380,7 +380,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
if (unresolved) {
|
||||
boolean ignoreUnresolved = false;
|
||||
for (PyInspectionExtension extension : Extensions.getExtensions(PyInspectionExtension.EP_NAME)) {
|
||||
if (extension.ignoreUnresolvedReference(node, reference)) {
|
||||
if (extension.ignoreUnresolvedReference(node, reference, myTypeEvalContext)) {
|
||||
ignoreUnresolved = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user