mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-2724 Exclude protected methods from completion list if completion is performed outside a class
This commit is contained in:
@@ -475,7 +475,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
List<Object> ret = new ArrayList<Object>();
|
||||
|
||||
boolean suppressParentheses = context.get(CTX_SUPPRESS_PARENTHESES) != null;
|
||||
addOwnClassMembers(location, namesAlready, suppressParentheses, ret);
|
||||
addOwnClassMembers(location, namesAlready, suppressParentheses, ret, prefix);
|
||||
|
||||
PsiFile origin = (location != null) ?
|
||||
CompletionUtil.getOriginalOrSelf(location)
|
||||
@@ -534,7 +534,11 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
}
|
||||
}
|
||||
|
||||
private void addOwnClassMembers(PsiElement expressionHook, Set<String> namesAlready, boolean suppressParentheses, List<Object> ret) {
|
||||
private void addOwnClassMembers(PsiElement expressionHook,
|
||||
Set<String> namesAlready,
|
||||
boolean suppressParentheses,
|
||||
List<Object> ret,
|
||||
@Nullable final String prefix) {
|
||||
PyClass containingClass = PsiTreeUtil.getParentOfType(expressionHook, PyClass.class);
|
||||
if (containingClass != null) {
|
||||
containingClass = CompletionUtil.getOriginalElement(containingClass);
|
||||
@@ -563,6 +567,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
String name = le.getLookupString();
|
||||
if (namesAlready.contains(name)) continue;
|
||||
if (!withinOurClass && isClassPrivate(name)) continue;
|
||||
if (!withinOurClass && isClassProtected(name) && prefix == null) continue;
|
||||
namesAlready.add(name);
|
||||
ret.add(le);
|
||||
}
|
||||
@@ -623,6 +628,10 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
return lookup_string.startsWith("__") && !lookup_string.endsWith("__");
|
||||
}
|
||||
|
||||
private static boolean isClassProtected(@NotNull final String lookupString) {
|
||||
return lookupString.startsWith("_") && !lookupString.startsWith("__");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getPyClass().getName();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class A:
|
||||
def _foo(self):
|
||||
pass
|
||||
|
||||
|
||||
A().<caret>
|
||||
@@ -0,0 +1,6 @@
|
||||
class A:
|
||||
def _foo(self):
|
||||
pass
|
||||
|
||||
|
||||
A()._foo()
|
||||
@@ -0,0 +1,6 @@
|
||||
class A:
|
||||
def _foo(self):
|
||||
pass
|
||||
|
||||
|
||||
A()._f<caret>
|
||||
@@ -932,6 +932,16 @@ public class PythonCompletionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testProtectedClassNames() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testProtectedClassNameNoPrefix() {
|
||||
final List<String> variants = doTestByFile();
|
||||
assertNotNull(variants);
|
||||
assertDoesntContain(variants, "_foo(self)");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/completion";
|
||||
|
||||
Reference in New Issue
Block a user