OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of protobuf; | 5 part of protobuf; |
6 | 6 |
7 class _ExtensionFieldSet { | 7 class _ExtensionFieldSet { |
8 final _FieldSet _parent; | 8 final _FieldSet _parent; |
9 final Map<int, Extension> _info = <int, Extension>{}; | 9 final Map<int, Extension> _info = <int, Extension>{}; |
10 final Map<int, dynamic> _values = <int, dynamic>{}; | 10 final Map<int, dynamic> _values = <int, dynamic>{}; |
(...skipping 20 matching lines...) Expand all Loading... | |
31 var value = _values[tagNumber]; | 31 var value = _values[tagNumber]; |
32 if (value == null) return false; | 32 if (value == null) return false; |
33 if (value is List) return value.isNotEmpty; | 33 if (value is List) return value.isNotEmpty; |
34 return true; | 34 return true; |
35 } | 35 } |
36 | 36 |
37 /// Ensures that the list exists and an extension is present. | 37 /// Ensures that the list exists and an extension is present. |
38 /// | 38 /// |
39 /// If it doesn't exist, creates the list and saves the extension. | 39 /// If it doesn't exist, creates the list and saves the extension. |
40 /// Suitable for public API and decoders. | 40 /// Suitable for public API and decoders. |
41 List _ensureRepeatedField(Extension fi) { | 41 List/*<T>*/ _ensureRepeatedField/*<T>*/(Extension/*<T>*/ fi) { |
42 assert(fi.isRepeated); | 42 assert(fi.isRepeated); |
43 assert(fi.extendee == _parent._messageName); | 43 assert(fi.extendee == _parent._messageName); |
44 | 44 |
45 var list = _values[fi.tagNumber]; | 45 var list = _values[fi.tagNumber]; |
46 if (list != null) return list; | 46 if (list != null) return list as List/*<T>*/; |
Leaf
2016/04/01 17:09:56
Is this going to have the right dynamic type (and
skybrian
2016/04/01 18:01:40
It's not statically checkable but the intent is th
skybrian
2016/04/01 18:04:35
On second thought, maybe this doesn't work? I'm re
Leaf
2016/04/01 18:15:59
If PbList<T> implements or extends List<T>, then y
| |
47 | 47 |
48 // Add info and create list. | 48 // Add info and create list. |
49 _validateInfo(fi); | 49 _validateInfo(fi); |
50 list = _parent._message.createRepeatedField(fi.tagNumber, fi); | 50 var newList = fi._createRepeatedField(_parent._message); |
51 _addInfoUnchecked(fi); | 51 _addInfoUnchecked(fi); |
52 _setFieldUnchecked(fi, list); | 52 _setFieldUnchecked(fi, newList); |
53 return list; | 53 return newList; |
54 } | 54 } |
55 | 55 |
56 _getFieldOrNull(Extension extension) => _values[extension.tagNumber]; | 56 _getFieldOrNull(Extension extension) => _values[extension.tagNumber]; |
57 | 57 |
58 void _clearFieldAndInfo(Extension fi) { | 58 void _clearFieldAndInfo(Extension fi) { |
59 _clearField(fi); | 59 _clearField(fi); |
60 _info.remove(fi.tagNumber); | 60 _info.remove(fi.tagNumber); |
61 } | 61 } |
62 | 62 |
63 void _clearField(Extension fi) { | 63 void _clearField(Extension fi) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 Iterable<int> get _tagNumbers => _values.keys; | 119 Iterable<int> get _tagNumbers => _values.keys; |
120 Iterable<Extension> get _infos => _info.values; | 120 Iterable<Extension> get _infos => _info.values; |
121 | 121 |
122 get _hasValues => _values.isNotEmpty; | 122 get _hasValues => _values.isNotEmpty; |
123 | 123 |
124 bool _equalValues(_ExtensionFieldSet other) => | 124 bool _equalValues(_ExtensionFieldSet other) => |
125 _areMapsEqual(_values, other._values); | 125 _areMapsEqual(_values, other._values); |
126 | 126 |
127 void _clearValues() => _values.clear(); | 127 void _clearValues() => _values.clear(); |
128 } | 128 } |
OLD | NEW |