MCPcopy Create free account
hub / github.com/mozilla/rhino / ArrayLiteral

Class ArrayLiteral

rhino/src/main/java/org/mozilla/javascript/ast/ArrayLiteral.java:31–185  ·  view source on GitHub ↗

AST node for an Array literal. The elements list will always be non-null, although the list will have no elements if the Array literal is empty. Node type is Token#ARRAYLIT. ArrayLiteral : [ Elisionopt ] [ ElementList ]

Source from the content-addressed store, hash-verified

29 * Elision <b>,</b></pre>
30 */
31public class ArrayLiteral extends AstNode implements DestructuringForm {
32
33 private static final List<AstNode> NO_ELEMS = Collections.unmodifiableList(new ArrayList<>());
34
35 private List<AstNode> elements;
36 private int destructuringLength;
37 private int skipCount;
38 private boolean isDestructuring;
39
40 {
41 type = Token.ARRAYLIT;
42 }
43
44 public ArrayLiteral() {}
45
46 public ArrayLiteral(int pos) {
47 super(pos);
48 }
49
50 public ArrayLiteral(int pos, int len) {
51 super(pos, len);
52 }
53
54 /**
55 * Returns the element list
56 *
57 * @return the element list. If there are no elements, returns an immutable empty list. Elisions
58 * are represented as {@link EmptyExpression} nodes.
59 */
60 public List<AstNode> getElements() {
61 return elements != null ? elements : NO_ELEMS;
62 }
63
64 /**
65 * Sets the element list, and sets each element's parent to this node.
66 *
67 * @param elements the element list. Can be {@code null}.
68 */
69 public void setElements(List<AstNode> elements) {
70 if (elements == null) {
71 this.elements = null;
72 } else {
73 if (this.elements != null) this.elements.clear();
74 for (AstNode e : elements) addElement(e);
75 }
76 }
77
78 /**
79 * Adds an element to the list, and sets its parent to this node.
80 *
81 * @param element the element to add
82 * @throws IllegalArgumentException if element is {@code null}. To indicate an empty element,
83 * use an {@link EmptyExpression} node.
84 */
85 public void addElement(AstNode element) {
86 assertNotNull(element);
87 if (elements == null) elements = new ArrayList<>();
88 elements.add(element);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected