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

Side by Side Diff: utils/pub/yaml/model.dart

Issue 11191078: Make hashCode a getter and not a method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status file with co19 issue number. Created 8 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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // This file contains the node classes for the internal representations of YAML 5 // This file contains the node classes for the internal representations of YAML
6 // documents. These nodes are used for both the serialization tree and the 6 // documents. These nodes are used for both the serialization tree and the
7 // representation graph. 7 // representation graph.
8 8
9 /** A tag that indicates the type of a YAML node. */ 9 /** A tag that indicates the type of a YAML node. */
10 class _Tag { 10 class _Tag {
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 String toString() { 41 String toString() {
42 if (name.startsWith(YAML_URI_PREFIX)) { 42 if (name.startsWith(YAML_URI_PREFIX)) {
43 return '!!${name.substring(YAML_URI_PREFIX.length)}'; 43 return '!!${name.substring(YAML_URI_PREFIX.length)}';
44 } else { 44 } else {
45 return '!<$name>'; 45 return '!<$name>';
46 } 46 }
47 } 47 }
48 48
49 int hashCode() => name.hashCode(); 49 int get hashCode => name.hashCode;
50 } 50 }
51 51
52 /** The abstract class for YAML nodes. */ 52 /** The abstract class for YAML nodes. */
53 class _Node { 53 class _Node {
54 /** Every YAML node has a tag that describes its type. */ 54 /** Every YAML node has a tag that describes its type. */
55 _Tag tag; 55 _Tag tag;
56 56
57 /** Any YAML node can have an anchor associated with it. */ 57 /** Any YAML node can have an anchor associated with it. */
58 String anchor; 58 String anchor;
59 59
60 _Node(this.tag, [this.anchor]); 60 _Node(this.tag, [this.anchor]);
61 61
62 bool operator ==(other) { 62 bool operator ==(other) {
63 if (other is! _Node) return false; 63 if (other is! _Node) return false;
64 return tag == other.tag; 64 return tag == other.tag;
65 } 65 }
66 66
67 int hashCode() => _hashCode([tag, anchor]); 67 int get hashCode => _hashCode([tag, anchor]);
68 68
69 abstract visit(_Visitor v); 69 abstract visit(_Visitor v);
70 } 70 }
71 71
72 /** A sequence node represents an ordered list of nodes. */ 72 /** A sequence node represents an ordered list of nodes. */
73 class _SequenceNode extends _Node { 73 class _SequenceNode extends _Node {
74 /** The nodes in the sequence. */ 74 /** The nodes in the sequence. */
75 List<_Node> content; 75 List<_Node> content;
76 76
77 _SequenceNode(String tagName, this.content) 77 _SequenceNode(String tagName, this.content)
78 : super(new _Tag.sequence(tagName)); 78 : super(new _Tag.sequence(tagName));
79 79
80 /** Two sequences are equal if their tags and contents are equal. */ 80 /** Two sequences are equal if their tags and contents are equal. */
81 bool operator ==(other) { 81 bool operator ==(other) {
82 // Should be super != other; bug 2554 82 // Should be super != other; bug 2554
83 if (!(super == other) || other is! _SequenceNode) return false; 83 if (!(super == other) || other is! _SequenceNode) return false;
84 if (content.length != other.content.length) return false; 84 if (content.length != other.content.length) return false;
85 for (var i = 0; i < content.length; i++) { 85 for (var i = 0; i < content.length; i++) {
86 if (content[i] != other.content[i]) return false; 86 if (content[i] != other.content[i]) return false;
87 } 87 }
88 return true; 88 return true;
89 } 89 }
90 90
91 String toString() => '$tag [${Strings.join(content.map((e) => '$e'), ', ')}]'; 91 String toString() => '$tag [${Strings.join(content.map((e) => '$e'), ', ')}]';
92 92
93 int hashCode() => super.hashCode() ^ _hashCode(content); 93 int get hashCode => super.hashCode ^ _hashCode(content);
94 94
95 visit(_Visitor v) => v.visitSequence(this); 95 visit(_Visitor v) => v.visitSequence(this);
96 } 96 }
97 97
98 /** An alias node is a reference to an anchor. */ 98 /** An alias node is a reference to an anchor. */
99 class _AliasNode extends _Node { 99 class _AliasNode extends _Node {
100 _AliasNode(String anchor) : super(new _Tag.scalar(_Tag.yaml("str")), anchor); 100 _AliasNode(String anchor) : super(new _Tag.scalar(_Tag.yaml("str")), anchor);
101 101
102 visit(_Visitor v) => v.visitAlias(this); 102 visit(_Visitor v) => v.visitAlias(this);
103 } 103 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 * Left-pads [str] with zeros so that it's at least [length] characters 194 * Left-pads [str] with zeros so that it's at least [length] characters
195 * long. 195 * long.
196 */ 196 */
197 String zeroPad(String str, int length) { 197 String zeroPad(String str, int length) {
198 assert(length >= str.length); 198 assert(length >= str.length);
199 var prefix = []; 199 var prefix = [];
200 prefix.insertRange(0, length - str.length, '0'); 200 prefix.insertRange(0, length - str.length, '0');
201 return '${Strings.join(prefix, '')}$str'; 201 return '${Strings.join(prefix, '')}$str';
202 } 202 }
203 203
204 int hashCode() => super.hashCode() ^ content.hashCode(); 204 int get hashCode => super.hashCode ^ content.hashCode;
205 205
206 visit(_Visitor v) => v.visitScalar(this); 206 visit(_Visitor v) => v.visitScalar(this);
207 } 207 }
208 208
209 /** A mapping node represents an unordered map of nodes to nodes. */ 209 /** A mapping node represents an unordered map of nodes to nodes. */
210 class _MappingNode extends _Node { 210 class _MappingNode extends _Node {
211 /** The node map. */ 211 /** The node map. */
212 Map<_Node, _Node> content; 212 Map<_Node, _Node> content;
213 213
214 _MappingNode(String tagName, this.content) 214 _MappingNode(String tagName, this.content)
(...skipping 10 matching lines...) Expand all
225 } 225 }
226 return true; 226 return true;
227 } 227 }
228 228
229 String toString() { 229 String toString() {
230 var strContent = Strings.join(content.getKeys(). 230 var strContent = Strings.join(content.getKeys().
231 map((k) => '${k}: ${content[k]}'), ', '); 231 map((k) => '${k}: ${content[k]}'), ', ');
232 return '$tag {$strContent}'; 232 return '$tag {$strContent}';
233 } 233 }
234 234
235 int hashCode() => super.hashCode() ^ _hashCode(content); 235 int get hashCode => super.hashCode ^ _hashCode(content);
236 236
237 visit(_Visitor v) => v.visitMapping(this); 237 visit(_Visitor v) => v.visitMapping(this);
238 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698