diff --git a/packages/flutter_tools/lib/src/dart/analysis.dart b/packages/flutter_tools/lib/src/dart/analysis.dart index 66752b2c4e..dd717fd632 100644 --- a/packages/flutter_tools/lib/src/dart/analysis.dart +++ b/packages/flutter_tools/lib/src/dart/analysis.dart @@ -2,12 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'dart:math' as math; -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import '../base/common.dart'; @@ -24,12 +21,12 @@ class AnalysisServer { AnalysisServer( this.sdkPath, this.directories, { - @required FileSystem fileSystem, - @required ProcessManager processManager, - @required Logger logger, - @required Platform platform, - @required Terminal terminal, - String protocolTrafficLog, + required FileSystem fileSystem, + required ProcessManager processManager, + required Logger logger, + required Platform platform, + required Terminal terminal, + String? protocolTrafficLog, }) : _fileSystem = fileSystem, _processManager = processManager, _logger = logger, @@ -44,9 +41,9 @@ class AnalysisServer { final Logger _logger; final Platform _platform; final Terminal _terminal; - final String _protocolTrafficLog; + final String? _protocolTrafficLog; - Process _process; + Process? _process; final StreamController _analyzingController = StreamController.broadcast(); final StreamController _errorsController = @@ -77,14 +74,14 @@ class AnalysisServer { _logger.printTrace('dart ${command.skip(1).join(' ')}'); _process = await _processManager.start(command); // This callback hookup can't throw. - unawaited(_process.exitCode.whenComplete(() => _process = null)); + unawaited(_process!.exitCode.whenComplete(() => _process = null)); - final Stream errorStream = _process.stderr + final Stream errorStream = _process!.stderr .transform(utf8.decoder) .transform(const LineSplitter()); errorStream.listen(_logger.printError); - final Stream inStream = _process.stdout + final Stream inStream = _process!.stdout .transform(utf8.decoder) .transform(const LineSplitter()); inStream.listen(_handleServerResponse); @@ -103,7 +100,7 @@ class AnalysisServer { Stream get onErrors => _errorsController.stream; - Future get onExit => _process.exitCode; + Future get onExit async => _process?.exitCode; void _sendCommand(String method, Map params) { final String message = json.encode({ @@ -111,7 +108,7 @@ class AnalysisServer { 'method': method, 'params': params, }); - _process.stdin.writeln(message); + _process?.stdin.writeln(message); _logger.printTrace('==> $message'); } @@ -124,19 +121,23 @@ class AnalysisServer { if (response['event'] != null) { final String event = response['event'] as String; final dynamic params = response['params']; - + Map? paramsMap; if (params is Map) { + paramsMap = castStringKeyedMap(params); + } + + if (paramsMap != null) { if (event == 'server.status') { - _handleStatus(castStringKeyedMap(response['params'])); + _handleStatus(paramsMap); } else if (event == 'analysis.errors') { - _handleAnalysisIssues(castStringKeyedMap(response['params'])); + _handleAnalysisIssues(paramsMap); } else if (event == 'server.error') { - _handleServerError(castStringKeyedMap(response['params'])); + _handleServerError(paramsMap); } } } else if (response['error'] != null) { // Fields are 'code', 'message', and 'stackTrace'. - final Map error = castStringKeyedMap(response['error']); + final Map error = castStringKeyedMap(response['error']!)!; _logger.printError( 'Error response from the server: ${error['code']} ${error['message']}'); if (error['stackTrace'] != null) { @@ -168,7 +169,7 @@ class AnalysisServer { final String file = issueInfo['file'] as String; final List errorsList = issueInfo['errors'] as List; final List errors = errorsList - .map>(castStringKeyedMap) + .map>((dynamic e) => castStringKeyedMap(e) ?? {}) .map((Map json) { return AnalysisError(WrittenError.fromJson(json), fileSystem: _fileSystem, @@ -182,7 +183,7 @@ class AnalysisServer { } } - Future dispose() async { + Future dispose() async { await _analyzingController.close(); await _errorsController.close(); return _process?.kill(); @@ -200,9 +201,9 @@ enum AnalysisSeverity { class AnalysisError implements Comparable { AnalysisError( this.writtenError, { - @required Platform platform, - @required Terminal terminal, - @required FileSystem fileSystem, + required Platform platform, + required Terminal terminal, + required FileSystem fileSystem, }) : _platform = platform, _terminal = terminal, _fileSystem = fileSystem; @@ -224,7 +225,6 @@ class AnalysisError implements Comparable { case AnalysisSeverity.none: return writtenError.severity; } - return null; } String get type => writtenError.type; @@ -269,14 +269,14 @@ class AnalysisError implements Comparable { /// [AnalysisError] in plain text content. class WrittenError { WrittenError._({ - @required this.severity, - @required this.type, - @required this.message, - @required this.code, - @required this.file, - @required this.startLine, - @required this.startColumn, - @required this.offset, + required this.severity, + required this.type, + required this.message, + required this.code, + required this.file, + required this.startLine, + required this.startColumn, + required this.offset, }); /// {