Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: editor/util/plugins/com.google.dart.java2dart/resources/ast_include.dart

Issue 29083004: Restore CompilationUnit.lineInfo in Java and Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /** 2 /**
3 * Instances of the class {@code NodeList} represent a list of AST nodes that ha ve a common parent. 3 * Instances of the class {@code NodeList} represent a list of AST nodes that ha ve a common parent.
4 */ 4 */
5 class NodeList<E extends ASTNode> extends Object with ListMixin<E> { 5 class NodeList<E extends ASTNode> extends Object with ListMixin<E> {
6 /** 6 /**
7 * Create an empty list with the given owner. This is a convenience method tha t allows the 7 * Create an empty list with the given owner. This is a convenience method tha t allows the
8 * compiler to determine the correct value of the type argument [E] without ne eding to 8 * compiler to determine the correct value of the type argument [E] without ne eding to
9 * explicitly specify it. 9 * explicitly specify it.
10 * 10 *
11 * @param owner the node that is the parent of each of the elements in the lis t 11 * @param owner the node that is the parent of each of the elements in the lis t
12 * @return the list that was created 12 * @return the list that was created
13 */ 13 */
14 static NodeList create(ASTNode owner) => new NodeList(owner); 14 static NodeList create(ASTNode owner) => new NodeList(owner);
15 15
16 /** 16 /**
17 * The node that is the parent of each of the elements in the list. 17 * The node that is the parent of each of the elements in the list.
18 */ 18 */
19 ASTNode owner; 19 ASTNode owner;
20 20
21 /** 21 /**
22 * The elements contained in the list. 22 * The elements contained in the list.
23 */ 23 */
24 List<ASTNode> _elements = ASTNode.EMPTY_ARRAY; 24 List<E> _elements = <E> [];
25 25
26 /** 26 /**
27 * Initialize a newly created list of nodes to be empty. 27 * Initialize a newly created list of nodes to be empty.
28 * 28 *
29 * @param owner the node that is the parent of each of the elements in the lis t 29 * @param owner the node that is the parent of each of the elements in the lis t
30 */ 30 */
31 NodeList(this.owner); 31 NodeList(this.owner);
32 32
33 /** 33 /**
34 * Use the given visitor to visit each of the nodes in this list. 34 * Use the given visitor to visit each of the nodes in this list.
35 * 35 *
36 * @param visitor the visitor to be used to visit the elements of this list 36 * @param visitor the visitor to be used to visit the elements of this list
37 */ 37 */
38 accept(ASTVisitor visitor) { 38 accept(ASTVisitor visitor) {
39 for (ASTNode element in _elements) { 39 for (E element in _elements) {
40 element.accept(visitor); 40 element.accept(visitor);
41 } 41 }
42 } 42 }
43 void add(E node) { 43 void add(E node) {
44 insert(length, node); 44 insert(length, node);
45 } 45 }
46 void insert(int index, E node) { 46 void insert(int index, E node) {
47 int length = _elements.length; 47 int length = _elements.length;
48 if (index < 0 || index > length) { 48 if (index < 0 || index > length) {
49 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); 49 throw new RangeError("Index: ${index}, Size: ${_elements.length}");
50 } 50 }
51 owner.becomeParentOf(node); 51 owner.becomeParentOf(node);
52 if (length == 0) { 52 if (length == 0) {
53 _elements = <ASTNode> [node]; 53 _elements = <E> [node];
54 } else { 54 } else {
55 List<ASTNode> newElements = new List<ASTNode>(length + 1); 55 List<E> newElements = new List<E>(length + 1);
56 JavaSystem.arraycopy(_elements, 0, newElements, 0, index); 56 JavaSystem.arraycopy(_elements, 0, newElements, 0, index);
57 newElements[index] = node; 57 newElements[index] = node;
58 JavaSystem.arraycopy(_elements, index, newElements, index + 1, length - in dex); 58 JavaSystem.arraycopy(_elements, index, newElements, index + 1, length - in dex);
59 _elements = newElements; 59 _elements = newElements;
60 } 60 }
61 } 61 }
62 bool addAll(Iterable<E> nodes) { 62 bool addAll(Iterable<E> nodes) {
63 if (nodes != null && !nodes.isEmpty) { 63 if (nodes != null && !nodes.isEmpty) {
64 int oldCount = _elements.length; 64 int oldCount = _elements.length;
65 int newCount = nodes.length; 65 int newCount = nodes.length;
66 List<ASTNode> newElements = new List<ASTNode>(oldCount + newCount); 66 List<E> newElements = new List<E>(oldCount + newCount);
67 JavaSystem.arraycopy(_elements, 0, newElements, 0, oldCount); 67 JavaSystem.arraycopy(_elements, 0, newElements, 0, oldCount);
68 int index = oldCount; 68 int index = oldCount;
69 for (E node in nodes) { 69 for (E node in nodes) {
70 owner.becomeParentOf(node); 70 owner.becomeParentOf(node);
71 newElements[index++] = node; 71 newElements[index++] = node;
72 } 72 }
73 _elements = newElements; 73 _elements = newElements;
74 return true; 74 return true;
75 } 75 }
76 return false; 76 return false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 E removeAt(int index) { 108 E removeAt(int index) {
109 if (index < 0 || index >= _elements.length) { 109 if (index < 0 || index >= _elements.length) {
110 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); 110 throw new RangeError("Index: ${index}, Size: ${_elements.length}");
111 } 111 }
112 E removedNode = _elements[index] as E; 112 E removedNode = _elements[index] as E;
113 int length = _elements.length; 113 int length = _elements.length;
114 if (length == 1) { 114 if (length == 1) {
115 _elements = ASTNode.EMPTY_ARRAY; 115 _elements = ASTNode.EMPTY_ARRAY;
116 return removedNode; 116 return removedNode;
117 } 117 }
118 List<ASTNode> newElements = new List<ASTNode>(length - 1); 118 List<E> newElements = new List<E>(length - 1);
119 JavaSystem.arraycopy(_elements, 0, newElements, 0, index); 119 JavaSystem.arraycopy(_elements, 0, newElements, 0, index);
120 JavaSystem.arraycopy(_elements, index + 1, newElements, index, length - inde x - 1); 120 JavaSystem.arraycopy(_elements, index + 1, newElements, index, length - inde x - 1);
121 _elements = newElements; 121 _elements = newElements;
122 return removedNode; 122 return removedNode;
123 } 123 }
124 void operator[]=(int index, E node) { 124 void operator[]=(int index, E node) {
125 if (index < 0 || index >= _elements.length) { 125 if (index < 0 || index >= _elements.length) {
126 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); 126 throw new RangeError("Index: ${index}, Size: ${_elements.length}");
127 } 127 }
128 _elements[index] as E; 128 _elements[index] as E;
129 owner.becomeParentOf(node); 129 owner.becomeParentOf(node);
130 _elements[index] = node; 130 _elements[index] = node;
131 } 131 }
132 int get length => _elements.length; 132 int get length => _elements.length;
133 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698