apply upcoming rule use_collection_literals_when_possible (#8649)

This commit is contained in:
Alexandre Ardhuin 2017-03-08 23:57:31 +01:00 committed by Ian Hickson
parent 906103dd10
commit 329e52c02c
32 changed files with 56 additions and 59 deletions

View file

@ -134,7 +134,7 @@ class CardBuilder extends SliverChildDelegate {
class OverlayGeometryAppState extends State<OverlayGeometryApp> {
List<CardModel> cardModels;
Map<MarkerType, Point> markers = new Map<MarkerType, Point>();
Map<MarkerType, Point> markers = <MarkerType, Point>{};
double markersScrollOffset = 0.0;
@override

View file

@ -303,7 +303,7 @@ class CalcExpression {
assert(false);
}
}
final List<ExpressionToken> outList = new List<ExpressionToken>();
final List<ExpressionToken> outList = <ExpressionToken>[];
outList.add(new ResultToken(currentTermValue));
return new CalcExpression(outList, ExpressionState.Result);
}

View file

@ -82,7 +82,7 @@ Future<Null> saveDurationsHistogram(List<Map<String, dynamic>> events, String ou
startEvent = event;
} else if (startEvent != null && eventName == 'Frame') {
final String routeName = startEvent['args']['to'];
durations[routeName] ??= new List<int>();
durations[routeName] ??= <int>[];
durations[routeName].add(event['dur']);
startEvent = null;
}

View file

@ -9,7 +9,7 @@ import 'dart:collection';
/// Consider using an [ObserverList] instead of a [List] when the number of
/// [contains] calls dominates the number of [add] and [remove] calls.
class ObserverList<T> extends Iterable<T> {
final List<T> _list = new List<T>();
final List<T> _list = <T>[];
bool _isDirty = false;
HashSet<T> _set;

View file

@ -49,7 +49,7 @@ class GestureArenaEntry {
}
class _GestureArena {
final List<GestureArenaMember> members = new List<GestureArenaMember>();
final List<GestureArenaMember> members = <GestureArenaMember>[];
bool isOpen = true;
bool isHeld = false;
bool hasPendingSweep = false;
@ -71,7 +71,7 @@ class _GestureArena {
/// See [https://flutter.io/gestures/#gesture-disambiguation] for more
/// information about the role this class plays in the gesture system.
class GestureArenaManager {
final Map<int, _GestureArena> _arenas = new Map<int, _GestureArena>();
final Map<int, _GestureArena> _arenas = <int, _GestureArena>{};
/// Adds a new member (e.g., gesture recognizer) to the arena.
GestureArenaEntry add(int pointer, GestureArenaMember member) {

View file

@ -264,7 +264,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
double _getPrimaryValueFromOffset(Offset value);
bool get _hasSufficientPendingDragDeltaToAccept;
Map<int, VelocityTracker> _velocityTrackers = new Map<int, VelocityTracker>();
Map<int, VelocityTracker> _velocityTrackers = <int, VelocityTracker>{};
@override
void addPointer(PointerEvent event) {

View file

@ -94,7 +94,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
Timer _doubleTapTimer;
_TapTracker _firstTap;
final Map<int, _TapTracker> _trackers = new Map<int, _TapTracker>();
final Map<int, _TapTracker> _trackers = <int, _TapTracker>{};
@override
void addPointer(PointerEvent event) {
@ -341,7 +341,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
/// particular location after [longTapDelay].
GestureMultiTapDownCallback onLongTapDown;
final Map<int, _TapGesture> _gestureMap = new Map<int, _TapGesture>();
final Map<int, _TapGesture> _gestureMap = <int, _TapGesture>{};
@override
void addPointer(PointerEvent event) {

View file

@ -13,7 +13,7 @@ typedef void PointerRoute(PointerEvent event);
/// A routing table for [PointerEvent] events.
class PointerRouter {
final Map<int, LinkedHashSet<PointerRoute>> _routeMap = new Map<int, LinkedHashSet<PointerRoute>>();
final Map<int, LinkedHashSet<PointerRoute>> _routeMap = <int, LinkedHashSet<PointerRoute>>{};
final LinkedHashSet<PointerRoute> _globalRoutes = new LinkedHashSet<PointerRoute>();
/// Adds a route to the routing table.

View file

@ -115,7 +115,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
double _initialSpan;
double _currentSpan;
Map<int, Point> _pointerLocations;
Map<int, VelocityTracker> _velocityTrackers = new Map<int, VelocityTracker>();
Map<int, VelocityTracker> _velocityTrackers = <int, VelocityTracker>{};
double get _scaleFactor => _initialSpan > 0.0 ? _currentSpan / _initialSpan : 1.0;
@ -127,7 +127,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
_state = ScaleState.possible;
_initialSpan = 0.0;
_currentSpan = 0.0;
_pointerLocations = new Map<int, Point>();
_pointerLocations = <int, Point>{};
}
}

View file

@ -90,7 +90,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
/// To assign a gesture recognizer to a team, see
/// [OneSequenceGestureRecognizer.team].
class GestureArenaTeam {
final Map<int, _CombiningGestureArenaMember> _combiners = new Map<int, _CombiningGestureArenaMember>();
final Map<int, _CombiningGestureArenaMember> _combiners = <int, _CombiningGestureArenaMember>{};
/// Adds a new member to the arena on behalf of this team.
///

View file

@ -63,10 +63,10 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
@override
_Estimate getEstimate() {
// Iterate over movement samples in reverse time order and collect samples.
final List<double> x = new List<double>();
final List<double> y = new List<double>();
final List<double> w = new List<double>();
final List<double> time = new List<double>();
final List<double> x = <double>[];
final List<double> y = <double>[];
final List<double> w = <double>[];
final List<double> time = <double>[];
int m = 0;
int index = _index;

View file

@ -134,7 +134,7 @@ class AlertDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Widget> children = new List<Widget>();
final List<Widget> children = <Widget>[];
if (title != null) {
children.add(new Padding(

View file

@ -233,7 +233,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
@override
Widget build(BuildContext context) {
final List<Widget> children = new List<Widget>();
final List<Widget> children = <Widget>[];
if (_previousAnimation.status != AnimationStatus.dismissed) {
children.add(new ScaleTransition(
scale: _previousAnimation,
@ -777,7 +777,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
}
}
final List<LayoutId> children = new List<LayoutId>();
final List<LayoutId> children = <LayoutId>[];
_addIfNonNull(children, config.body, _ScaffoldSlot.body);

View file

@ -178,7 +178,7 @@ class Stepper extends StatefulWidget {
class _StepperState extends State<Stepper> with TickerProviderStateMixin {
List<GlobalKey> _keys;
final Map<int, StepState> _oldStates = new Map<int, StepState>();
final Map<int, StepState> _oldStates = <int, StepState>{};
@override
void initState() {

View file

@ -578,10 +578,10 @@ class BoxShadow {
if (a == null && b == null)
return null;
if (a == null)
a = new List<BoxShadow>();
a = <BoxShadow>[];
if (b == null)
b = new List<BoxShadow>();
final List<BoxShadow> result = new List<BoxShadow>();
b = <BoxShadow>[];
final List<BoxShadow> result = <BoxShadow>[];
final int commonLength = math.min(a.length, b.length);
for (int i = 0; i < commonLength; ++i)
result.add(BoxShadow.lerp(a[i], b[i], t));

View file

@ -1483,7 +1483,7 @@ abstract class RenderBox extends RenderObject {
double getDistanceToActualBaseline(TextBaseline baseline) {
assert(_debugDoingBaseline);
if (_cachedBaselines == null)
_cachedBaselines = new Map<TextBaseline, double>();
_cachedBaselines = <TextBaseline, double>{};
_cachedBaselines.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline));
return _cachedBaselines[baseline];
}

View file

@ -170,7 +170,7 @@ abstract class MultiChildLayoutDelegate {
});
try {
_idToChild = new Map<Object, RenderBox>();
_idToChild = <Object, RenderBox>{};
RenderBox child = firstChild;
while (child != null) {
final MultiChildLayoutParentData childParentData = child.parentData;

View file

@ -494,7 +494,7 @@ class RenderTable extends RenderBox {
assert(configuration != null);
_columns = columns ?? (children != null && children.isNotEmpty ? children.first.length : 0);
_rows = rows ?? 0;
_children = new List<RenderBox>()..length = _columns * _rows;
_children = <RenderBox>[]..length = _columns * _rows;
_columnWidths = columnWidths ?? new HashMap<int, TableColumnWidth>();
_defaultColumnWidth = defaultColumnWidth;
_border = border;
@ -529,7 +529,7 @@ class RenderTable extends RenderBox {
final int oldColumns = columns;
final List<RenderBox> oldChildren = _children;
_columns = value;
_children = new List<RenderBox>()..length = columns * rows;
_children = <RenderBox>[]..length = columns * rows;
final int columnsToCopy = math.min(columns, oldColumns);
for (int y = 0; y < rows; y += 1) {
for (int x = 0; x < columnsToCopy; x += 1)

View file

@ -402,7 +402,7 @@ abstract class SchedulerBinding extends BindingBase {
});
}
final List<FrameCallback> _persistentCallbacks = new List<FrameCallback>();
final List<FrameCallback> _persistentCallbacks = <FrameCallback>[];
/// Adds a persistent frame callback.
///
@ -420,7 +420,7 @@ abstract class SchedulerBinding extends BindingBase {
_persistentCallbacks.add(callback);
}
final List<FrameCallback> _postFrameCallbacks = new List<FrameCallback>();
final List<FrameCallback> _postFrameCallbacks = <FrameCallback>[];
/// Schedule a callback for the end of this frame.
///
@ -637,7 +637,7 @@ abstract class SchedulerBinding extends BindingBase {
Timeline.startSync('Animate');
assert(schedulerPhase == SchedulerPhase.transientCallbacks);
final Map<int, _FrameCallbackEntry> callbacks = _transientCallbacks;
_transientCallbacks = new Map<int, _FrameCallbackEntry>();
_transientCallbacks = <int, _FrameCallbackEntry>{};
callbacks.forEach((int id, _FrameCallbackEntry callbackEntry) {
if (!_removedIds.contains(id))
_invokeFrameCallback(callbackEntry.callback, timeStamp, callbackEntry.debugStack);

View file

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection';
import 'image_stream.dart';
const int _kDefaultSize = 1000;
@ -27,7 +25,7 @@ const int _kDefaultSize = 1000;
/// Generally this class is not used directly. The [ImageProvider] class and its
/// subclasses automatically handle the caching of images.
class ImageCache {
final LinkedHashMap<Object, ImageStreamCompleter> _cache = new LinkedHashMap<Object, ImageStreamCompleter>();
final Map<Object, ImageStreamCompleter> _cache = <Object, ImageStreamCompleter>{};
/// Maximum number of entries to store in the cache.
///

View file

@ -358,7 +358,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
break;
case _kMap:
final int length = _readSize(buffer);
result = new Map<dynamic, dynamic>();
result = <dynamic, dynamic>{};
for (int i = 0; i < length; i++) {
result[_readValue(buffer)] = _readValue(buffer);
}
@ -418,4 +418,3 @@ class StandardMethodCodec implements MethodCodec {
throw new FormatException('Invalid envelope');
}
}

View file

@ -380,8 +380,8 @@ List<T> _mapAvatarsToData<T>(List<_DragAvatar<T>> avatars) {
}
class _DragTargetState<T> extends State<DragTarget<T>> {
final List<_DragAvatar<T>> _candidateAvatars = new List<_DragAvatar<T>>();
final List<_DragAvatar<dynamic>> _rejectedAvatars = new List<_DragAvatar<dynamic>>();
final List<_DragAvatar<T>> _candidateAvatars = <_DragAvatar<T>>[];
final List<_DragAvatar<dynamic>> _rejectedAvatars = <_DragAvatar<dynamic>>[];
bool didEnter(_DragAvatar<dynamic> avatar) {
assert(!_candidateAvatars.contains(avatar));

View file

@ -167,11 +167,11 @@ abstract class GlobalKey<T extends State<StatefulWidget>> extends Key {
/// constructor.
const GlobalKey.constructor() : super._();
static final Map<GlobalKey, Element> _registry = new Map<GlobalKey, Element>();
static final Map<GlobalKey, Set<GlobalKeyRemoveListener>> _removeListeners = new Map<GlobalKey, Set<GlobalKeyRemoveListener>>();
static final Map<GlobalKey, Element> _registry = <GlobalKey, Element>{};
static final Map<GlobalKey, Set<GlobalKeyRemoveListener>> _removeListeners = <GlobalKey, Set<GlobalKeyRemoveListener>>{};
static final Set<GlobalKey> _removedKeys = new HashSet<GlobalKey>();
static final Set<Element> _debugIllFatedElements = new HashSet<Element>();
static final Map<GlobalKey, Element> _debugReservations = new Map<GlobalKey, Element>();
static final Map<GlobalKey, Element> _debugReservations = <GlobalKey, Element>{};
void _register(Element element) {
assert(() {
@ -3421,7 +3421,7 @@ class InheritedElement extends ProxyElement {
if (incomingWidgets != null)
_inheritedWidgets = new Map<Type, InheritedElement>.from(incomingWidgets);
else
_inheritedWidgets = new Map<Type, InheritedElement>();
_inheritedWidgets = <Type, InheritedElement>{};
_inheritedWidgets[widget.runtimeType] = this;
}
@ -3789,7 +3789,7 @@ abstract class RenderObjectElement extends BuildableElement {
final bool haveOldChildren = oldChildrenTop <= oldChildrenBottom;
Map<Key, Element> oldKeyedChildren;
if (haveOldChildren) {
oldKeyedChildren = new Map<Key, Element>();
oldKeyedChildren = <Key, Element>{};
while (oldChildrenTop <= oldChildrenBottom) {
final Element oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenTop]);
assert(oldChild == null || oldChild._debugLifecycleState == _ElementLifecycle.active);

View file

@ -697,7 +697,7 @@ class Navigator extends StatefulWidget {
/// The state for a [Navigator] widget.
class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
final GlobalKey<OverlayState> _overlayKey = new GlobalKey<OverlayState>();
final List<Route<dynamic>> _history = new List<Route<dynamic>>();
final List<Route<dynamic>> _history = <Route<dynamic>>[];
final Set<Route<dynamic>> _poppedRoutes = new Set<Route<dynamic>>();
@override

View file

@ -266,7 +266,7 @@ class Overlay extends StatefulWidget {
/// Used to insert [OverlayEntry]s into the overlay using the [insert] and
/// [insertAll] functions.
class OverlayState extends State<Overlay> with TickerProviderStateMixin {
final List<OverlayEntry> _entries = new List<OverlayEntry>();
final List<OverlayEntry> _entries = <OverlayEntry>[];
@override
void initState() {

View file

@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart';
void main() {
testWidgets('Events bubble up the tree', (WidgetTester tester) async {
final List<String> log = new List<String>();
final List<String> log = <String>[];
await tester.pumpWidget(
new Listener(

View file

@ -330,7 +330,7 @@ class DevFS {
final Set<String> assetPathsToEvict = new Set<String>();
final List<Future<Map<String, dynamic>>> _pendingOperations =
new List<Future<Map<String, dynamic>>>();
<Future<Map<String, dynamic>>>[];
Uri _baseUri;
Uri get baseUri => _baseUri;
@ -376,7 +376,7 @@ class DevFS {
// Handle deletions.
printTrace('Scanning for deleted files');
final String assetBuildDirPrefix = _asUriPath(getAssetBuildDirectory());
final List<Uri> toRemove = new List<Uri>();
final List<Uri> toRemove = <Uri>[];
_entries.forEach((Uri deviceUri, DevFSContent content) {
if (!content._exists) {
final Future<Map<String, dynamic>> operation =

View file

@ -434,7 +434,7 @@ class _IOSDeviceLogReader extends DeviceLogReader {
}
class _IOSDevicePortForwarder extends DevicePortForwarder {
_IOSDevicePortForwarder(this.device) : _forwardedPorts = new List<ForwardedPort>();
_IOSDevicePortForwarder(this.device) : _forwardedPorts = <ForwardedPort>[];
final IOSDevice device;

View file

@ -61,7 +61,7 @@ class HotRunner extends ResidentRunner {
Uri _observatoryUri;
final bool benchmarkMode;
final Map<String, int> benchmarkData = new Map<String, int>();
final Map<String, int> benchmarkData = <String, int>{};
// The initial launch is from a snapshot.
bool _runningFromSnapshot = true;
String kernelFilePath;
@ -141,7 +141,7 @@ class HotRunner extends ResidentRunner {
return 1;
}
final Map<String, dynamic> platformArgs = new Map<String, dynamic>();
final Map<String, dynamic> platformArgs = <String, dynamic>{};
await startEchoingDeviceLog(package);

View file

@ -24,7 +24,7 @@ const String _kCopyTemplateExtension = '.copy.tmpl';
/// extensions.
class Template {
Template(Directory templateSource, Directory baseDir) {
_templateFilePaths = new Map<String, String>();
_templateFilePaths = <String, String>{};
if (!templateSource.existsSync()) {
return;

View file

@ -505,14 +505,14 @@ class VM extends ServiceObjectOwner {
_removeDeadIsolates(map['isolates']);
}
final Map<String, ServiceObject> _cache = new Map<String,ServiceObject>();
final Map<String,Isolate> _isolateCache = new Map<String,Isolate>();
final Map<String, ServiceObject> _cache = <String,ServiceObject>{};
final Map<String,Isolate> _isolateCache = <String,Isolate>{};
/// The list of live isolates, ordered by isolate start time.
final List<Isolate> isolates = new List<Isolate>();
final List<Isolate> isolates = <Isolate>[];
/// The set of live views.
final Map<String, FlutterView> _viewCache = new Map<String, FlutterView>();
final Map<String, FlutterView> _viewCache = <String, FlutterView>{};
int _compareIsolates(Isolate a, Isolate b) {
final DateTime aStart = a.startTime;
@ -767,7 +767,7 @@ class Isolate extends ServiceObjectOwner {
DateTime startTime;
ServiceEvent pauseEvent;
final Map<String, ServiceObject> _cache = new Map<String, ServiceObject>();
final Map<String, ServiceObject> _cache = <String, ServiceObject>{};
@override
ServiceObject getFromMap(Map<String, dynamic> map) {
@ -967,7 +967,7 @@ class Isolate extends ServiceObjectOwner {
class ServiceMap extends ServiceObject implements Map<String, dynamic> {
ServiceMap._empty(ServiceObjectOwner owner) : super._empty(owner);
final Map<String, dynamic> _map = new Map<String, dynamic>();
final Map<String, dynamic> _map = <String, dynamic>{};
@override
void _update(Map<String, dynamic> map, bool mapIsRef) {

View file

@ -77,7 +77,7 @@ void applyMocksToCommand(FlutterCommand command) {
/// Common functionality for tracking mock interaction
class BasicMock {
final List<String> messages = new List<String>();
final List<String> messages = <String>[];
void expectMessages(List<String> expectedMessages) {
final List<String> actualMessages = new List<String>.from(messages);