mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
"resolve to attribute assigned nearby" logic should also work when qualifier type is unknown; provide test
This commit is contained in:
@@ -69,13 +69,17 @@ public class PyQualifiedReference extends PyReferenceImpl {
|
||||
return ret; // qualifier is positive that such name cannot exist in it
|
||||
}
|
||||
ret.addAll(membersOfQualifier);
|
||||
}
|
||||
|
||||
// enrich the type info with any fields assigned nearby
|
||||
if (qualifier instanceof PyQualifiedExpression && ret.isEmpty()) {
|
||||
if (addAssignedAttributes(ret, referencedName, (PyQualifiedExpression)qualifier)) return ret;
|
||||
// look for assignment of this attribute in containing function
|
||||
if (qualifier instanceof PyQualifiedExpression && ret.isEmpty()) {
|
||||
if (addAssignedAttributes(ret, referencedName, (PyQualifiedExpression)qualifier)) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else if (myContext.allowImplicits() && canQualifyAnImplicitName(qualifier, qualifierType)) {
|
||||
|
||||
if ((qualifierType == null || qualifierType instanceof PyTypeReference) &&
|
||||
myContext.allowImplicits() && canQualifyAnImplicitName(qualifier, qualifierType)) {
|
||||
addImplicitResolveResults(referencedName, ret);
|
||||
}
|
||||
|
||||
@@ -196,13 +200,10 @@ public class PyQualifiedReference extends PyReferenceImpl {
|
||||
}
|
||||
|
||||
private static boolean addAssignedAttributes(ResolveResultList ret, String referencedName, PyQualifiedExpression qualifier) {
|
||||
List<PyExpression> qualifier_path = PyResolveUtil.unwindQualifiers(qualifier);
|
||||
if (qualifier_path != null) {
|
||||
for (PyExpression ex : collectAssignedAttributes(qualifier)) {
|
||||
if (referencedName.equals(ex.getName())) {
|
||||
ret.poke(ex, RatedResolveResult.RATE_NORMAL);
|
||||
return true;
|
||||
}
|
||||
for (PyExpression ex : collectAssignedAttributes(qualifier)) {
|
||||
if (referencedName.equals(ex.getName())) {
|
||||
ret.poke(ex, RatedResolveResult.RATE_NORMAL);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
def foo(bar):
|
||||
bar.xyzzy = 1
|
||||
print bar.xyzzy
|
||||
# <ref>
|
||||
@@ -432,4 +432,8 @@ public class PyResolveTest extends PyResolveTestCase {
|
||||
final PsiElement psiElement = resolveResults[0].getElement();
|
||||
assertTrue(psiElement instanceof PyTargetExpression && "xyzzy".equals(((PyTargetExpression)psiElement).getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testAttributeAssignedNearby() {
|
||||
assertResolvesTo(PyTargetExpression.class, "xyzzy");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user