correctly resolve assignment to multiple instance fields as a tuple

This commit is contained in:
Dmitry Jemerov
2008-03-20 16:41:26 +03:00
parent 86d9f1b69b
commit d211e7cf37
3 changed files with 20 additions and 8 deletions
@@ -43,19 +43,20 @@ public class PyAssignmentStatementImpl extends PyElementImpl implements PyAssign
pyVisitor.visitPyAssignmentStatement(this);
}
@PsiCached
public PyExpression[] getTargets() {
//TODO: this is incomplete. it should look for the = sign
final ASTNode[] nodes = getNode().getChildren(PyElementTypes.EXPRESSIONS);
ASTNode[] targets = new ASTNode[nodes.length - 1];
System.arraycopy(nodes, 0, targets, 0, nodes.length - 1);
return PyPsiUtils.nodesToPsi(targets, PyExpression.EMPTY_ARRAY);
if (nodes.length > 0) {
final PyExpression target = (PyExpression) nodes [0].getPsi();
if (target instanceof PyTupleExpression) {
return ((PyTupleExpression) target).getElements();
}
return new PyExpression[] { target };
}
return PyExpression.EMPTY_ARRAY;
}
@PsiCached
public
@Nullable
PyExpression getAssignedValue() {
public PyExpression getAssignedValue() {
PsiElement child = getLastChild();
while (child != null && !(child instanceof PyExpression)) {
child = child.getPrevSibling();
@@ -0,0 +1,6 @@
class A:
def __init__(self, aa, bb):
self.aa, self.bb = aa, bb
def f(self):
print self.b<ref>b
@@ -82,6 +82,11 @@ public class PyResolveTest extends ResolveTestCase {
assertTrue(targetElement instanceof PyTargetExpression);
}
public void testMultipleFields() throws Exception {
PsiElement targetElement = resolve();
assertTrue(targetElement instanceof PyTargetExpression);
}
@Override
protected String getTestDataPath() {
return PathManager.getHomePath() + "/plugins/python/testData/resolve/";