From 767c92bcaa5378ea970569f474d2ac476bcacc62 Mon Sep 17 00:00:00 2001 From: fitermay Date: Fri, 25 Aug 2017 06:46:47 +0300 Subject: [PATCH] PY-25794: prevent PyProtectedMemberInspection from unnecessarily unstubbing superclasses (cherry picked from commit 4720047) --- .../inspections/PyProtectedMemberInspection.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java index 8a7bb3cb7670..59b1c4bb22c6 100644 --- a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java @@ -33,9 +33,9 @@ import com.jetbrains.python.inspections.quickfix.PyAddPropertyForFieldQuickFix; import com.jetbrains.python.inspections.quickfix.PyMakePublicQuickFix; import com.jetbrains.python.inspections.quickfix.PyRenameElementQuickFix; import com.jetbrains.python.psi.*; +import com.jetbrains.python.psi.types.PyClassType; import com.jetbrains.python.psi.types.PyModuleType; import com.jetbrains.python.psi.types.PyType; -import com.jetbrains.python.refactoring.PyRefactoringUtil; import com.jetbrains.python.testing.PyTestsSharedKt; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -43,8 +43,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Set; /** * User: ktisha @@ -121,16 +121,22 @@ public class PyProtectedMemberInspection extends PyInspection { } final PsiElement resolvedExpression = reference.resolve(); final PyClass resolvedClass = getClassOwner(resolvedExpression); + if (resolvedExpression instanceof PyTargetExpression) { + final String newName = StringUtil.trimLeading(name, '_'); if (resolvedClass != null) { + final String qFixName = resolvedClass.getProperties().containsKey(newName) ? PyBundle.message("QFIX.use.property") : PyBundle.message("QFIX.add.property"); quickFixes.add(new PyAddPropertyForFieldQuickFix(qFixName)); - final Collection usedNames = PyRefactoringUtil.collectUsedNames(resolvedClass); - if (!usedNames.contains(newName)) { - quickFixes.add(new PyMakePublicQuickFix()); + final PyClassType classType = PyUtil.as(myTypeEvalContext.getType(resolvedClass), PyClassType.class); + if (classType != null) { + final Set usedNames = classType.getMemberNames(true, myTypeEvalContext); + if (!usedNames.contains(newName)) { + quickFixes.add(new PyMakePublicQuickFix()); + } } } }