OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.dart.ast.ast; | 5 library analyzer.src.dart.ast.ast; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 7582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7593 | 7593 |
7594 /** | 7594 /** |
7595 * A list of AST nodes that have a common parent. | 7595 * A list of AST nodes that have a common parent. |
7596 */ | 7596 */ |
7597 class NodeListImpl<E extends AstNode> extends Object | 7597 class NodeListImpl<E extends AstNode> extends Object |
7598 with ListMixin<E> | 7598 with ListMixin<E> |
7599 implements NodeList<E> { | 7599 implements NodeList<E> { |
7600 /** | 7600 /** |
7601 * The node that is the parent of each of the elements in the list. | 7601 * The node that is the parent of each of the elements in the list. |
7602 */ | 7602 */ |
7603 @override | 7603 AstNodeImpl _owner; |
7604 AstNodeImpl owner; | |
7605 | 7604 |
7606 /** | 7605 /** |
7607 * The elements contained in the list. | 7606 * The elements contained in the list. |
7608 */ | 7607 */ |
7609 List<E> _elements = <E>[]; | 7608 List<E> _elements = <E>[]; |
7610 | 7609 |
7611 /** | 7610 /** |
7612 * Initialize a newly created list of nodes such that all of the nodes that | 7611 * Initialize a newly created list of nodes such that all of the nodes that |
7613 * are added to the list will have their parent set to the given [owner]. The | 7612 * are added to the list will have their parent set to the given [owner]. The |
7614 * list will initially be populated with the given [elements]. | 7613 * list will initially be populated with the given [elements]. |
7615 */ | 7614 */ |
7616 NodeListImpl(this.owner, [List<E> elements]) { | 7615 NodeListImpl(this._owner, [List<E> elements]) { |
7617 addAll(elements); | 7616 addAll(elements); |
7618 } | 7617 } |
7619 | 7618 |
7620 @override | 7619 @override |
7621 Token get beginToken { | 7620 Token get beginToken { |
7622 if (_elements.length == 0) { | 7621 if (_elements.length == 0) { |
7623 return null; | 7622 return null; |
7624 } | 7623 } |
7625 return _elements[0].beginToken; | 7624 return _elements[0].beginToken; |
7626 } | 7625 } |
7627 | 7626 |
7628 @override | 7627 @override |
7629 Token get endToken { | 7628 Token get endToken { |
7630 int length = _elements.length; | 7629 int length = _elements.length; |
7631 if (length == 0) { | 7630 if (length == 0) { |
7632 return null; | 7631 return null; |
7633 } | 7632 } |
7634 return _elements[length - 1].endToken; | 7633 return _elements[length - 1].endToken; |
7635 } | 7634 } |
7636 | 7635 |
7637 int get length => _elements.length; | 7636 int get length => _elements.length; |
7638 | 7637 |
7639 @deprecated // Never intended for public use. | 7638 @deprecated // Never intended for public use. |
7640 @override | 7639 @override |
7641 void set length(int newLength) { | 7640 void set length(int newLength) { |
7642 throw new UnsupportedError("Cannot resize NodeList."); | 7641 throw new UnsupportedError("Cannot resize NodeList."); |
7643 } | 7642 } |
7644 | 7643 |
| 7644 @override |
| 7645 AstNode get owner => _owner; |
| 7646 |
| 7647 @override |
| 7648 void set owner(AstNode value) { |
| 7649 _owner = value as AstNodeImpl; |
| 7650 } |
| 7651 |
7645 E operator [](int index) { | 7652 E operator [](int index) { |
7646 if (index < 0 || index >= _elements.length) { | 7653 if (index < 0 || index >= _elements.length) { |
7647 throw new RangeError("Index: $index, Size: ${_elements.length}"); | 7654 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
7648 } | 7655 } |
7649 return _elements[index]; | 7656 return _elements[index]; |
7650 } | 7657 } |
7651 | 7658 |
7652 void operator []=(int index, E node) { | 7659 void operator []=(int index, E node) { |
7653 if (index < 0 || index >= _elements.length) { | 7660 if (index < 0 || index >= _elements.length) { |
7654 throw new RangeError("Index: $index, Size: ${_elements.length}"); | 7661 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
7655 } | 7662 } |
7656 owner._becomeParentOf(node); | 7663 _owner._becomeParentOf(node); |
7657 _elements[index] = node; | 7664 _elements[index] = node; |
7658 } | 7665 } |
7659 | 7666 |
7660 @override | 7667 @override |
7661 accept(AstVisitor visitor) { | 7668 accept(AstVisitor visitor) { |
7662 int length = _elements.length; | 7669 int length = _elements.length; |
7663 for (var i = 0; i < length; i++) { | 7670 for (var i = 0; i < length; i++) { |
7664 _elements[i].accept(visitor); | 7671 _elements[i].accept(visitor); |
7665 } | 7672 } |
7666 } | 7673 } |
7667 | 7674 |
7668 @override | 7675 @override |
7669 void add(E node) { | 7676 void add(E node) { |
7670 insert(length, node); | 7677 insert(length, node); |
7671 } | 7678 } |
7672 | 7679 |
7673 @override | 7680 @override |
7674 bool addAll(Iterable<E> nodes) { | 7681 bool addAll(Iterable<E> nodes) { |
7675 if (nodes != null && !nodes.isEmpty) { | 7682 if (nodes != null && !nodes.isEmpty) { |
7676 _elements.addAll(nodes); | 7683 _elements.addAll(nodes); |
7677 for (E node in nodes) { | 7684 for (E node in nodes) { |
7678 owner._becomeParentOf(node); | 7685 _owner._becomeParentOf(node); |
7679 } | 7686 } |
7680 return true; | 7687 return true; |
7681 } | 7688 } |
7682 return false; | 7689 return false; |
7683 } | 7690 } |
7684 | 7691 |
7685 @override | 7692 @override |
7686 void clear() { | 7693 void clear() { |
7687 _elements = <E>[]; | 7694 _elements = <E>[]; |
7688 } | 7695 } |
7689 | 7696 |
7690 @override | 7697 @override |
7691 void insert(int index, E node) { | 7698 void insert(int index, E node) { |
7692 int length = _elements.length; | 7699 int length = _elements.length; |
7693 if (index < 0 || index > length) { | 7700 if (index < 0 || index > length) { |
7694 throw new RangeError("Index: $index, Size: ${_elements.length}"); | 7701 throw new RangeError("Index: $index, Size: ${_elements.length}"); |
7695 } | 7702 } |
7696 owner._becomeParentOf(node); | 7703 _owner._becomeParentOf(node); |
7697 if (length == 0) { | 7704 if (length == 0) { |
7698 _elements.add(node); | 7705 _elements.add(node); |
7699 } else { | 7706 } else { |
7700 _elements.insert(index, node); | 7707 _elements.insert(index, node); |
7701 } | 7708 } |
7702 } | 7709 } |
7703 | 7710 |
7704 @override | 7711 @override |
7705 E removeAt(int index) { | 7712 E removeAt(int index) { |
7706 if (index < 0 || index >= _elements.length) { | 7713 if (index < 0 || index >= _elements.length) { |
(...skipping 3288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10995 | 11002 |
10996 @override | 11003 @override |
10997 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 11004 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
10998 visitor.visitYieldStatement(this); | 11005 visitor.visitYieldStatement(this); |
10999 | 11006 |
11000 @override | 11007 @override |
11001 void visitChildren(AstVisitor visitor) { | 11008 void visitChildren(AstVisitor visitor) { |
11002 _expression?.accept(visitor); | 11009 _expression?.accept(visitor); |
11003 } | 11010 } |
11004 } | 11011 } |
OLD | NEW |