From 5c01f4e80c7eb531e4768de135e95e1dda92b398 Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Tue, 12 Jun 2018 15:38:49 +0200 Subject: [PATCH] Remove uses of `retype` (#95) * Remove uses of `retype` --- CHANGELOG.md | 1 + lib/src/canonicalized_map.dart | 3 ++- lib/src/empty_unmodifiable_set.dart | 1 + lib/src/queue_list.dart | 11 +++-------- lib/src/wrappers.dart | 17 ++++++++++++----- pubspec.yaml | 4 ++-- test/canonicalized_map_test.dart | 4 ++-- test/queue_list_test.dart | 9 ++------- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af6a93..3c9d4dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Fix the parameter names in overridden methods to match the source. * Make tests Dart 2 type-safe. +* Stop depending on SDK `retype` and deprecate methods. ## 1.14.9 diff --git a/lib/src/canonicalized_map.dart b/lib/src/canonicalized_map.dart index b28c6cc..9e1d5cf 100644 --- a/lib/src/canonicalized_map.dart +++ b/lib/src/canonicalized_map.dart @@ -120,7 +120,8 @@ class CanonicalizedMap implements Map { void removeWhere(bool test(K key, V value)) => _base.removeWhere((_, pair) => test(pair.first, pair.last)); - Map retype() => _base.retype(); + @deprecated + Map retype() => cast(); V update(K key, V update(V value), {V ifAbsent()}) => _base .update(_canonicalize(key), (pair) => new Pair(key, update(pair.last)), diff --git a/lib/src/empty_unmodifiable_set.dart b/lib/src/empty_unmodifiable_set.dart index 436e88d..997619d 100644 --- a/lib/src/empty_unmodifiable_set.dart +++ b/lib/src/empty_unmodifiable_set.dart @@ -25,6 +25,7 @@ class EmptyUnmodifiableSet extends IterableBase bool containsAll(Iterable other) => other.isEmpty; Iterable followedBy(Iterable other) => new Set.from(other); E lookup(Object element) => null; + @deprecated EmptyUnmodifiableSet retype() => new EmptyUnmodifiableSet(); E singleWhere(bool test(E element), {E orElse()}) => super.singleWhere(test); Iterable whereType() => new EmptyUnmodifiableSet(); diff --git a/lib/src/queue_list.dart b/lib/src/queue_list.dart index 8b68cc8..8b706bf 100644 --- a/lib/src/queue_list.dart +++ b/lib/src/queue_list.dart @@ -98,15 +98,10 @@ class QueueList extends Object with ListMixin implements Queue { } } - QueueList cast() { - QueueList self = this; - if (self is QueueList) { - return self; - } - return retype(); - } + QueueList cast() => QueueList._castFrom(this); - QueueList retype() => QueueList._castFrom(this); + @deprecated + QueueList retype() => cast(); String toString() => IterableBase.iterableToFullString(this, "{", "}"); diff --git a/lib/src/wrappers.dart b/lib/src/wrappers.dart index cead501..f7fe578 100644 --- a/lib/src/wrappers.dart +++ b/lib/src/wrappers.dart @@ -61,7 +61,8 @@ abstract class _DelegatingIterableBase implements Iterable { E reduce(E combine(E value, E element)) => _base.reduce(combine); - Iterable retype() => _base.retype(); + @deprecated + Iterable retype() => cast(); E get single => _base.single; @@ -221,7 +222,8 @@ class DelegatingList extends DelegatingIterable implements List { _listBase.retainWhere(test); } - List retype() => _listBase.retype(); + @deprecated + List retype() => cast(); Iterable get reversed => _listBase.reversed; @@ -301,7 +303,8 @@ class DelegatingSet extends DelegatingIterable implements Set { _setBase.retainAll(elements); } - Set retype() => _setBase.retype(); + @deprecated + Set retype() => cast(); void retainWhere(bool test(E element)) { _setBase.retainWhere(test); @@ -368,7 +371,8 @@ class DelegatingQueue extends DelegatingIterable implements Queue { _baseQueue.retainWhere(test); } - Queue retype() => _baseQueue.retype(); + @deprecated + Queue retype() => cast(); E removeFirst() => _baseQueue.removeFirst(); @@ -446,7 +450,8 @@ class DelegatingMap implements Map { void removeWhere(bool test(K key, V value)) => _base.removeWhere(test); - Map retype() => _base.retype(); + @deprecated + Map retype() => cast(); Iterable get values => _base.values; @@ -518,6 +523,7 @@ class MapKeySet extends _DelegatingIterableBase E lookup(Object element) => throw new UnsupportedError("MapKeySet doesn't support lookup()."); + @deprecated Set retype() => Set.castFrom(this); /// Returns a new set which contains all the elements of [this] and [other]. @@ -669,6 +675,7 @@ class MapValueSet extends _DelegatingIterableBase implements Set { void retainWhere(bool test(V element)) => removeWhere((element) => !test(element)); + @deprecated Set retype() => Set.castFrom(this); /// Returns a new set which contains all the elements of [this] and [other]. diff --git a/pubspec.yaml b/pubspec.yaml index 06f183e..323f039 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ name: collection -version: 1.14.10-dev +version: 1.14.10 author: Dart Team description: Collections and utilities functions and classes related to collections. homepage: https://www.github.com/dart-lang/collection environment: # Required for Dart 2.0 collection changes. - sdk: '>=2.0.0-dev.49.0 <2.0.0' + sdk: '>=2.0.0-dev.55.0 <2.0.0' dev_dependencies: build_runner: ^0.8.0 diff --git a/test/canonicalized_map_test.dart b/test/canonicalized_map_test.dart index 4049d85..078e57c 100644 --- a/test/canonicalized_map_test.dart +++ b/test/canonicalized_map_test.dart @@ -155,8 +155,8 @@ void main() { expect(map, {"01": "value 01", "2": "value 2"}); }); - test("retype returns a new map instance", () { - expect(map.retype(), isNot(same(map))); + test("cast returns a new map instance", () { + expect(map.cast(), isNot(same(map))); }); }); diff --git a/test/queue_list_test.dart b/test/queue_list_test.dart index ed26a65..639eb68 100644 --- a/test/queue_list_test.dart +++ b/test/queue_list_test.dart @@ -253,11 +253,6 @@ void main() { }); }); - test("cast uses the same QueueList if possible", () { - var queue = new QueueList(); - expect(queue.cast(), same(queue)); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); - test("cast does not throw on mutation when the type is valid", () { var patternQueue = new QueueList()..addAll(['a', 'b']); var stringQueue = patternQueue.cast(); @@ -294,9 +289,9 @@ void main() { ); }); - test("retype returns a new QueueList", () { + test("cast returns a new QueueList", () { var queue = new QueueList(); - expect(queue.retype(), isNot(same(queue))); + expect(queue.cast(), isNot(same(queue))); }); }