diff --git a/pkg/compiler/lib/src/helpers/debug_collection.dart b/pkg/compiler/lib/src/helpers/debug_collection.dart index 2ec5eb9d624..03ac0e9edc2 100644 --- a/pkg/compiler/lib/src/helpers/debug_collection.dart +++ b/pkg/compiler/lib/src/helpers/debug_collection.dart @@ -21,12 +21,10 @@ class DebugMap implements Map { putIfAbsentCallback = value; } - Map cast() { - Map self = this; - return self is Map ? self : this.retype(); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); bool containsValue(Object value) { return sourceMap.containsValue(value); @@ -109,12 +107,10 @@ class DebugIterable implements Iterable { Iterator get iterator => iterable.iterator; - Iterable cast() { - Iterable self = this; - return self is Iterable ? self : this.retype(); - } + Iterable cast() => Iterable.castFrom(this); - Iterable retype() => Iterable.castFrom(this); + @Deprecated("Use cast instead.") + Iterable retype() => cast(); Iterable map(T f(E element)) => iterable.map(f); @@ -193,12 +189,10 @@ class DebugList extends DebugIterable implements List { List get list => iterable; - List cast() { - List self = this; - return self is List ? self : this.retype(); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); List operator +(List other) => list + other; @@ -302,12 +296,10 @@ class DebugSet extends DebugIterable implements Set { Set get set => iterable; - Set cast() { - Set self = this; - return self is Set ? self : this.retype(); - } + Set cast() => Set.castFrom(this); - Set retype() => Set.castFrom(this); + @Deprecated("Use cast instead.") + Set retype() => cast(); bool contains(Object value) => set.contains(value); diff --git a/pkg/compiler/lib/src/helpers/expensive_map.dart b/pkg/compiler/lib/src/helpers/expensive_map.dart index 35001e4017a..48be3849459 100644 --- a/pkg/compiler/lib/src/helpers/expensive_map.dart +++ b/pkg/compiler/lib/src/helpers/expensive_map.dart @@ -68,12 +68,10 @@ class ExpensiveMap extends MapBase { } } - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); Iterable> get entries => _maps[0].entries; diff --git a/pkg/compiler/lib/src/helpers/track_map.dart b/pkg/compiler/lib/src/helpers/track_map.dart index 833a08a5701..0a87cf5fd63 100644 --- a/pkg/compiler/lib/src/helpers/track_map.dart +++ b/pkg/compiler/lib/src/helpers/track_map.dart @@ -99,7 +99,8 @@ class TrackMap implements Map { Map cast() => _map.cast(); - Map retype() => _map.retype(); + @Deprecated("Use cast instead.") + Map retype() => cast(); Iterable> get entries => _map.entries; diff --git a/pkg/compiler/lib/src/util/emptyset.dart b/pkg/compiler/lib/src/util/emptyset.dart index d37b0c422b2..1fa3dbaddb1 100644 --- a/pkg/compiler/lib/src/util/emptyset.dart +++ b/pkg/compiler/lib/src/util/emptyset.dart @@ -9,12 +9,10 @@ import 'dart:collection' show IterableBase; class ImmutableEmptySet extends IterableBase implements Set { const ImmutableEmptySet(); - Set cast() { - Set self = this; - return self is Set ? self : this.retype(); - } + Set cast() => new ImmutableEmptySet(); - Set retype() => new ImmutableEmptySet(); + @Deprecated("Use cast instead.") + Set retype() => cast(); get iterator => const _EmptySetIterator(); int get length => 0; diff --git a/pkg/compiler/lib/src/util/setlet.dart b/pkg/compiler/lib/src/util/setlet.dart index 27e7a863b81..08195f051e5 100644 --- a/pkg/compiler/lib/src/util/setlet.dart +++ b/pkg/compiler/lib/src/util/setlet.dart @@ -29,7 +29,10 @@ class Setlet extends SetBase { static Set _newSet() => new Setlet(); - Set retype() => Set.castFrom(this, newSet: _newSet); + Set cast() => Set.castFrom(this, newSet: _newSet); + + @Deprecated("Use cast instead.") + Set retype() => cast(); Iterator get iterator { if (_extra == null) { diff --git a/pkg/dev_compiler/tool/input_sdk/private/js_array.dart b/pkg/dev_compiler/tool/input_sdk/private/js_array.dart index abcf157db90..3cac8a5beb5 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/js_array.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/js_array.dart @@ -66,12 +66,10 @@ class JSArray implements List, JSIndexable { } } - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void add(E value) { checkGrowable('add'); diff --git a/runtime/lib/compact_hash.dart b/runtime/lib/compact_hash.dart index 82bc53209a1..fb3d938b0e6 100644 --- a/runtime/lib/compact_hash.dart +++ b/runtime/lib/compact_hash.dart @@ -460,12 +460,10 @@ class _CompactLinkedHashSet extends _HashFieldBase static Set _newEmpty() => new _CompactLinkedHashSet(); - Set cast() { - Set self = this; - return self is Set ? self : Set.castFrom(this, newSet: _newEmpty); - } + Set cast() => Set.castFrom(this, newSet: _newEmpty); - Set retype() => Set.castFrom(this, newSet: _newEmpty); + @Deprecated("Use cast instead.") + Set retype() => cast(); int get length => _usedData - _deletedKeys; @@ -623,12 +621,10 @@ class _CompactLinkedIdentityHashSet extends _CompactLinkedHashSet static Set _newEmpty() => new _CompactLinkedIdentityHashSet(); - Set cast() { - Set self = this; - return self is Set ? self : Set.castFrom(this, newSet: _newEmpty); - } + Set cast() => Set.castFrom(this, newSet: _newEmpty); - Set retype() => Set.castFrom(this, newSet: _newEmpty); + @Deprecated("Use cast instead.") + Set retype() => cast(); } class _CompactLinkedCustomHashSet extends _CompactLinkedHashSet { @@ -646,12 +642,10 @@ class _CompactLinkedCustomHashSet extends _CompactLinkedHashSet { _CompactLinkedCustomHashSet(this._equality, this._hasher, validKey) : _validKey = (validKey != null) ? validKey : new _TypeTest().test; - Set cast() { - Set self = this; - return self is Set ? self : Set.castFrom(this); - } + Set cast() => Set.castFrom(this); - Set retype() => Set.castFrom(this); + @Deprecated("Use cast instead.") + Set retype() => cast(); Set toSet() => new _CompactLinkedCustomHashSet(_equality, _hasher, _validKey) diff --git a/runtime/lib/immutable_map.dart b/runtime/lib/immutable_map.dart index 0417d71218d..2057a574eb6 100644 --- a/runtime/lib/immutable_map.dart +++ b/runtime/lib/immutable_map.dart @@ -13,12 +13,10 @@ class _ImmutableMap implements Map { const _ImmutableMap._create(_ImmutableList keyValuePairs) : _kvPairs = keyValuePairs; - Map cast() { - Map self = this; - return (self is Map) ? self : this.retype(); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); V operator [](Object key) { // To preserve the key-value order of the map literal, the keys are diff --git a/runtime/lib/typed_data_patch.dart b/runtime/lib/typed_data_patch.dart index 383bfcda35a..b868a2d2521 100644 --- a/runtime/lib/typed_data_patch.dart +++ b/runtime/lib/typed_data_patch.dart @@ -123,12 +123,10 @@ abstract class _IntListMixin implements List { Iterable followedBy(Iterable other) => new FollowedByIterable.firstEfficient(this, other); - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void set first(int value) { if (this.length == 0) throw new RangeError.index(0, this); @@ -486,12 +484,10 @@ abstract class _DoubleListMixin implements List { Iterable followedBy(Iterable other) => new FollowedByIterable.firstEfficient(this, other); - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void set first(double value) { if (this.length == 0) throw new RangeError.index(0, this); @@ -852,12 +848,10 @@ abstract class _Float32x4ListMixin implements List { Iterable followedBy(Iterable other) => new FollowedByIterable.firstEfficient(this, other); - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void set first(Float32x4 value) { if (this.length == 0) throw new RangeError.index(0, this); @@ -1222,12 +1216,10 @@ abstract class _Int32x4ListMixin implements List { Iterable followedBy(Iterable other) => new FollowedByIterable.firstEfficient(this, other); - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void set first(Int32x4 value) { if (this.length == 0) throw new RangeError.index(0, this); @@ -1591,12 +1583,10 @@ abstract class _Float64x2ListMixin implements List { Iterable followedBy(Iterable other) => new FollowedByIterable.firstEfficient(this, other); - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void set first(Float64x2 value) { if (this.length == 0) throw new RangeError.index(0, this); diff --git a/samples-dev/swarm/swarm_ui_lib/observable/observable.dart b/samples-dev/swarm/swarm_ui_lib/observable/observable.dart index e9d32f8c027..4ae4097ef50 100644 --- a/samples-dev/swarm/swarm_ui_lib/observable/observable.dart +++ b/samples-dev/swarm/swarm_ui_lib/observable/observable.dart @@ -148,7 +148,8 @@ class ObservableList extends AbstractObservable List cast() => _internal.cast(); - List retype() => _internal.retype(); + @Deprecated("Use cast instead.") + List retype() => cast(); Iterable whereType() => _internal.whereType(); diff --git a/sdk/lib/_http/http_session.dart b/sdk/lib/_http/http_session.dart index 1e1ff5e3ed5..baca21b8bee 100644 --- a/sdk/lib/_http/http_session.dart +++ b/sdk/lib/_http/http_session.dart @@ -79,7 +79,8 @@ class _HttpSession implements HttpSession { Map cast() => _data.cast(); - Map retype() => _data.retype(); + @Deprecated("Use cast instead.") + Map retype() => cast(); update(key, update(value), {ifAbsent()}) => _data.update(key, update, ifAbsent: ifAbsent); diff --git a/sdk/lib/_internal/js_runtime/lib/constant_map.dart b/sdk/lib/_internal/js_runtime/lib/constant_map.dart index cf0285a31b6..9f571b915e4 100644 --- a/sdk/lib/_internal/js_runtime/lib/constant_map.dart +++ b/sdk/lib/_internal/js_runtime/lib/constant_map.dart @@ -47,12 +47,10 @@ abstract class ConstantMap implements Map { const ConstantMap._(); - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); bool get isEmpty => length == 0; diff --git a/sdk/lib/_internal/js_runtime/lib/js_array.dart b/sdk/lib/_internal/js_runtime/lib/js_array.dart index 04e8f49cd16..df030037e40 100644 --- a/sdk/lib/_internal/js_runtime/lib/js_array.dart +++ b/sdk/lib/_internal/js_runtime/lib/js_array.dart @@ -119,12 +119,10 @@ class JSArray extends Interceptor implements List, JSIndexable { } } - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); void add(E value) { checkGrowable('add'); diff --git a/sdk/lib/async/stream.dart b/sdk/lib/async/stream.dart index 4f9f8a96ef0..5df84c57550 100644 --- a/sdk/lib/async/stream.dart +++ b/sdk/lib/async/stream.dart @@ -932,25 +932,16 @@ abstract class Stream { return future; } - /** - * Adapt this stream to be a `Stream`. - * - * If this stream already has the desired type, its returned directly. - * Otherwise it is wrapped as a `Stream` which checks at run-time that - * each data event emitted by this stream is also an instance of [R]. - */ - Stream cast() { - Stream self = this; - return self is Stream ? self : retype(); - } - /** * Adapt this stream to be a `Stream`. * * This stream is wrapped as a `Stream` which checks at run-time that * each data event emitted by this stream is also an instance of [R]. */ - Stream retype() => Stream.castFrom(this); + Stream cast() => Stream.castFrom(this); + + @Deprecated("Use cast instead.") + Stream retype() => cast(); /** * Collects all elements of this stream in a [List]. @@ -2020,15 +2011,6 @@ abstract class StreamTransformer { */ Stream bind(Stream stream); - /** - * Provides a `StreamTransformer` view of this stream transformer. - * - * If this transformer already has the desired type, or a subtype, - * it is returned directly, - * otherwise returns the result of `retype()`. - */ - StreamTransformer cast(); - /** * Provides a `StreamTrasformer` view of this stream transformer. * @@ -2037,6 +2019,9 @@ abstract class StreamTransformer { * and it will check that all data events produced by this transformer * are acually instances of [RT]. */ + StreamTransformer cast(); + + @Deprecated("Use cast instead.") StreamTransformer retype(); } @@ -2048,13 +2033,11 @@ abstract class StreamTransformer { abstract class StreamTransformerBase implements StreamTransformer { const StreamTransformerBase(); - StreamTransformer cast() { - StreamTransformer self = this; - return self is StreamTransformer ? self : retype(); - } - - StreamTransformer retype() => + StreamTransformer cast() => StreamTransformer.castFrom(this); + + @Deprecated("Use cast instead.") + StreamTransformer retype() => cast(); } /** diff --git a/sdk/lib/collection/collections.dart b/sdk/lib/collection/collections.dart index 743e27ab962..f20b5ce937f 100644 --- a/sdk/lib/collection/collections.dart +++ b/sdk/lib/collection/collections.dart @@ -21,13 +21,10 @@ class UnmodifiableListView extends UnmodifiableListBase { */ UnmodifiableListView(Iterable source) : _source = source; - List cast() { - List self = this; - if (self is List) return self; - return new UnmodifiableListView(_source.cast()); - } + List cast() => new UnmodifiableListView(_source.cast()); - List retype() => new UnmodifiableListView(_source.retype()); + @Deprecated("Use cast instead.") + List retype() => cast(); int get length => _source.length; diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart index b652da3421d..b75dc446812 100644 --- a/sdk/lib/collection/hash_set.dart +++ b/sdk/lib/collection/hash_set.dart @@ -14,14 +14,10 @@ abstract class _HashSetBase extends SetBase { Set _newSimilarSet(); - Set cast() { - Set self = this; - return self is Set - ? self - : Set.castFrom(this, newSet: _newSimilarSet); - } + Set cast() => Set.castFrom(this, newSet: _newSimilarSet); - Set retype() => Set.castFrom(this, newSet: _newSimilarSet); + @Deprecated("Use cast instead.") + Set retype() => cast(); Set difference(Set other) { Set result = _newSet(); diff --git a/sdk/lib/collection/iterable.dart b/sdk/lib/collection/iterable.dart index 6b88ff93bd5..fe1873a672d 100644 --- a/sdk/lib/collection/iterable.dart +++ b/sdk/lib/collection/iterable.dart @@ -15,12 +15,10 @@ abstract class IterableMixin implements Iterable { // - SetMixin // If changing a method here, also change the other copies. - Iterable cast() { - Iterable self = this; - return self is Iterable ? self : Iterable.castFrom(this); - } + Iterable cast() => Iterable.castFrom(this); - Iterable retype() => Iterable.castFrom(this); + @Deprecated("Use cast instead.") + Iterable retype() => cast(); Iterable map(T f(E element)) => new MappedIterable(this, f); diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart index 4ced94b326d..fb430a783a2 100644 --- a/sdk/lib/collection/list.dart +++ b/sdk/lib/collection/list.dart @@ -329,12 +329,10 @@ abstract class ListMixin implements List { this.length = 0; } - List cast() { - List self = this; - return self is List ? self : List.castFrom(this); - } + List cast() => List.castFrom(this); - List retype() => List.castFrom(this); + @Deprecated("Use cast instead.") + List retype() => cast(); E removeLast() { if (length == 0) { diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart index bdd775aab96..5bc178d0a46 100644 --- a/sdk/lib/collection/maps.dart +++ b/sdk/lib/collection/maps.dart @@ -118,12 +118,10 @@ abstract class MapMixin implements Map { // It should clear the map even if some keys are not equal to themselves. void clear(); - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); void forEach(void action(K key, V value)) { for (K key in keys) { @@ -318,7 +316,8 @@ class MapView implements Map { Map cast() => _map.cast(); - Map retype() => _map.retype(); + @Deprecated("Use cast instead.") + Map retype() => cast(); V operator [](Object key) => _map[key]; void operator []=(K key, V value) { @@ -380,12 +379,9 @@ class UnmodifiableMapView extends MapView with _UnmodifiableMapMixin { UnmodifiableMapView(Map map) : super(map); - Map cast() { - Map self = this; - if (self is Map) return self; - return new UnmodifiableMapView(_map.cast()); - } + Map cast() => + new UnmodifiableMapView(_map.cast()); - Map retype() => - new UnmodifiableMapView(_map.retype()); + @Deprecated("Use cast instead.") + Map retype() => cast(); } diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart index 48136e642be..2242fb272e0 100644 --- a/sdk/lib/collection/queue.dart +++ b/sdk/lib/collection/queue.dart @@ -66,9 +66,7 @@ abstract class Queue implements EfficientLengthIterable { new CastQueue(source); /** - * Provides a view of this queue as a queue of [R] instances. - * - * If this queue is already a `Queue`, it is returned unchanged. + * Provides a view of this queue as a queue of [R] instances, if necessary. * * If this queue contains only instances of [R], all read operations * will work correctly. If any operation tries to access an element @@ -81,18 +79,7 @@ abstract class Queue implements EfficientLengthIterable { */ Queue cast(); - /** - * Provides a view of this queue as a queue of [R] instances, if necessary. - * - * If this queue contains only instances of [R], all read operations - * will work correctly. If any operation tries to access an element - * that is not an instance of [R], the access will throw instead. - * - * Elements added to the queue (e.g., by using [addFirst] or [addAll]) - * must be instance of [R] to be valid arguments to the adding function, - * and they must be instances of [E] as well to be accepted by - * this queue as well. - */ + @Deprecated("Use cast instead.") Queue retype(); /** @@ -356,12 +343,10 @@ class DoubleLinkedQueue extends Iterable implements Queue { factory DoubleLinkedQueue.of(Iterable elements) => new DoubleLinkedQueue()..addAll(elements); - Queue cast() { - Queue self = this; - return self is Queue ? self : Queue.castFrom(this); - } + Queue cast() => Queue.castFrom(this); - Queue retype() => Queue.castFrom(this); + @Deprecated("Use cast instead.") + Queue retype() => cast(); int get length => _elementCount; @@ -657,12 +642,10 @@ class ListQueue extends ListIterable implements Queue { // Iterable interface. - Queue cast() { - Queue self = this; - return self is Queue ? self : this.retype(); - } + Queue cast() => Queue.castFrom(this); - Queue retype() => Queue.castFrom(this); + @Deprecated("Use cast instead.") + Queue retype() => cast(); Iterator get iterator => new _ListQueueIterator(this); diff --git a/sdk/lib/collection/set.dart b/sdk/lib/collection/set.dart index 377d574baee..86e832910fe 100644 --- a/sdk/lib/collection/set.dart +++ b/sdk/lib/collection/set.dart @@ -23,10 +23,6 @@ part of dart.collection; * Implementations of `Set` using this mixin should consider also implementing * `clear` in constant time. The default implementation works by removing every * element. - * - * The [cast] implementation uses [retype] to do the actual cast, so if - * the cast operation wants to pass a custom `newSet` to [Set.castFrom], - * it only needs to override [retype]. */ abstract class SetMixin implements Set { // This class reimplements all of [IterableMixin]. @@ -51,12 +47,10 @@ abstract class SetMixin implements Set { bool get isNotEmpty => length != 0; - Set cast() { - Set self = this; - return self is Set ? self : this.retype(); - } + Set cast() => Set.castFrom(this); - Set retype() => Set.castFrom(this); + @Deprecated("Use cast instead.") + Set retype() => cast(); Iterable followedBy(Iterable other) => new FollowedByIterable.firstEfficient(this, other); diff --git a/sdk/lib/collection/splay_tree.dart b/sdk/lib/collection/splay_tree.dart index fad3ce809a2..dce7dc5e185 100644 --- a/sdk/lib/collection/splay_tree.dart +++ b/sdk/lib/collection/splay_tree.dart @@ -765,12 +765,10 @@ class SplayTreeSet extends _SplayTree> Set _newSet() => new SplayTreeSet((T a, T b) => _comparator(a as E, b as E), _validKey); - Set cast() { - Set self = this; - return self is Set ? self : Set.castFrom(this, newSet: _newSet); - } + Set cast() => Set.castFrom(this, newSet: _newSet); - Set retype() => Set.castFrom(this, newSet: _newSet); + @Deprecated("Use cast instead.") + Set retype() => cast(); int _compare(E e1, E e2) => _comparator(e1, e2); diff --git a/sdk/lib/convert/converter.dart b/sdk/lib/convert/converter.dart index 01d61865727..3fdcb4c7b11 100644 --- a/sdk/lib/convert/converter.dart +++ b/sdk/lib/convert/converter.dart @@ -56,18 +56,6 @@ abstract class Converter extends StreamTransformerBase { stream, (EventSink sink) => new _ConverterStreamEventSink(this, sink)); } - /** - * Provides a `Converter` view of this stream transformer. - * - * If this transformer already has the desired type, or a subtype, - * it is returned directly, - * otherwise returns the result of `retype()`. - */ - Converter cast() { - Converter self = this; - return self is Converter ? self : retype(); - } - /** * Provides a `Converter` view of this stream transformer. * @@ -76,7 +64,10 @@ abstract class Converter extends StreamTransformerBase { * and it will check that all conversion output produced by this converter * are acually instances of [RT]. */ - Converter retype() => Converter.castFrom(this); + Converter cast() => Converter.castFrom(this); + + @Deprecated("Use cast instead.") + Converter retype() => cast(); } /** diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart index 218781211a6..99361f71be5 100644 --- a/sdk/lib/core/iterable.dart +++ b/sdk/lib/core/iterable.dart @@ -153,20 +153,6 @@ abstract class Iterable { */ Iterator get iterator; - /** - * Makes this iterable useful as an `Iterable`, if necessary. - * - * Like [retype] except that this iterable is returned as-is - * if it is already an `Iterable`. - * - * It means that `someIterable.cast().toList()` is not guaranteed - * to return precisely a `List`, but it may return a subtype. - */ - Iterable cast() { - Iterable self = this; - return self is Iterable ? self : Iterable.castFrom(this); - } - /** * Provides a view of this iterable as an iterable of [R] instances. * @@ -177,7 +163,10 @@ abstract class Iterable { * When the returned iterable creates a new object that depends on * the type [R], e.g., from [toList], it will have exactly the type [R]. */ - Iterable retype() => Iterable.castFrom(this); + Iterable cast() => Iterable.castFrom(this); + + @Deprecated("Use cast instead.") + Iterable retype() => cast(); /** * Returns the lazy concatentation of this iterable and [other]. diff --git a/sdk/lib/core/list.dart b/sdk/lib/core/list.dart index 8df6ca5b3b6..bff5b31a403 100644 --- a/sdk/lib/core/list.dart +++ b/sdk/lib/core/list.dart @@ -253,22 +253,6 @@ abstract class List implements EfficientLengthIterable { } } - /** - * Returns a view of this list as a list of [R] instances, if necessary. - * - * If this list is already a `List`, it is returned unchanged. - * - * If this list contains only instances of [R], all read operations - * will work correctly. If any operation tries to access an element - * that is not an instance of [R], the access will throw instead. - * - * Elements added to the list (e.g., by using [add] or [addAll]) - * must be instance of [R] to be valid arguments to the adding function, - * and they must be instances of [E] as well to be accepted by - * this list as well. - */ - List cast(); - /** * Returns a view of this list as a list of [R] instances. * @@ -283,6 +267,9 @@ abstract class List implements EfficientLengthIterable { * * Typically implemented as `List.castFrom(this)`. */ + List cast(); + + @Deprecated("Use cast instead.") List retype(); /** diff --git a/sdk/lib/core/map.dart b/sdk/lib/core/map.dart index 9009dff5b24..51fda37fb60 100644 --- a/sdk/lib/core/map.dart +++ b/sdk/lib/core/map.dart @@ -177,20 +177,6 @@ abstract class Map { factory Map.fromEntries(Iterable> entries) => {}..addEntries(entries); - /** - * Provides a view of this map as having [RK] keys and [RV] instances, - * if necessary. - * - * If this set contains only keys of type [RK] and values of type [RV], - * all read operations will work correctly. - * If any operation exposes a non-[RK] key or non-[RV] value, - * the operation will throw instead. - * - * Entries added to the map must be valid for both a `Map` and a - * `Map`. - */ - Map cast(); - /** * Provides a view of this map as having [RK] keys and [RV] instances, * if necessary. @@ -205,6 +191,9 @@ abstract class Map { * Entries added to the map must be valid for both a `Map` and a * `Map`. */ + Map cast(); + + @Deprecated("Use cast instead.") Map retype(); /** diff --git a/sdk/lib/core/set.dart b/sdk/lib/core/set.dart index e7c36be6653..d85ae2b497d 100644 --- a/sdk/lib/core/set.dart +++ b/sdk/lib/core/set.dart @@ -114,9 +114,7 @@ abstract class Set extends EfficientLengthIterable { new CastSet(source, newSet); /** - * Provides a view of this set as a set of [R] instances, if necessary. - * - * If this set is already a `Set`, it is returned unchanged. + * Provides a view of this set as a set of [R] instances. * * If this set contains only instances of [R], all read operations * will work correctly. If any operation tries to access an element @@ -129,18 +127,7 @@ abstract class Set extends EfficientLengthIterable { */ Set cast(); - /** - * Provides a view of this set as a set of [R] instances. - * - * If this set contains only instances of [R], all read operations - * will work correctly. If any operation tries to access an element - * that is not an instance of [R], the access will throw instead. - * - * Elements added to the set (e.g., by using [add] or [addAll]) - * must be instance of [R] to be valid arguments to the adding function, - * and they must be instances of [E] as well to be accepted by - * this set as well. - */ + @Deprecated("Use cast instead.") Set retype(); /** diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index acf0390cd7f..1f622c48197 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -46414,12 +46414,10 @@ abstract class _AttributeMap extends MapBase { }); } - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); bool containsValue(Object value) { for (var v in this.values) { @@ -46581,12 +46579,10 @@ class _DataAttributeMap extends MapBase { }); } - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); // TODO: Use lazy iterator when it is available on Map. bool containsValue(Object value) => values.any((v) => v == value); diff --git a/sdk/lib/internal/async_cast.dart b/sdk/lib/internal/async_cast.dart index 924ac53f4e1..eb59a7d08bd 100644 --- a/sdk/lib/internal/async_cast.dart +++ b/sdk/lib/internal/async_cast.dart @@ -18,12 +18,10 @@ class CastStream extends Stream { ..onData(onData); } - Stream cast() { - Stream self = this; - return self is Stream ? self : this.retype(); - } + Stream cast() => new CastStream(_source); - Stream retype() => new CastStream(_source); + @Deprecated("Use cast instead.") + Stream retype() => cast(); } class CastStreamSubscription implements StreamSubscription { @@ -63,11 +61,12 @@ class CastStreamTransformer final StreamTransformer _source; CastStreamTransformer(this._source); - // cast is inherited from StreamTransformerBase. - - StreamTransformer retype() => + StreamTransformer cast() => new CastStreamTransformer(_source); + @Deprecated("Use cast instead.") + StreamTransformer retype() => cast(); + Stream bind(Stream stream) => _source.bind(stream.cast()).cast(); } @@ -83,6 +82,9 @@ class CastConverter extends Converter { Stream bind(Stream stream) => _source.bind(stream.cast()).cast(); - Converter retype() => + Converter cast() => new CastConverter(_source); + + @Deprecated("Use cast instead.") + Converter retype() => cast(); } diff --git a/sdk/lib/internal/cast.dart b/sdk/lib/internal/cast.dart index 97652531ca1..c2a6ce4f985 100644 --- a/sdk/lib/internal/cast.dart +++ b/sdk/lib/internal/cast.dart @@ -188,13 +188,10 @@ class CastSet extends _CastIterableBase implements Set { static Set _defaultEmptySet() => new Set(); - Set cast() { - Set self = this; - if (self is Set) return self; - return this.retype(); - } + Set cast() => new CastSet(_source, _emptySet); - Set retype() => new CastSet(_source, _emptySet); + @Deprecated("Use cast instead.") + Set retype() => cast(); bool add(T value) => _source.add(value as S); @@ -370,13 +367,10 @@ class CastQueue extends _CastIterableBase with _CastQueueMixin { final Queue _source; CastQueue(this._source); - Queue cast() { - Queue self = this; - if (self is Queue) return self; - return retype(); - } + Queue cast() => new CastQueue(_source); - Queue retype() => new CastQueue(_source); + @Deprecated("Use cast instead.") + Queue retype() => cast(); } // TODO(lrn): Use when ListQueue implements List. diff --git a/tests/corelib_2/growable_list_test.dart b/tests/corelib_2/growable_list_test.dart index f6787ffde17..ebe04bc0116 100644 --- a/tests/corelib_2/growable_list_test.dart +++ b/tests/corelib_2/growable_list_test.dart @@ -37,7 +37,9 @@ class EfficientTestIterable extends TestIterableBase implements Set { // Avoid warnings because we don't actually implement Set. noSuchMethod(i) => super.noSuchMethod(i); Set cast() => throw "not used by test"; - Set retype() => throw "not used by test"; + + @Deprecated("Use cast instead.") + Set retype() => cast(); } class CallbackIterator implements Iterator { diff --git a/tools/dom/src/AttributeMap.dart b/tools/dom/src/AttributeMap.dart index 85aef194108..a6e79f3be33 100644 --- a/tools/dom/src/AttributeMap.dart +++ b/tools/dom/src/AttributeMap.dart @@ -15,12 +15,10 @@ abstract class _AttributeMap extends MapBase { }); } - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); bool containsValue(Object value) { for (var v in this.values) { @@ -182,12 +180,10 @@ class _DataAttributeMap extends MapBase { }); } - Map cast() { - Map self = this; - return self is Map ? self : Map.castFrom(this); - } + Map cast() => Map.castFrom(this); - Map retype() => Map.castFrom(this); + @Deprecated("Use cast instead.") + Map retype() => cast(); // TODO: Use lazy iterator when it is available on Map. bool containsValue(Object value) => values.any((v) => v == value);