Unnecessary new (#20138)

* enable lint unnecessary_new

* fix tests

* fix tests

* fix tests
diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart
index 51bc7fa..a99c278 100644
--- a/packages/flutter_tools/lib/src/vmservice.dart
+++ b/packages/flutter_tools/lib/src/vmservice.dart
@@ -66,7 +66,7 @@
     printTrace('This was attempt #$attempts. Will retry in $delay.');
 
     // Delay next attempt.
-    await new Future<Null>.delayed(delay);
+    await Future<Null>.delayed(delay);
 
     // Back off exponentially.
     delay *= 2;
@@ -84,13 +84,13 @@
   }
 
   if (socket == null) {
-    throw new ToolExit(
+    throw ToolExit(
       'Attempted to connect to Dart observatory $_kMaxAttempts times, and '
       'all attempts failed. Giving up. The URL was $uri'
     );
   }
 
-  return new IOWebSocketChannel(socket).cast<String>();
+  return IOWebSocketChannel(socket).cast<String>();
 }
 
 /// The default VM service request timeout.
@@ -112,7 +112,7 @@
     ReloadSources reloadSources,
     CompileExpression compileExpression,
   ) {
-    _vm = new VM._empty(this);
+    _vm = VM._empty(this);
     _peer.listen().catchError(_connectionError.completeError);
 
     _peer.registerMethod('streamNotify', (rpc.Parameters event) {
@@ -126,11 +126,11 @@
         final bool pause = params.asMap['pause'] ?? false;
 
         if (isolateId is! String || isolateId.isEmpty)
-          throw new rpc.RpcException.invalidParams('Invalid \'isolateId\': $isolateId');
+          throw rpc.RpcException.invalidParams('Invalid \'isolateId\': $isolateId');
         if (force is! bool)
-          throw new rpc.RpcException.invalidParams('Invalid \'force\': $force');
+          throw rpc.RpcException.invalidParams('Invalid \'force\': $force');
         if (pause is! bool)
-          throw new rpc.RpcException.invalidParams('Invalid \'pause\': $pause');
+          throw rpc.RpcException.invalidParams('Invalid \'pause\': $pause');
 
         try {
           await reloadSources(isolateId, force: force, pause: pause);
@@ -138,7 +138,7 @@
         } on rpc.RpcException {
           rethrow;
         } catch (e, st) {
-          throw new rpc.RpcException(rpc_error_code.SERVER_ERROR,
+          throw rpc.RpcException(rpc_error_code.SERVER_ERROR,
               'Error during Sources Reload: $e\n$st');
         }
       });
@@ -155,16 +155,16 @@
       _peer.registerMethod('compileExpression', (rpc.Parameters params) async {
         final String isolateId = params['isolateId'].asString;
         if (isolateId is! String || isolateId.isEmpty)
-          throw new rpc.RpcException.invalidParams(
+          throw rpc.RpcException.invalidParams(
               'Invalid \'isolateId\': $isolateId');
         final String expression = params['expression'].asString;
         if (expression is! String || expression.isEmpty)
-          throw new rpc.RpcException.invalidParams(
+          throw rpc.RpcException.invalidParams(
               'Invalid \'expression\': $expression');
         final List<String> definitions =
-            new List<String>.from(params['definitions'].asList);
+            List<String>.from(params['definitions'].asList);
         final List<String> typeDefinitions =
-            new List<String>.from(params['typeDefinitions'].asList);
+            List<String>.from(params['typeDefinitions'].asList);
         final String libraryUri = params['libraryUri'].asString;
         final String klass = params['klass'].exists ? params['klass'].asString : null;
         final bool isStatic = params['isStatic'].asBoolOr(false);
@@ -178,7 +178,7 @@
         } on rpc.RpcException {
           rethrow;
         } catch (e, st) {
-          throw new rpc.RpcException(rpc_error_code.SERVER_ERROR,
+          throw rpc.RpcException(rpc_error_code.SERVER_ERROR,
               'Error during expression compilation: $e\n$st');
         }
       });
@@ -201,7 +201,7 @@
     final Directory dir = getRecordingSink(location, _kRecordingType);
     _openChannel = (Uri uri) async {
       final StreamChannel<String> delegate = await _defaultOpenChannel(uri);
-      return new RecordingVMServiceChannel(delegate, dir);
+      return RecordingVMServiceChannel(delegate, dir);
     };
   }
 
@@ -212,7 +212,7 @@
   /// passed to [enableRecordingConnection]), or a [ToolExit] will be thrown.
   static void enableReplayConnection(String location) {
     final Directory dir = getReplaySource(location, _kRecordingType);
-    _openChannel = (Uri uri) async => new ReplayVMServiceChannel(dir);
+    _openChannel = (Uri uri) async => ReplayVMServiceChannel(dir);
   }
 
   /// Connect to a Dart VM Service at [httpUri].
@@ -234,8 +234,8 @@
   }) async {
     final Uri wsUri = httpUri.replace(scheme: 'ws', path: fs.path.join(httpUri.path, 'ws'));
     final StreamChannel<String> channel = await _openChannel(wsUri);
-    final rpc.Peer peer = new rpc.Peer.withoutJson(jsonDocument.bind(channel));
-    final VMService service = new VMService._(peer, httpUri, wsUri, requestTimeout, reloadSources, compileExpression);
+    final rpc.Peer peer = rpc.Peer.withoutJson(jsonDocument.bind(channel));
+    final VMService service = VMService._(peer, httpUri, wsUri, requestTimeout, reloadSources, compileExpression);
     // This call is to ensure we are able to establish a connection instead of
     // keeping on trucking and failing farther down the process.
     await service._sendRequest('getVersion', const <String, dynamic>{});
@@ -246,7 +246,7 @@
   final Uri wsAddress;
   final rpc.Peer _peer;
   final Duration _requestTimeout;
-  final Completer<Map<String, dynamic>> _connectionError = new Completer<Map<String, dynamic>>();
+  final Completer<Map<String, dynamic>> _connectionError = Completer<Map<String, dynamic>>();
 
   VM _vm;
   /// The singleton [VM] object. Owns [Isolate] and [FlutterView] objects.
@@ -255,7 +255,7 @@
   final Map<String, StreamController<ServiceEvent>> _eventControllers =
       <String, StreamController<ServiceEvent>>{};
 
-  final Set<String> _listeningFor = new Set<String>();
+  final Set<String> _listeningFor = Set<String>();
 
   /// Whether our connection to the VM service has been closed;
   bool get isClosed => _peer.isClosed;
@@ -298,7 +298,7 @@
   StreamController<ServiceEvent> _getEventController(String eventName) {
     StreamController<ServiceEvent> controller = _eventControllers[eventName];
     if (controller == null) {
-      controller = new StreamController<ServiceEvent>.broadcast();
+      controller = StreamController<ServiceEvent>.broadcast();
       _eventControllers[eventName] = controller;
     }
     return controller;
@@ -316,7 +316,7 @@
     if (eventIsolate != null) {
       // getFromMap creates the Isolate if necessary.
       final Isolate isolate = vm.getFromMap(eventIsolate);
-      event = new ServiceObject._fromMap(isolate, eventData);
+      event = ServiceObject._fromMap(isolate, eventData);
       if (event.kind == ServiceEvent.kIsolateExit) {
         vm._isolateCache.remove(isolate.id);
         vm._buildIsolateList();
@@ -327,7 +327,7 @@
       }
     } else {
       // The event doesn't have an isolate, so it is owned by the VM.
-      event = new ServiceObject._fromMap(vm, eventData);
+      event = ServiceObject._fromMap(vm, eventData);
     }
     _getEventController(streamId).add(event);
   }
@@ -351,7 +351,7 @@
     for (int i = 0; (vm.firstView == null) && (i < attempts); i++) {
       // If the VM doesn't yet have a view, wait for one to show up.
       printTrace('Waiting for Flutter view');
-      await new Future<Null>.delayed(new Duration(seconds: attemptSeconds));
+      await Future<Null>.delayed(Duration(seconds: attemptSeconds));
       await getVM();
       await vm.refreshViews();
     }
@@ -425,25 +425,25 @@
       return null;
 
     if (!_isServiceMap(map))
-      throw new VMServiceObjectLoadError('Expected a service map', map);
+      throw VMServiceObjectLoadError('Expected a service map', map);
 
     final String type = _stripRef(map['type']);
 
     ServiceObject serviceObject;
     switch (type) {
       case 'Event':
-        serviceObject = new ServiceEvent._empty(owner);
+        serviceObject = ServiceEvent._empty(owner);
       break;
       case 'FlutterView':
-        serviceObject = new FlutterView._empty(owner.vm);
+        serviceObject = FlutterView._empty(owner.vm);
       break;
       case 'Isolate':
-        serviceObject = new Isolate._empty(owner.vm);
+        serviceObject = Isolate._empty(owner.vm);
       break;
     }
     // If we don't have a model object for this service object type, as a
     // fallback return a ServiceMap object.
-    serviceObject ??= new ServiceMap._empty(owner);
+    serviceObject ??= ServiceMap._empty(owner);
     // We have now constructed an empty service object, call update to populate it.
     serviceObject.updateFromMap(map);
     return serviceObject;
@@ -511,14 +511,14 @@
     }
 
     if (_inProgressReload == null) {
-      final Completer<ServiceObject> completer = new Completer<ServiceObject>();
+      final Completer<ServiceObject> completer = Completer<ServiceObject>();
       _inProgressReload = completer.future;
 
       try {
         final Map<String, dynamic> response = await _fetchDirect();
         if (_stripRef(response['type']) == 'Sentinel') {
           // An object may have been collected.
-          completer.complete(new ServiceObject._fromMap(owner, response));
+          completer.complete(ServiceObject._fromMap(owner, response));
         } else {
           updateFromMap(response);
           completer.complete(this);
@@ -540,7 +540,7 @@
     final String mapType = _stripRef(map['type']);
 
     if ((_type != null) && (_type != mapType)) {
-      throw new VMServiceObjectLoadError('ServiceObject types must not change',
+      throw VMServiceObjectLoadError('ServiceObject types must not change',
                                          map);
     }
     _type = mapType;
@@ -548,7 +548,7 @@
 
     _canCache = map['fixedId'] == true;
     if ((_id != null) && (_id != map['id']) && _canCache) {
-      throw new VMServiceObjectLoadError('ServiceObject id changed', map);
+      throw VMServiceObjectLoadError('ServiceObject id changed', map);
     }
     _id = map['id'];
 
@@ -614,7 +614,7 @@
     _kind = map['kind'];
     assert(map['isolate'] == null || owner == map['isolate']);
     _timestamp =
-        new DateTime.fromMillisecondsSinceEpoch(map['timestamp']);
+        DateTime.fromMillisecondsSinceEpoch(map['timestamp']);
     if (map['extensionKind'] != null) {
       _extensionKind = map['extensionKind'];
       _extensionData = map['extensionData'];
@@ -747,7 +747,7 @@
 
   void _removeDeadIsolates(List<Isolate> newIsolates) {
     // Build a set of new isolates.
-    final Set<String> newIsolateSet = new Set<String>();
+    final Set<String> newIsolateSet = Set<String>();
     for (Isolate iso in newIsolates)
       newIsolateSet.add(iso.id);
 
@@ -782,7 +782,7 @@
         Isolate isolate = _isolateCache[mapId];
         if (isolate == null) {
           // Add new isolate to the cache.
-          isolate = new ServiceObject._fromMap(this, map);
+          isolate = ServiceObject._fromMap(this, map);
           _isolateCache[mapId] = isolate;
           _buildIsolateList();
 
@@ -801,7 +801,7 @@
         FlutterView view = _viewCache[mapId];
         if (view == null) {
           // Add new view to the cache.
-          view = new ServiceObject._fromMap(this, map);
+          view = ServiceObject._fromMap(this, map);
           _viewCache[mapId] = view;
         } else {
           view.updateFromMap(map);
@@ -810,7 +810,7 @@
       }
       break;
       default:
-        throw new VMServiceObjectLoadError(
+        throw VMServiceObjectLoadError(
             'VM.getFromMap called for something other than an isolate', map);
     }
   }
@@ -821,7 +821,7 @@
       // Trigger a VM load, then get the isolate. Ignore any errors.
       return load().then<Isolate>((ServiceObject serviceObject) => getIsolate(isolateId)).catchError((dynamic error) => null);
     }
-    return new Future<Isolate>.value(_isolateCache[isolateId]);
+    return Future<Isolate>.value(_isolateCache[isolateId]);
   }
 
   /// Invoke the RPC and return the raw response.
@@ -845,7 +845,7 @@
     } on TimeoutException {
       printTrace('Request to Dart VM Service timed out: $method($params)');
       if (timeoutFatal)
-        throw new TimeoutException('Request to Dart VM Service timed out: $method($params)');
+        throw TimeoutException('Request to Dart VM Service timed out: $method($params)');
       return null;
     } on WebSocketChannelException catch (error) {
       throwToolExit('Error connecting to observatory: $error');
@@ -867,7 +867,7 @@
       params: params,
       timeout: timeout,
     );
-    final ServiceObject serviceObject = new ServiceObject._fromMap(this, response);
+    final ServiceObject serviceObject = ServiceObject._fromMap(this, response);
     if ((serviceObject != null) && (serviceObject._canCache)) {
       final String serviceObjectId = serviceObject.id;
       _cache.putIfAbsent(serviceObjectId, () => serviceObject);
@@ -1000,13 +1000,13 @@
     final double mcs = _totalCollectionTimeInSeconds *
       Duration.microsecondsPerSecond /
       math.max(_collections, 1);
-    return new Duration(microseconds: mcs.ceil());
+    return Duration(microseconds: mcs.ceil());
   }
 
   Duration get avgCollectionPeriod {
     final double mcs = _averageCollectionPeriodInMillis *
                        Duration.microsecondsPerMillisecond;
-    return new Duration(microseconds: mcs.ceil());
+    return Duration(microseconds: mcs.ceil());
   }
 
   @override
@@ -1083,7 +1083,7 @@
       return serviceObject;
     }
     // Build the object from the map directly.
-    serviceObject = new ServiceObject._fromMap(this, map);
+    serviceObject = ServiceObject._fromMap(this, map);
     if ((serviceObject != null) && serviceObject.canCache)
       _cache[mapId] = serviceObject;
     return serviceObject;
@@ -1117,9 +1117,9 @@
   }
 
   void _updateHeaps(Map<String, dynamic> map, bool mapIsRef) {
-    _newSpace ??= new HeapSpace._empty(this);
+    _newSpace ??= HeapSpace._empty(this);
     _newSpace._update(map['new'], mapIsRef);
-    _oldSpace ??= new HeapSpace._empty(this);
+    _oldSpace ??= HeapSpace._empty(this);
     _oldSpace._update(map['old'], mapIsRef);
   }
 
@@ -1130,7 +1130,7 @@
     _loaded = true;
 
     final int startTimeMillis = map['startTime'];
-    startTime = new DateTime.fromMillisecondsSinceEpoch(startTimeMillis);
+    startTime = DateTime.fromMillisecondsSinceEpoch(startTimeMillis);
 
     _upgradeCollection(map, this);
 
@@ -1158,7 +1158,7 @@
       final Map<String, dynamic> response = await invokeRpcRaw('_reloadSources', params: arguments);
       return response;
     } on rpc.RpcException catch (e) {
-      return new Future<Map<String, dynamic>>.error(<String, dynamic>{
+      return Future<Map<String, dynamic>>.error(<String, dynamic>{
         'code': e.code,
         'message': e.message,
         'data': e.data,
@@ -1199,11 +1199,11 @@
       for (int i = 1; i < lineTuple.length; i += 2) {
         if (lineTuple[i] == tokenPos) {
           final int column = lineTuple[i + 1];
-          return new ProgramElement(name, uri, line, column);
+          return ProgramElement(name, uri, line, column);
         }
       }
     }
-    return new ProgramElement(name, uri);
+    return ProgramElement(name, uri);
   }
 
   // Lists program elements changed in the most recent reload that have not
@@ -1425,7 +1425,7 @@
                              Uri assetsDirectoryUri) async {
     final String viewId = id;
     // When this completer completes the isolate is running.
-    final Completer<Null> completer = new Completer<Null>();
+    final Completer<Null> completer = Completer<Null>();
     final StreamSubscription<ServiceEvent> subscription =
       (await owner.vm.vmService.onIsolateEvent).listen((ServiceEvent event) {
       // TODO(johnmccutchan): Listen to the debug stream and catch initial