mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Skipping ""Access to a protected member" for "_meta" for PY-16477
This commit is contained in:
@@ -18,6 +18,8 @@ package com.jetbrains.python.codeInsight;
|
||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPolyVariantReference;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.Function;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
@@ -206,6 +208,19 @@ public class PyCustomMember {
|
||||
return myFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if some reference points to this element
|
||||
* @param reference reference to check
|
||||
* @return true if reference points to it
|
||||
*/
|
||||
public final boolean isReferenceToMe(@NotNull final PsiReference reference) {
|
||||
final PsiElement element = reference.resolve();
|
||||
if (!(element instanceof MyInstanceElement)) {
|
||||
return false;
|
||||
}
|
||||
return ((MyInstanceElement)element).getThis().equals(this);
|
||||
}
|
||||
|
||||
private class MyInstanceElement extends ASTWrapperPsiElement implements PyTypedElement {
|
||||
private final PyClass myClass;
|
||||
private final PsiElement myContext;
|
||||
@@ -216,6 +231,10 @@ public class PyCustomMember {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
private PyCustomMember getThis() {
|
||||
return PyCustomMember.this;
|
||||
}
|
||||
|
||||
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
|
||||
if (myTypeCallback != null) {
|
||||
return myTypeCallback.fun(myContext);
|
||||
|
||||
@@ -18,11 +18,9 @@ package com.jetbrains.python.inspections;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.jetbrains.python.psi.PyDocStringOwner;
|
||||
import com.jetbrains.python.psi.PyElement;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyQualifiedExpression;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -60,4 +58,15 @@ public abstract class PyInspectionExtension {
|
||||
public boolean ignoreUnresolvedMember(@NotNull PyType type, @NotNull String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if access to protected (the one started with "_") symbol should not be treated as violation.
|
||||
*
|
||||
* @param expression access expression i.e. "_foo"
|
||||
* @param context type eval to be used
|
||||
* @return true if ignore
|
||||
*/
|
||||
public boolean ignoreProtectedSymbol(@NotNull final PyReferenceExpression expression, @NotNull final TypeEvalContext context) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,11 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
if (name != null && name.startsWith("_") && !name.startsWith("__") && !name.endsWith("__")) {
|
||||
final PsiReference reference = node.getReference(getResolveContext());
|
||||
if (reference == null) return;
|
||||
for (final PyInspectionExtension inspectionExtension : PyInspectionExtension.EP_NAME.getExtensions()) {
|
||||
if (inspectionExtension.ignoreProtectedSymbol(node, myTypeEvalContext)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiElement resolvedExpression = reference.resolve();
|
||||
final PyClass resolvedClass = getClassOwner(resolvedExpression);
|
||||
if (resolvedExpression instanceof PyTargetExpression) {
|
||||
|
||||
Reference in New Issue
Block a user