Search in sources :

Example 16 with PyTargetExpression

use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.

the class PyAssignmentMappingTest method testMultiple.

public void testMultiple() throws Exception {
    Map<String, PsiElement> marks = loadTest();
    final int TARGET_NUM = 3;
    Assert.assertEquals(TARGET_NUM + 1, marks.size());
    // const -> expr;
    PsiElement src = marks.get("<src>").getParent();
    PsiElement[] dsts = new PsiElement[TARGET_NUM];
    for (int i = 0; i < TARGET_NUM; i += 1) {
        // ident -> target expr
        PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent();
        Assert.assertTrue(dst instanceof PyTargetExpression);
        dsts[i] = dst;
    }
    PyAssignmentStatement stmt = (PyAssignmentStatement) src.getParent();
    List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
    Assert.assertEquals(TARGET_NUM, mapping.size());
    for (int i = 0; i < TARGET_NUM; i += 1) {
        Pair<PyExpression, PyExpression> pair = mapping.get(i);
        Assert.assertEquals(dsts[i], pair.getFirst());
        Assert.assertEquals(src, pair.getSecond());
    }
}
Also used : PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) PyExpression(com.jetbrains.python.psi.PyExpression) PyAssignmentStatement(com.jetbrains.python.psi.PyAssignmentStatement) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

PyTargetExpression (com.jetbrains.python.psi.PyTargetExpression)16 PsiElement (com.intellij.psi.PsiElement)11 PyExpression (com.jetbrains.python.psi.PyExpression)7 Pair (com.intellij.openapi.util.Pair)6 PyAssignmentStatement (com.jetbrains.python.psi.PyAssignmentStatement)6 PyClass (com.jetbrains.python.psi.PyClass)3 PyFunction (com.jetbrains.python.psi.PyFunction)3 PyReferenceExpression (com.jetbrains.python.psi.PyReferenceExpression)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiReference (com.intellij.psi.PsiReference)2 PyUtil (com.jetbrains.python.psi.PyUtil)2 Nullable (org.jetbrains.annotations.Nullable)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 Editor (com.intellij.openapi.editor.Editor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiFile (com.intellij.psi.PsiFile)1 PsiNameIdentifierOwner (com.intellij.psi.PsiNameIdentifierOwner)1 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)1 VariableInplaceRenamer (com.intellij.refactoring.rename.inplace.VariableInplaceRenamer)1 PyCustomMember (com.jetbrains.python.codeInsight.PyCustomMember)1