nashorn/src/jdk/nashorn/internal/ir/ObjectNode.java
changeset 17981 9b8e085aa1fe
parent 17769 14ea7feaf658
child 18867 bc91e3fcc5ba
equal deleted inserted replaced
17979:adae4d39ee07 17981:9b8e085aa1fe
    25 
    25 
    26 package jdk.nashorn.internal.ir;
    26 package jdk.nashorn.internal.ir;
    27 
    27 
    28 import java.util.Collections;
    28 import java.util.Collections;
    29 import java.util.List;
    29 import java.util.List;
    30 
       
    31 import jdk.nashorn.internal.ir.annotations.Immutable;
    30 import jdk.nashorn.internal.ir.annotations.Immutable;
    32 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
    31 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
    33 
    32 
    34 /**
    33 /**
    35  * IR representation of an object literal.
    34  * IR representation of an object literal.
    36  */
    35  */
    37 @Immutable
    36 @Immutable
    38 public final class ObjectNode extends Node {
    37 public final class ObjectNode extends Node {
    39 
    38 
    40     /** Literal elements. */
    39     /** Literal elements. */
    41     private final List<Node> elements;
    40     private final List<PropertyNode> elements;
    42 
    41 
    43     /**
    42     /**
    44      * Constructor
    43      * Constructor
    45      *
    44      *
    46      * @param token    token
    45      * @param token    token
    47      * @param finish   finish
    46      * @param finish   finish
    48      * @param elements the elements used to initialize this ObjectNode
    47      * @param elements the elements used to initialize this ObjectNode
    49      */
    48      */
    50     public ObjectNode(final long token, final int finish, final List<Node> elements) {
    49     public ObjectNode(final long token, final int finish, final List<PropertyNode> elements) {
    51         super(token, finish);
    50         super(token, finish);
    52         this.elements = elements;
    51         this.elements = elements;
    53     }
    52     }
    54 
    53 
    55     private ObjectNode(final ObjectNode objectNode, final List<Node> elements) {
    54     private ObjectNode(final ObjectNode objectNode, final List<PropertyNode> elements) {
    56         super(objectNode);
    55         super(objectNode);
    57         this.elements = elements;
    56         this.elements = elements;
    58     }
    57     }
    59 
    58 
    60     @Override
    59     @Override
    61     public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
    60     public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
    62         if (visitor.enterObjectNode(this)) {
    61         if (visitor.enterObjectNode(this)) {
    63             return visitor.leaveObjectNode(setElements(Node.accept(visitor, Node.class, elements)));
    62             return visitor.leaveObjectNode(setElements(Node.accept(visitor, PropertyNode.class, elements)));
    64         }
    63         }
    65 
    64 
    66         return this;
    65         return this;
    67     }
    66     }
    68 
    67 
    90 
    89 
    91     /**
    90     /**
    92      * Get the elements of this literal node
    91      * Get the elements of this literal node
    93      * @return a list of elements
    92      * @return a list of elements
    94      */
    93      */
    95     public List<Node> getElements() {
    94     public List<PropertyNode> getElements() {
    96         return Collections.unmodifiableList(elements);
    95         return Collections.unmodifiableList(elements);
    97     }
    96     }
    98 
    97 
    99     private ObjectNode setElements(final List<Node> elements) {
    98     private ObjectNode setElements(final List<PropertyNode> elements) {
   100         if (this.elements == elements) {
    99         if (this.elements == elements) {
   101             return this;
   100             return this;
   102         }
   101         }
   103         return new ObjectNode(this, elements);
   102         return new ObjectNode(this, elements);
   104     }
   103     }