mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correctly resolve assignment to multiple instance fields as a tuple
This commit is contained in:
@@ -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/";
|
||||
|
||||
Reference in New Issue
Block a user