[flutter_tool] Use curly braces around single statment control structures (#40446)
diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index d095b3e..a5af8de 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart
@@ -72,15 +72,17 @@ printTrace('Exception attempting to connect to Observatory: $e'); printTrace('This was attempt #$attempts. Will retry in $delay.'); - if (attempts == 10) + if (attempts == 10) { printStatus('This is taking longer than expected...'); + } // Delay next attempt. await Future<void>.delayed(delay); // Back off exponentially, up to 1600ms per attempt. - if (delay < const Duration(seconds: 1)) + if (delay < const Duration(seconds: 1)) { delay *= 2; + } } final WebSocketConnector constructor = context.get<WebSocketConnector>() ?? io.WebSocket.connect; @@ -121,12 +123,15 @@ final bool force = params.asMap['force'] ?? false; final bool pause = params.asMap['pause'] ?? false; - if (isolateId is! String || isolateId.isEmpty) + if (isolateId is! String || isolateId.isEmpty) { throw rpc.RpcException.invalidParams('Invalid \'isolateId\': $isolateId'); - if (force is! bool) + } + if (force is! bool) { throw rpc.RpcException.invalidParams('Invalid \'force\': $force'); - if (pause is! bool) + } + if (pause is! bool) { throw rpc.RpcException.invalidParams('Invalid \'pause\': $pause'); + } try { await reloadSources(isolateId, force: force, pause: pause); @@ -149,8 +154,9 @@ _peer.registerMethod('hotRestart', (rpc.Parameters params) async { final bool pause = params.asMap['pause'] ?? false; - if (pause is! bool) + if (pause is! bool) { throw rpc.RpcException.invalidParams('Invalid \'pause\': $pause'); + } try { await restart(pause: pause); @@ -185,13 +191,15 @@ if (compileExpression != null) { _peer.registerMethod('compileExpression', (rpc.Parameters params) async { final String isolateId = params['isolateId'].asString; - if (isolateId is! String || isolateId.isEmpty) + if (isolateId is! String || isolateId.isEmpty) { throw rpc.RpcException.invalidParams( 'Invalid \'isolateId\': $isolateId'); + } final String expression = params['expression'].asString; - if (expression is! String || expression.isEmpty) + if (expression is! String || expression.isEmpty) { throw rpc.RpcException.invalidParams( 'Invalid \'expression\': $expression'); + } final List<String> definitions = List<String>.from(params['definitions'].asList); final List<String> typeDefinitions = @@ -399,8 +407,9 @@ dynamic collection, ServiceObjectOwner owner, ) { - if (collection is ServiceMap) + if (collection is ServiceMap) { return; + } if (collection is Map<String, dynamic>) { _upgradeMap(collection, owner); } else if (collection is List) { @@ -444,11 +453,13 @@ ServiceObjectOwner owner, Map<String, dynamic> map, ) { - if (map == null) + if (map == null) { return null; + } - if (!_isServiceMap(map)) + if (!_isServiceMap(map)) { throw VMServiceObjectLoadError('Expected a service map', map); + } final String type = _stripRef(map['type']); @@ -506,8 +517,9 @@ /// If this is not already loaded, load it. Otherwise reload. Future<ServiceObject> load() async { - if (loaded) + if (loaded) { return this; + } return reload(); } @@ -527,8 +539,9 @@ // We should always reload the VM. // We can't reload objects without an id. // We shouldn't reload an immutable and already loaded object. - if (!isVM && (!hasId || (immutable && loaded))) + if (!isVM && (!hasId || (immutable && loaded))) { return this; + } if (_inProgressReload == null) { final Completer<ServiceObject> completer = Completer<ServiceObject>(); @@ -695,8 +708,9 @@ @override void _update(Map<String, dynamic> map, bool mapIsRef) { - if (mapIsRef) + if (mapIsRef) { return; + } // Upgrade the collection. A side effect of this call is that any new // isolates in the map are created and added to the isolate cache. @@ -704,8 +718,9 @@ _loaded = true; _pid = map['pid']; - if (map['_heapAllocatedMemoryUsage'] != null) + if (map['_heapAllocatedMemoryUsage'] != null) { _heapAllocatedMemoryUsage = map['_heapAllocatedMemoryUsage']; + } _maxRSS = map['_maxRSS']; _embedder = map['_embedder']; @@ -766,8 +781,9 @@ void _removeDeadIsolates(List<Isolate> newIsolates) { // Build a set of new isolates. final Set<String> newIsolateSet = <String>{}; - for (Isolate iso in newIsolates) + for (Isolate iso in newIsolates) { newIsolateSet.add(iso.id); + } // Remove any old isolates which no longer exist. final List<String> toRemove = <String>[]; @@ -844,8 +860,9 @@ static String _truncate(String message, int width, String ellipsis) { assert(ellipsis.length < width); - if (message.length <= width) + if (message.length <= width) { return message; + } return message.substring(0, width - ellipsis.length) + ellipsis; } @@ -978,8 +995,9 @@ Future<void> refreshViews({ bool waitForViews = false }) async { assert(waitForViews != null); assert(loaded); - if (!isFlutterEngine) + if (!isFlutterEngine) { return; + } int failCount = 0; while (true) { _viewCache.clear(); @@ -988,11 +1006,13 @@ // This message updates all the views of every isolate. await vmService.vm.invokeRpc<ServiceObject>( '_flutter.listViews', truncateLogs: false); - if (_viewCache.values.isNotEmpty || !waitForViews) + if (_viewCache.values.isNotEmpty || !waitForViews) { return; + } failCount += 1; - if (failCount == 5) // waited 200ms + if (failCount == 5) { // waited 200ms printStatus('Flutter is taking longer than expected to report its views. Still trying...'); + } await Future<void>.delayed(const Duration(milliseconds: 50)); await reload(); } @@ -1005,8 +1025,9 @@ } List<FlutterView> allViewsWithName(String isolateFilter) { - if (_viewCache.values.isEmpty) + if (_viewCache.values.isEmpty) { return null; + } return _viewCache.values.where( (FlutterView v) => v.uiIsolate.name.contains(isolateFilter) ).toList(); @@ -1081,8 +1102,9 @@ @override ServiceObject getFromMap(Map<String, dynamic> map) { - if (map == null) + if (map == null) { return null; + } final String mapType = _stripRef(map['type']); if (mapType == 'Isolate') { // There are sometimes isolate refs in ServiceEvents. @@ -1097,8 +1119,9 @@ } // Build the object from the map directly. serviceObject = ServiceObject._fromMap(this, map); - if ((serviceObject != null) && serviceObject.canCache) + if ((serviceObject != null) && serviceObject.canCache) { _cache[mapId] = serviceObject; + } return serviceObject; } @@ -1135,8 +1158,9 @@ @override void _update(Map<String, dynamic> map, bool mapIsRef) { - if (mapIsRef) + if (mapIsRef) { return; + } _loaded = true; final int startTimeMillis = map['startTime']; @@ -1199,8 +1223,9 @@ return await invokeRpcRaw(method, params: params); } on rpc.RpcException catch (e) { // If an application is not using the framework - if (e.code == rpc_error_code.METHOD_NOT_FOUND) + if (e.code == rpc_error_code.METHOD_NOT_FOUND) { return null; + } rethrow; } } @@ -1279,8 +1304,9 @@ Future<List<int>> flutterDebugSaveCompilationTrace() async { final Map<String, dynamic> result = await invokeFlutterExtensionRpcRaw('ext.flutter.saveCompilationTrace'); - if (result != null && result['value'] is List<dynamic>) + if (result != null && result['value'] is List<dynamic>) { return result['value'].cast<int>(); + } return null; } @@ -1294,8 +1320,9 @@ 'ext.flutter.platformOverride', params: platform != null ? <String, dynamic>{'value': platform} : <String, String>{}, ); - if (result != null && result['value'] is String) + if (result != null && result['value'] is String) { return result['value']; + } return 'unknown'; } @@ -1393,8 +1420,9 @@ // launch errors. if (event.kind == ServiceEvent.kIsolateRunnable) { printTrace('Isolate is runnable.'); - if (!completer.isCompleted) + if (!completer.isCompleted) { completer.complete(); + } } }); await owner.vm.runInView(viewId,