Closes PY-58.

This commit is contained in:
Dmitry Cheryasov
2008-08-23 08:07:19 +04:00
parent 1774933718
commit b7282f1e37
4 changed files with 30 additions and 6 deletions
@@ -27,6 +27,9 @@ import com.jetbrains.python.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: yole
@@ -46,14 +49,16 @@ public class PyAssignmentStatementImpl extends PyElementImpl implements PyAssign
public PyExpression[] getTargets() {
final ASTNode[] nodes = getNode().getChildren(PyElementTypes.EXPRESSIONS);
if (nodes.length > 0) {
final PyExpression target = (PyExpression) nodes [0].getPsi();
if (target instanceof PyTupleExpression) {
return ((PyTupleExpression) target).getElements();
PyExpression[] psi_nodes = new PyExpression[nodes.length];
for (int i = 0; i < nodes.length; i += 1) psi_nodes[i] = (PyExpression)nodes[i].getPsi();
List<PyExpression> candidates = PyUtil.flattenedParens(psi_nodes); // put all possible tuples to one level
List<PyExpression> targets = new ArrayList<PyExpression>();
for (PyExpression expr : candidates) { // only filter out targets
if (expr instanceof PyTargetExpression) {
targets.add(expr);
}
return new PyExpression[] { target };
}
return PyExpression.EMPTY_ARRAY;
return targets.toArray(new PyExpression[targets.size()]);
}
/**
+2
View File
@@ -0,0 +1,2 @@
aa = bb = cc = 1
b<ref>b
@@ -0,0 +1,2 @@
(aa, (bb, cc)) = (1, (2, 3))
b<ref>b
@@ -7,6 +7,7 @@ package com.jetbrains.python;
import com.intellij.openapi.application.PathManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.ResolveTestCase;
import com.jetbrains.python.psi.*;
@@ -117,6 +118,20 @@ public class PyResolveTest extends ResolveTestCase {
assertTrue(targetElement.getParent() instanceof PyAssignmentStatement);
}
public void testMultiTarget() throws Exception {
PsiElement targetElement = resolve();
assertTrue(targetElement instanceof PyTargetExpression);
assertTrue(targetElement.getParent() instanceof PyAssignmentStatement);
}
public void testMultiTargetTuple() throws Exception {
PsiElement targetElement = resolve();
assertTrue(targetElement instanceof PyTargetExpression);
assertNotNull(PsiTreeUtil.getParentOfType(targetElement, PyAssignmentStatement.class)); // it's deep in a tuple
}
@Override
protected String getTestDataPath() {
return PathManager.getHomePath() + "/plugins/python/testData/resolve/";