Skip to content

Commit

Permalink
Remove uses of retype (#95)
Browse files Browse the repository at this point in the history
* Remove uses of `retype`
  • Loading branch information
lrhn committed Jun 12, 2018
1 parent 0a34d50 commit 5c01f4e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/src/canonicalized_map.dart
Expand Up @@ -120,7 +120,8 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
void removeWhere(bool test(K key, V value)) =>
_base.removeWhere((_, pair) => test(pair.first, pair.last));

Map<K2, V2> retype<K2, V2>() => _base.retype<K2, V2>();
@deprecated
Map<K2, V2> retype<K2, V2>() => cast<K2, V2>();

V update(K key, V update(V value), {V ifAbsent()}) => _base
.update(_canonicalize(key), (pair) => new Pair(key, update(pair.last)),
Expand Down
1 change: 1 addition & 0 deletions lib/src/empty_unmodifiable_set.dart
Expand Up @@ -25,6 +25,7 @@ class EmptyUnmodifiableSet<E> extends IterableBase<E>
bool containsAll(Iterable<Object> other) => other.isEmpty;
Iterable<E> followedBy(Iterable<E> other) => new Set.from(other);
E lookup(Object element) => null;
@deprecated
EmptyUnmodifiableSet<T> retype<T>() => new EmptyUnmodifiableSet<T>();
E singleWhere(bool test(E element), {E orElse()}) => super.singleWhere(test);
Iterable<T> whereType<T>() => new EmptyUnmodifiableSet<T>();
Expand Down
11 changes: 3 additions & 8 deletions lib/src/queue_list.dart
Expand Up @@ -98,15 +98,10 @@ class QueueList<E> extends Object with ListMixin<E> implements Queue<E> {
}
}

QueueList<T> cast<T>() {
QueueList<Object> self = this;
if (self is QueueList<T>) {
return self;
}
return retype<T>();
}
QueueList<T> cast<T>() => QueueList._castFrom<E, T>(this);

QueueList<T> retype<T>() => QueueList._castFrom<E, T>(this);
@deprecated
QueueList<T> retype<T>() => cast<T>();

String toString() => IterableBase.iterableToFullString(this, "{", "}");

Expand Down
17 changes: 12 additions & 5 deletions lib/src/wrappers.dart
Expand Up @@ -61,7 +61,8 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {

E reduce(E combine(E value, E element)) => _base.reduce(combine);

Iterable<T> retype<T>() => _base.retype<T>();
@deprecated
Iterable<T> retype<T>() => cast<T>();

E get single => _base.single;

Expand Down Expand Up @@ -221,7 +222,8 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
_listBase.retainWhere(test);
}

List<T> retype<T>() => _listBase.retype<T>();
@deprecated
List<T> retype<T>() => cast<T>();

Iterable<E> get reversed => _listBase.reversed;

Expand Down Expand Up @@ -301,7 +303,8 @@ class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> {
_setBase.retainAll(elements);
}

Set<T> retype<T>() => _setBase.retype<T>();
@deprecated
Set<T> retype<T>() => cast<T>();

void retainWhere(bool test(E element)) {
_setBase.retainWhere(test);
Expand Down Expand Up @@ -368,7 +371,8 @@ class DelegatingQueue<E> extends DelegatingIterable<E> implements Queue<E> {
_baseQueue.retainWhere(test);
}

Queue<T> retype<T>() => _baseQueue.retype<T>();
@deprecated
Queue<T> retype<T>() => cast<T>();

E removeFirst() => _baseQueue.removeFirst();

Expand Down Expand Up @@ -446,7 +450,8 @@ class DelegatingMap<K, V> implements Map<K, V> {

void removeWhere(bool test(K key, V value)) => _base.removeWhere(test);

Map<K2, V2> retype<K2, V2>() => _base.retype<K2, V2>();
@deprecated
Map<K2, V2> retype<K2, V2>() => cast<K2, V2>();

Iterable<V> get values => _base.values;

Expand Down Expand Up @@ -518,6 +523,7 @@ class MapKeySet<E> extends _DelegatingIterableBase<E>
E lookup(Object element) =>
throw new UnsupportedError("MapKeySet doesn't support lookup().");

@deprecated
Set<T> retype<T>() => Set.castFrom<E, T>(this);

/// Returns a new set which contains all the elements of [this] and [other].
Expand Down Expand Up @@ -669,6 +675,7 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
void retainWhere(bool test(V element)) =>
removeWhere((element) => !test(element));

@deprecated
Set<T> retype<T>() => Set.castFrom<V, T>(this);

/// Returns a new set which contains all the elements of [this] and [other].
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
@@ -1,12 +1,12 @@
name: collection
version: 1.14.10-dev
version: 1.14.10
author: Dart Team <misc@dartlang.org>
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
Expand Down
4 changes: 2 additions & 2 deletions test/canonicalized_map_test.dart
Expand Up @@ -155,8 +155,8 @@ void main() {
expect(map, {"01": "value 01", "2": "value 2"});
});

test("retype returns a new map instance", () {
expect(map.retype<Pattern, Pattern>(), isNot(same(map)));
test("cast returns a new map instance", () {
expect(map.cast<Pattern, Pattern>(), isNot(same(map)));
});
});

Expand Down
9 changes: 2 additions & 7 deletions test/queue_list_test.dart
Expand Up @@ -253,11 +253,6 @@ void main() {
});
});

test("cast uses the same QueueList if possible", () {
var queue = new QueueList<String>();
expect(queue.cast<Pattern>(), 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<Pattern>()..addAll(['a', 'b']);
var stringQueue = patternQueue.cast<String>();
Expand Down Expand Up @@ -294,9 +289,9 @@ void main() {
);
});

test("retype returns a new QueueList", () {
test("cast returns a new QueueList", () {
var queue = new QueueList<String>();
expect(queue.retype<Pattern>(), isNot(same(queue)));
expect(queue.cast<Pattern>(), isNot(same(queue)));
});
}

Expand Down

0 comments on commit 5c01f4e

Please sign in to comment.