2 * Copyright 2000-2014 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.jetbrains.python.psi;
18 import com.intellij.openapi.util.Pair;
19 import org.jetbrains.annotations.NotNull;
20 import org.jetbrains.annotations.Nullable;
22 import java.util.List;
25 * Describes an assignment statement.
27 public interface PyAssignmentStatement extends PyStatement, PyNamedElementContainer {
30 * @return the left-hand side of the statement; each item may consist of many elements.
32 PyExpression[] getTargets();
35 * Return all expressions which are considered assignment targets (to the left of the last = sign in the statement).
36 * Doesn't unpack tuples, parentheses or anything.
38 * @return the list of assignment target expressions
41 PyExpression[] getRawTargets();
45 * @return right-hand side of the statement; may as well consist of many elements.
48 PyExpression getAssignedValue();
51 * Applies a visitor to every element of left-hand side. Tuple elements are flattened down to their most nested
52 * parts. E.g. if the target is <tt>a, b[1], (c(2).d, e.f)</tt>, then expressions
53 * <tt>a</tt>, <tt>b[1]</tt>, <tt>c(2).d</tt>, <tt>e.f</tt> will be visited.
54 * Order of visiting is not guaranteed.
55 * @param visitor its {@link PyElementVisitor#visitPyExpression} method will be called for each elementary target expression
57 //void visitElementaryTargets(PyElementVisitor visitor);
61 * Maps target expressions to assigned values, unpacking tuple expressions.
62 * For "{@code a, (b, c) = 1, (2, 'foo')}" the result will be [(a,1), (b:2), (c:'foo')].
64 * If there's a number of LHS targets, the RHS expression is mapped to every target.
65 * For "{@code a = b = c = 1}" the result will be [(a,1), (b,1), (c,1)].
67 * Elements of tuples and tuples themselves may get interspersed in complex mappings.
68 * For "{@code a = b,c = 1,2}" the result will be [(a,(1,2)), (b,1), (c,2)].
70 * If RHS and LHS are mis-balanced, certain target or value expressions may be null.
71 * If source is severely incorrect, the returned mapping is empty.
72 * @return a list of [target, value] pairs; either part of a pair may be null, but not both.
75 List<Pair<PyExpression, PyExpression>> getTargetsToValuesMapping();
78 PyExpression getLeftHandSideExpression();
80 boolean isAssignmentTo(@NotNull String name);