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 yaml.yaml_node_wrapper; | 5 library yaml.yaml_node_wrapper; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:collection/collection.dart' as pkg_collection; | 9 import 'package:collection/collection.dart' as pkg_collection; |
10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
11 | 11 |
12 import 'null_span.dart'; | 12 import 'null_span.dart'; |
| 13 import 'style.dart'; |
13 import 'yaml_node.dart'; | 14 import 'yaml_node.dart'; |
14 | 15 |
15 /// A wrapper that makes a normal Dart map behave like a [YamlMap]. | 16 /// A wrapper that makes a normal Dart map behave like a [YamlMap]. |
16 class YamlMapWrapper extends MapBase | 17 class YamlMapWrapper extends MapBase |
17 with pkg_collection.UnmodifiableMapMixin | 18 with pkg_collection.UnmodifiableMapMixin |
18 implements YamlMap { | 19 implements YamlMap { |
| 20 final CollectionStyle style = CollectionStyle.ANY; |
| 21 |
19 final Map _dartMap; | 22 final Map _dartMap; |
20 | 23 |
21 final SourceSpan span; | 24 final SourceSpan span; |
22 | 25 |
23 final Map<dynamic, YamlNode> nodes; | 26 final Map<dynamic, YamlNode> nodes; |
24 | 27 |
25 Map get value => this; | 28 Map get value => this; |
26 | 29 |
27 Iterable get keys => _dartMap.keys; | 30 Iterable get keys => _dartMap.keys; |
28 | 31 |
(...skipping 19 matching lines...) Expand all Loading... |
48 } | 51 } |
49 | 52 |
50 /// The implementation of [YamlMapWrapper.nodes] as a wrapper around the Dart | 53 /// The implementation of [YamlMapWrapper.nodes] as a wrapper around the Dart |
51 /// map. | 54 /// map. |
52 class _YamlMapNodes extends MapBase<dynamic, YamlNode> | 55 class _YamlMapNodes extends MapBase<dynamic, YamlNode> |
53 with pkg_collection.UnmodifiableMapMixin<dynamic, YamlNode> { | 56 with pkg_collection.UnmodifiableMapMixin<dynamic, YamlNode> { |
54 final Map _dartMap; | 57 final Map _dartMap; |
55 | 58 |
56 final SourceSpan _span; | 59 final SourceSpan _span; |
57 | 60 |
58 Iterable get keys => | 61 Iterable get keys => _dartMap.keys.map((key) => |
59 _dartMap.keys.map((key) => new YamlScalar.internal(key, _span)); | 62 new YamlScalar.internal(key, _span, ScalarStyle.ANY)); |
60 | 63 |
61 _YamlMapNodes(this._dartMap, this._span); | 64 _YamlMapNodes(this._dartMap, this._span); |
62 | 65 |
63 YamlNode operator [](Object key) { | 66 YamlNode operator [](Object key) { |
64 // Use "as" here because key being assigned to invalidates type propagation. | 67 // Use "as" here because key being assigned to invalidates type propagation. |
65 if (key is YamlScalar) key = (key as YamlScalar).value; | 68 if (key is YamlScalar) key = (key as YamlScalar).value; |
66 if (!_dartMap.containsKey(key)) return null; | 69 if (!_dartMap.containsKey(key)) return null; |
67 return _nodeForValue(_dartMap[key], _span); | 70 return _nodeForValue(_dartMap[key], _span); |
68 } | 71 } |
69 | 72 |
70 int get hashCode => _dartMap.hashCode; | 73 int get hashCode => _dartMap.hashCode; |
71 | 74 |
72 operator ==(Object other) => | 75 operator ==(Object other) => |
73 other is _YamlMapNodes && other._dartMap == _dartMap; | 76 other is _YamlMapNodes && other._dartMap == _dartMap; |
74 } | 77 } |
75 | 78 |
76 // TODO(nweiz): Use UnmodifiableListMixin when issue 18970 is fixed. | 79 // TODO(nweiz): Use UnmodifiableListMixin when issue 18970 is fixed. |
77 /// A wrapper that makes a normal Dart list behave like a [YamlList]. | 80 /// A wrapper that makes a normal Dart list behave like a [YamlList]. |
78 class YamlListWrapper extends ListBase implements YamlList { | 81 class YamlListWrapper extends ListBase implements YamlList { |
| 82 final CollectionStyle style = CollectionStyle.ANY; |
| 83 |
79 final List _dartList; | 84 final List _dartList; |
80 | 85 |
81 final SourceSpan span; | 86 final SourceSpan span; |
82 | 87 |
83 final List<YamlNode> nodes; | 88 final List<YamlNode> nodes; |
84 | 89 |
85 List get value => this; | 90 List get value => this; |
86 | 91 |
87 int get length => _dartList.length; | 92 int get length => _dartList.length; |
88 | 93 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 144 |
140 int get hashCode => _dartList.hashCode; | 145 int get hashCode => _dartList.hashCode; |
141 | 146 |
142 operator ==(Object other) => | 147 operator ==(Object other) => |
143 other is _YamlListNodes && other._dartList == _dartList; | 148 other is _YamlListNodes && other._dartList == _dartList; |
144 } | 149 } |
145 | 150 |
146 YamlNode _nodeForValue(value, SourceSpan span) { | 151 YamlNode _nodeForValue(value, SourceSpan span) { |
147 if (value is Map) return new YamlMapWrapper._(value, span); | 152 if (value is Map) return new YamlMapWrapper._(value, span); |
148 if (value is List) return new YamlListWrapper._(value, span); | 153 if (value is List) return new YamlListWrapper._(value, span); |
149 return new YamlScalar.internal(value, span); | 154 return new YamlScalar.internal(value, span, ScalarStyle.ANY); |
150 } | 155 } |
OLD | NEW |