find usages considers a reference to be a usage if it resolves to an element that shadows our name or is shadowed by ours (PY-6241)

This commit is contained in:
Dmitry Jemerov
2013-02-05 20:09:49 +01:00
parent 108b42b84b
commit f4d2b40874
3 changed files with 27 additions and 0 deletions
@@ -446,6 +446,12 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
return true;
}
// we shadow their name or they shadow ours (PY-6241)
if (resolveResult instanceof PsiNamedElement && resolveResult instanceof ScopeOwner && element instanceof ScopeOwner &&
ourScopeOwner == PsiTreeUtil.getParentOfType(resolveResult, ScopeOwner.class)) {
return true;
}
if (!haveQualifiers(element) && ourScopeOwner != null && theirScopeOwner != null) {
if (resolvesToSameGlobal(element, elementName, ourScopeOwner, theirScopeOwner, resolveResult)) return true;
}
@@ -0,0 +1,16 @@
class C(object):
def __init__(self):
self._x = None
@property
def <caret>x(self):
"""I'm the 'x' property."""
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
@@ -127,6 +127,11 @@ public class PyFindUsagesTest extends PyTestCase {
}
}
public void testNameShadowing() { // PY-6241
final Collection<UsageInfo> usages = myFixture.testFindUsages("findUsages/NameShadowing.py");
assertEquals(2, usages.size());
}
private Collection<UsageInfo> findMultiFileUsages(String filename) {
final String testName = getTestName(false);
myFixture.copyDirectoryToProject("findUsages/" + testName, "");