8015955: ObjectNode.elements should be stronger typed

Wed, 05 Jun 2013 10:44:32 +0200

author
attila
date
Wed, 05 Jun 2013 10:44:32 +0200
changeset 324
0feca8a93cb3
parent 322
62b096f7bac3
child 325
9374c04f38fe

8015955: ObjectNode.elements should be stronger typed
Reviewed-by: lagergren, sundar

src/jdk/nashorn/internal/codegen/CodeGenerator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/BlockLexicalContext.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/ObjectNode.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/JSONParser.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/Parser.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/JSONFunctions.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Wed Jun 05 12:08:49 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Wed Jun 05 10:44:32 2013 +0200
     1.3 @@ -1326,8 +1326,7 @@
     1.4  
     1.5      @Override
     1.6      public boolean enterObjectNode(final ObjectNode objectNode) {
     1.7 -        final List<Node> elements = objectNode.getElements();
     1.8 -        final int        size     = elements.size();
     1.9 +        final List<PropertyNode> elements = objectNode.getElements();
    1.10  
    1.11          final List<String> keys    = new ArrayList<>();
    1.12          final List<Symbol> symbols = new ArrayList<>();
    1.13 @@ -1335,8 +1334,7 @@
    1.14  
    1.15          boolean hasGettersSetters = false;
    1.16  
    1.17 -        for (int i = 0; i < size; i++) {
    1.18 -            final PropertyNode propertyNode = (PropertyNode)elements.get(i);
    1.19 +        for (PropertyNode propertyNode: elements) {
    1.20              final Node         value        = propertyNode.getValue();
    1.21              final String       key          = propertyNode.getKeyName();
    1.22              final Symbol       symbol       = value == null ? null : propertyNode.getSymbol();
     2.1 --- a/src/jdk/nashorn/internal/ir/BlockLexicalContext.java	Wed Jun 05 12:08:49 2013 +0530
     2.2 +++ b/src/jdk/nashorn/internal/ir/BlockLexicalContext.java	Wed Jun 05 10:44:32 2013 +0200
     2.3 @@ -63,7 +63,6 @@
     2.4          return sstack.pop();
     2.5      }
     2.6  
     2.7 -    @SuppressWarnings("unchecked")
     2.8      @Override
     2.9      public <T extends LexicalContextNode> T pop(final T node) {
    2.10          T expected = node;
     3.1 --- a/src/jdk/nashorn/internal/ir/ObjectNode.java	Wed Jun 05 12:08:49 2013 +0530
     3.2 +++ b/src/jdk/nashorn/internal/ir/ObjectNode.java	Wed Jun 05 10:44:32 2013 +0200
     3.3 @@ -27,7 +27,6 @@
     3.4  
     3.5  import java.util.Collections;
     3.6  import java.util.List;
     3.7 -
     3.8  import jdk.nashorn.internal.ir.annotations.Immutable;
     3.9  import jdk.nashorn.internal.ir.visitor.NodeVisitor;
    3.10  
    3.11 @@ -38,7 +37,7 @@
    3.12  public final class ObjectNode extends Node {
    3.13  
    3.14      /** Literal elements. */
    3.15 -    private final List<Node> elements;
    3.16 +    private final List<PropertyNode> elements;
    3.17  
    3.18      /**
    3.19       * Constructor
    3.20 @@ -47,12 +46,12 @@
    3.21       * @param finish   finish
    3.22       * @param elements the elements used to initialize this ObjectNode
    3.23       */
    3.24 -    public ObjectNode(final long token, final int finish, final List<Node> elements) {
    3.25 +    public ObjectNode(final long token, final int finish, final List<PropertyNode> elements) {
    3.26          super(token, finish);
    3.27          this.elements = elements;
    3.28      }
    3.29  
    3.30 -    private ObjectNode(final ObjectNode objectNode, final List<Node> elements) {
    3.31 +    private ObjectNode(final ObjectNode objectNode, final List<PropertyNode> elements) {
    3.32          super(objectNode);
    3.33          this.elements = elements;
    3.34      }
    3.35 @@ -60,7 +59,7 @@
    3.36      @Override
    3.37      public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
    3.38          if (visitor.enterObjectNode(this)) {
    3.39 -            return visitor.leaveObjectNode(setElements(Node.accept(visitor, Node.class, elements)));
    3.40 +            return visitor.leaveObjectNode(setElements(Node.accept(visitor, PropertyNode.class, elements)));
    3.41          }
    3.42  
    3.43          return this;
    3.44 @@ -92,11 +91,11 @@
    3.45       * Get the elements of this literal node
    3.46       * @return a list of elements
    3.47       */
    3.48 -    public List<Node> getElements() {
    3.49 +    public List<PropertyNode> getElements() {
    3.50          return Collections.unmodifiableList(elements);
    3.51      }
    3.52  
    3.53 -    private ObjectNode setElements(final List<Node> elements) {
    3.54 +    private ObjectNode setElements(final List<PropertyNode> elements) {
    3.55          if (this.elements == elements) {
    3.56              return this;
    3.57          }
     4.1 --- a/src/jdk/nashorn/internal/parser/JSONParser.java	Wed Jun 05 12:08:49 2013 +0530
     4.2 +++ b/src/jdk/nashorn/internal/parser/JSONParser.java	Wed Jun 05 10:44:32 2013 +0200
     4.3 @@ -282,7 +282,7 @@
     4.4          next();
     4.5  
     4.6          // Prepare to accumulate elements.
     4.7 -        final List<Node> elements = new ArrayList<>();
     4.8 +        final List<PropertyNode> elements = new ArrayList<>();
     4.9  
    4.10          // Create a block for the object literal.
    4.11  loop:
    4.12 @@ -298,7 +298,7 @@
    4.13  
    4.14              default:
    4.15                  // Get and add the next property.
    4.16 -                final Node property = propertyAssignment();
    4.17 +                final PropertyNode property = propertyAssignment();
    4.18                  elements.add(property);
    4.19  
    4.20                  // Comma between property assigments is mandatory in JSON.
    4.21 @@ -317,7 +317,7 @@
    4.22       * Parse a property assignment from the token stream
    4.23       * @return the property assignment as a Node
    4.24       */
    4.25 -    private Node propertyAssignment() {
    4.26 +    private PropertyNode propertyAssignment() {
    4.27          // Capture firstToken.
    4.28          final long propertyToken = token;
    4.29          LiteralNode<?> name = null;
     5.1 --- a/src/jdk/nashorn/internal/parser/Parser.java	Wed Jun 05 12:08:49 2013 +0530
     5.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java	Wed Jun 05 10:44:32 2013 +0200
     5.3 @@ -59,7 +59,6 @@
     5.4  import java.util.LinkedHashMap;
     5.5  import java.util.List;
     5.6  import java.util.Map;
     5.7 -
     5.8  import jdk.nashorn.internal.codegen.CompilerConstants;
     5.9  import jdk.nashorn.internal.codegen.Namespace;
    5.10  import jdk.nashorn.internal.ir.AccessNode;
    5.11 @@ -2028,7 +2027,7 @@
    5.12              }
    5.13          }
    5.14  
    5.15 -        return new ObjectNode(objectToken, finish, new ArrayList<Node>(map.values()));
    5.16 +        return new ObjectNode(objectToken, finish, new ArrayList<>(map.values()));
    5.17      }
    5.18  
    5.19      /**
     6.1 --- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Wed Jun 05 12:08:49 2013 +0530
     6.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Wed Jun 05 10:44:32 2013 +0200
     6.3 @@ -25,9 +25,11 @@
     6.4  
     6.5  package jdk.nashorn.internal.runtime;
     6.6  
     6.7 +import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow;
     6.8 +import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
     6.9 +
    6.10  import java.lang.invoke.MethodHandle;
    6.11  import java.util.Iterator;
    6.12 -import java.util.List;
    6.13  import jdk.nashorn.internal.ir.LiteralNode;
    6.14  import jdk.nashorn.internal.ir.Node;
    6.15  import jdk.nashorn.internal.ir.ObjectNode;
    6.16 @@ -36,8 +38,6 @@
    6.17  import jdk.nashorn.internal.parser.JSONParser;
    6.18  import jdk.nashorn.internal.parser.TokenType;
    6.19  import jdk.nashorn.internal.runtime.linker.Bootstrap;
    6.20 -import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow;
    6.21 -import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
    6.22  
    6.23  /**
    6.24   * Utilities used by "JSON" object implementation.
    6.25 @@ -171,10 +171,8 @@
    6.26              final ObjectNode   objNode  = (ObjectNode) node;
    6.27              final ScriptObject object   = ((GlobalObject)global).newObject();
    6.28              final boolean      strict   = global.isStrictContext();
    6.29 -            final List<Node>   elements = objNode.getElements();
    6.30  
    6.31 -            for (final Node elem : elements) {
    6.32 -                final PropertyNode pNode     = (PropertyNode) elem;
    6.33 +            for (final PropertyNode pNode: objNode.getElements()) {
    6.34                  final Node         valueNode = pNode.getValue();
    6.35  
    6.36                  final String name = pNode.getKeyName();

mercurial