Skip to content

Commit e6ed64c

Browse files
authored
Add methods where needed for Dart 2.0 core lib changes. (flutter#65)
Add methods where needed for Dart 2.0 core lib changes. Right now, all of the implementations throw (except in trivial cases, like the EmptyUnmodifiable* classes). They can be updated, typically to call `super` or reference a wrapped object, once the new methods have been released as part of a Dart 2.0 release, and this pubspec.yaml updates to guarantee that those implementations exist.
1 parent 99ceec8 commit e6ed64c

9 files changed

Lines changed: 360 additions & 4 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 1.14.4
2+
3+
* Add implementation stubs of upcoming Dart 2.0 core library methods, namely
4+
new methods for classes that implement Iterable, List, Map, Queue, and Set.
5+
6+
## 1.14.3
7+
8+
* Fix MapKeySet.lookup to be a valid override in strong mode.
9+
10+
## 1.14.2
11+
12+
* Add type arguments to SyntheticInvocation.
13+
114
## 1.14.1
215

316
* Make `Equality` implementations accept `null` as argument to `hash`.

lib/src/canonicalized_map.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
6969
other.forEach((key, value) => this[key] = value);
7070
}
7171

72+
// TODO: Dart 2.0 requires this method to be implemented.
73+
void addEntries(Iterable<Object> entries) {
74+
// Change Iterable<Object> to Iterable<MapEntry<K, V>> when
75+
// the MapEntry class has been added.
76+
throw new UnimplementedError('addEntries');
77+
}
78+
79+
// TODO: Dart 2.0 requires this method to be implemented.
80+
Map<K2, V2> cast<K2, V2>() {
81+
throw new UnimplementedError('cast');
82+
}
83+
7284
void clear() {
7385
_base.clear();
7486
}
@@ -81,6 +93,13 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
8193
bool containsValue(Object value) =>
8294
_base.values.any((pair) => pair.last == value);
8395

96+
// TODO: Dart 2.0 requires this method to be implemented.
97+
Iterable<Null> get entries {
98+
// Change Iterable<Null> to Iterable<MapEntry<K, V>> when
99+
// the MapEntry class has been added.
100+
throw new UnimplementedError('entries');
101+
}
102+
84103
void forEach(void f(K key, V value)) {
85104
_base.forEach((key, pair) => f(pair.first, pair.last));
86105
}
@@ -93,6 +112,13 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
93112

94113
int get length => _base.length;
95114

115+
// TODO: Dart 2.0 requires this method to be implemented.
116+
Map<K2, V2> map<K2, V2>(Object transform(K key, V value)) {
117+
// Change Object to MapEntry<K2, V2> when
118+
// the MapEntry class has been added.
119+
throw new UnimplementedError('map');
120+
}
121+
96122
V putIfAbsent(K key, V ifAbsent()) {
97123
return _base
98124
.putIfAbsent(_canonicalize(key), () => new Pair(key, ifAbsent()))
@@ -105,6 +131,26 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
105131
return pair == null ? null : pair.last;
106132
}
107133

134+
// TODO: Dart 2.0 requires this method to be implemented.
135+
void removeWhere(bool test(K key, V value)) {
136+
throw new UnimplementedError('removeWhere');
137+
}
138+
139+
// TODO: Dart 2.0 requires this method to be implemented.
140+
Map<K2, V2> retype<K2, V2>() {
141+
throw new UnimplementedError('retype');
142+
}
143+
144+
// TODO: Dart 2.0 requires this method to be implemented.
145+
V update(K key, V update(V value), {V ifAbsent()}) {
146+
throw new UnimplementedError('update');
147+
}
148+
149+
// TODO: Dart 2.0 requires this method to be implemented.
150+
void updateAll(V update(K key, V value)) {
151+
throw new UnimplementedError('updateAll');
152+
}
153+
108154
Iterable<V> get values => _base.values.map((pair) => pair.last);
109155

110156
String toString() => Maps.mapToString(this);

lib/src/empty_unmodifiable_set.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ class EmptyUnmodifiableSet<E> extends IterableBase<E>
2020

2121
const EmptyUnmodifiableSet();
2222

23+
EmptyUnmodifiableSet<T> cast<T>() => const EmptyUnmodifiableSet<T>();
2324
bool contains(Object element) => false;
2425
bool containsAll(Iterable<Object> other) => other.isEmpty;
26+
Iterable<E> followedBy(Iterable<E> other) => new Set.from(other);
2527
E lookup(Object element) => null;
28+
EmptyUnmodifiableSet<T> retype<T>() => const EmptyUnmodifiableSet<T>();
29+
E singleWhere(bool test(E element), {E orElse()}) => super.singleWhere(test);
30+
Iterable<T> whereType<T>() => const EmptyUnmodifiableSet<T>();
2631
Set<E> toSet() => new Set();
2732
Set<E> union(Set<E> other) => new Set.from(other);
2833
Set<E> intersection(Set<Object> other) => new Set();

lib/src/queue_list.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ class QueueList<E> extends Object with ListMixin<E> implements Queue<E> {
8080
}
8181
}
8282

83+
// TODO: Dart 2.0 requires this method to be implemented.
84+
QueueList<T> cast<T>() {
85+
throw new UnimplementedError('cast');
86+
}
87+
88+
// TODO: Dart 2.0 requires this method to be implemented.
89+
QueueList<T> retype<T>() {
90+
throw new UnimplementedError('retype');
91+
}
92+
8393
String toString() => IterableBase.iterableToFullString(this, "{", "}");
8494

8595
// Queue interface.

lib/src/typed_wrappers.dart

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
2121

2222
bool any(bool test(E element)) => _base.any(_validate(test));
2323

24+
// TODO: Dart 2.0 requires this method to be implemented.
25+
Iterable<T> cast<T>() {
26+
throw new UnimplementedError('cast');
27+
}
28+
2429
bool contains(Object element) => _base.contains(element);
2530

2631
E elementAt(int index) => _base.elementAt(index) as E;
@@ -38,6 +43,11 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
3843
_base.fold(initialValue,
3944
(previousValue, element) => combine(previousValue, element as E));
4045

46+
// TODO: Dart 2.0 requires this method to be implemented.
47+
Iterable<E> followedBy(Iterable<E> other) {
48+
throw new UnimplementedError('followedBy');
49+
}
50+
4151
void forEach(void f(E element)) => _base.forEach(_validate(f));
4252

4353
bool get isEmpty => _base.isEmpty;
@@ -60,10 +70,17 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
6070
E reduce(E combine(E value, E element)) =>
6171
_base.reduce((value, element) => combine(value as E, element as E)) as E;
6272

73+
// TODO: Dart 2.0 requires this method to be implemented.
74+
Iterable<T> retype<T>() {
75+
throw new UnimplementedError('retype');
76+
}
77+
6378
E get single => _base.single as E;
6479

65-
E singleWhere(bool test(E element)) =>
66-
_base.singleWhere(_validate(test)) as E;
80+
E singleWhere(bool test(E element), {E orElse()}) {
81+
if (orElse != null) throw new UnimplementedError('singleWhere:orElse');
82+
return _base.singleWhere(_validate(test)) as E;
83+
}
6784

6885
Iterable<E> skip(int n) => new TypeSafeIterable<E>(_base.skip(n));
6986

@@ -83,6 +100,11 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
83100
Iterable<E> where(bool test(E element)) =>
84101
new TypeSafeIterable<E>(_base.where(_validate(test)));
85102

103+
// TODO: Dart 2.0 requires this method to be implemented.
104+
Iterable<T> whereType<T>() {
105+
throw new UnimplementedError('whereType');
106+
}
107+
86108
String toString() => _base.toString();
87109

88110
/// Returns a version of [function] that asserts that its argument is an
@@ -116,6 +138,11 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
116138
_listBase[index] = value;
117139
}
118140

141+
// TODO: Dart 2.0 requires this method to be implemented.
142+
List<E> operator +(List<E> other) {
143+
throw new UnimplementedError('+');
144+
}
145+
119146
void add(E value) {
120147
_listBase.add(value);
121148
}
@@ -126,6 +153,11 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
126153

127154
Map<int, E> asMap() => new TypeSafeMap<int, E>(_listBase.asMap());
128155

156+
// TODO: Dart 2.0 requires this method to be implemented.
157+
List<T> cast<T>() {
158+
throw new UnimplementedError('cast');
159+
}
160+
129161
void clear() {
130162
_listBase.clear();
131163
}
@@ -134,11 +166,22 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
134166
_listBase.fillRange(start, end, fillValue);
135167
}
136168

169+
// TODO: Dart 2.0 requires this method to be implemented.
170+
set first(E value) {
171+
if (this.isEmpty) throw new RangeError.index(0, this);
172+
this[0] = value;
173+
}
174+
137175
Iterable<E> getRange(int start, int end) =>
138176
new TypeSafeIterable<E>(_listBase.getRange(start, end));
139177

140178
int indexOf(E element, [int start = 0]) => _listBase.indexOf(element, start);
141179

180+
// TODO: Dart 2.0 requires this method to be implemented.
181+
int indexWhere(bool test(E element), [int start = 0]) {
182+
throw new UnimplementedError('indexWhere');
183+
}
184+
142185
void insert(int index, E element) {
143186
_listBase.insert(index, element);
144187
}
@@ -147,9 +190,20 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
147190
_listBase.insertAll(index, iterable);
148191
}
149192

193+
// TODO: Dart 2.0 requires this method to be implemented.
194+
set last(E value) {
195+
if (this.isEmpty) throw new RangeError.index(0, this);
196+
this[this.length - 1] = value;
197+
}
198+
150199
int lastIndexOf(E element, [int start]) =>
151200
_listBase.lastIndexOf(element, start);
152201

202+
// TODO: Dart 2.0 requires this method to be implemented.
203+
int lastIndexWhere(bool test(E element), [int start]) {
204+
throw new UnimplementedError('lastIndexWhere');
205+
}
206+
153207
set length(int newLength) {
154208
_listBase.length = newLength;
155209
}
@@ -176,6 +230,11 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
176230
_listBase.retainWhere(_validate(test));
177231
}
178232

233+
// TODO: Dart 2.0 requires this method to be implemented.
234+
List<T> retype<T>() {
235+
throw new UnimplementedError('retype');
236+
}
237+
179238
Iterable<E> get reversed => new TypeSafeIterable<E>(_listBase.reversed);
180239

181240
void setAll(int index, Iterable<E> iterable) {
@@ -217,6 +276,11 @@ class TypeSafeSet<E> extends TypeSafeIterable<E> implements DelegatingSet<E> {
217276
_setBase.addAll(elements);
218277
}
219278

279+
// TODO: Dart 2.0 requires this method to be implemented.
280+
Set<T> cast<T>() {
281+
throw new UnimplementedError('cast');
282+
}
283+
220284
void clear() {
221285
_setBase.clear();
222286
}
@@ -249,6 +313,11 @@ class TypeSafeSet<E> extends TypeSafeIterable<E> implements DelegatingSet<E> {
249313
_setBase.retainWhere(_validate(test));
250314
}
251315

316+
// TODO: Dart 2.0 requires this method to be implemented.
317+
Set<T> retype<T>() {
318+
throw new UnimplementedError('retype');
319+
}
320+
252321
Set<E> union(Set<E> other) => new TypeSafeSet<E>(_setBase.union(other));
253322
}
254323

@@ -278,6 +347,11 @@ class TypeSafeQueue<E> extends TypeSafeIterable<E>
278347
_baseQueue.addLast(value);
279348
}
280349

350+
// TODO: Dart 2.0 requires this method to be implemented.
351+
Queue<T> cast<T>() {
352+
throw new UnimplementedError('cast');
353+
}
354+
281355
void clear() {
282356
_baseQueue.clear();
283357
}
@@ -292,6 +366,11 @@ class TypeSafeQueue<E> extends TypeSafeIterable<E>
292366
_baseQueue.retainWhere(_validate(test));
293367
}
294368

369+
// TODO: Dart 2.0 requires this method to be implemented.
370+
Queue<T> retype<T>() {
371+
throw new UnimplementedError('retype');
372+
}
373+
295374
E removeFirst() => _baseQueue.removeFirst() as E;
296375

297376
E removeLast() => _baseQueue.removeLast() as E;
@@ -316,6 +395,18 @@ class TypeSafeMap<K, V> implements DelegatingMap<K, V> {
316395
_base.addAll(other);
317396
}
318397

398+
// TODO: Dart 2.0 requires this method to be implemented.
399+
void addEntries(Iterable<Object> entries) {
400+
// Change Iterable<Object> to Iterable<MapEntry<K, V>> when
401+
// the MapEntry class has been added.
402+
throw new UnimplementedError('addEntries');
403+
}
404+
405+
// TODO: Dart 2.0 requires this method to be implemented.
406+
Map<K2, V2> cast<K2, V2>() {
407+
throw new UnimplementedError('cast');
408+
}
409+
319410
void clear() {
320411
_base.clear();
321412
}
@@ -324,6 +415,13 @@ class TypeSafeMap<K, V> implements DelegatingMap<K, V> {
324415

325416
bool containsValue(Object value) => _base.containsValue(value);
326417

418+
// TODO: Dart 2.0 requires this method to be implemented.
419+
Iterable<Null> get entries {
420+
// Change Iterable<Null> to Iterable<MapEntry<K, V>> when
421+
// the MapEntry class has been added.
422+
throw new UnimplementedError('entries');
423+
}
424+
327425
void forEach(void f(K key, V value)) {
328426
_base.forEach((key, value) => f(key as K, value as V));
329427
}
@@ -336,11 +434,38 @@ class TypeSafeMap<K, V> implements DelegatingMap<K, V> {
336434

337435
int get length => _base.length;
338436

437+
// TODO: Dart 2.0 requires this method to be implemented.
438+
Map<K2, V2> map<K2, V2>(Object transform(K key, V value)) {
439+
// Change Object to MapEntry<K2, V2> when
440+
// the MapEntry class has been added.
441+
throw new UnimplementedError('map');
442+
}
443+
339444
V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent) as V;
340445

341446
V remove(Object key) => _base.remove(key) as V;
342447

448+
// TODO: Dart 2.0 requires this method to be implemented.
449+
void removeWhere(bool test(K key, V value)) {
450+
throw new UnimplementedError('removeWhere');
451+
}
452+
453+
// TODO: Dart 2.0 requires this method to be implemented.
454+
Map<K2, V2> retype<K2, V2>() {
455+
throw new UnimplementedError('retype');
456+
}
457+
343458
Iterable<V> get values => new TypeSafeIterable<V>(_base.values);
344459

345460
String toString() => _base.toString();
461+
462+
// TODO: Dart 2.0 requires this method to be implemented.
463+
V update(K key, V update(V value), {V ifAbsent()}) {
464+
throw new UnimplementedError('update');
465+
}
466+
467+
// TODO: Dart 2.0 requires this method to be implemented.
468+
void updateAll(V update(K key, V value)) {
469+
throw new UnimplementedError('updateAll');
470+
}
346471
}

lib/src/unmodifiable_wrappers.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,12 @@ abstract class UnmodifiableMapMixin<K, V> implements Map<K, V> {
168168
/// Throws an [UnsupportedError];
169169
/// operations that change the map are disallowed.
170170
void clear() => _throw();
171+
172+
/// Throws an [UnsupportedError];
173+
/// operations that change the map are disallowed.
174+
set first(_) => _throw();
175+
176+
/// Throws an [UnsupportedError];
177+
/// operations that change the map are disallowed.
178+
set last(_) => _throw();
171179
}

0 commit comments

Comments
 (0)