analysis_server: Prefer type annotations over raw types in benchmark/, tool/

Change-Id: I2f0c8bfd484f5aee46395fa86cd3cfabda7c0148
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286204
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/analysis_options.yaml b/pkg/analysis_server/analysis_options.yaml
index c3d96c6..c9d601a 100644
--- a/pkg/analysis_server/analysis_options.yaml
+++ b/pkg/analysis_server/analysis_options.yaml
@@ -3,6 +3,8 @@
 analyzer:
   language:
     strict-casts: true
+    # TODO(srawlins): Enable this; there are currently ~250 violations.
+    # strict-raw-types: true
   exclude:
     - test/mock_packages/**
   errors:
diff --git a/pkg/analysis_server/benchmark/benchmarks.dart b/pkg/analysis_server/benchmark/benchmarks.dart
index 9d4aed2..fe4d21b 100644
--- a/pkg/analysis_server/benchmark/benchmarks.dart
+++ b/pkg/analysis_server/benchmark/benchmarks.dart
@@ -20,7 +20,7 @@
 import 'perf/flutter_analyze_benchmark.dart';
 import 'perf/flutter_completion_benchmark.dart';
 
-Future main(List<String> args) async {
+Future<void> main(List<String> args) async {
   var benchmarks = [
     ColdAnalysisBenchmark(ServerBenchmark.das),
     ColdAnalysisBenchmark(ServerBenchmark.lsp),
@@ -163,7 +163,7 @@
   set flutterRepositoryPath(String path);
 }
 
-class ListCommand extends Command {
+class ListCommand extends Command<void> {
   final List<Benchmark> benchmarks;
 
   ListCommand(this.benchmarks) {
@@ -195,7 +195,7 @@
   }
 }
 
-class RunCommand extends Command {
+class RunCommand extends Command<void> {
   final List<Benchmark> benchmarks;
 
   RunCommand(this.benchmarks) {
@@ -225,7 +225,7 @@
   String get name => 'run';
 
   @override
-  Future run() async {
+  Future<void> run() async {
     var args = argResults;
     if (args == null) {
       throw StateError('argResults have not been set');
diff --git a/pkg/analysis_server/benchmark/integration/input_converter.dart b/pkg/analysis_server/benchmark/integration/input_converter.dart
index fd45405..f0490ec 100644
--- a/pkg/analysis_server/benchmark/integration/input_converter.dart
+++ b/pkg/analysis_server/benchmark/integration/input_converter.dart
@@ -31,7 +31,7 @@
   /// for those requests for which a response has not been processed.
   /// The completer is called with the actual json response
   /// when it becomes available.
-  final Map<String, Completer> responseCompleters = {};
+  final Map<String, Completer<Object?>> responseCompleters = {};
 
   /// A mapping from request/response id to the actual response result
   /// for those responses that have not been processed.
@@ -184,7 +184,8 @@
   /// Return a future that completes when the response is received
   /// or `null` if the response has already been received
   /// and the completer completed.
-  Future<void>? processExpectedResponse(String id, Completer completer) {
+  Future<void>? processExpectedResponse(
+      String id, Completer<Object?> completer) {
     if (responseMap.containsKey(id)) {
       logger.log(Level.INFO, 'processing cached response $id');
       completer.complete(responseMap.remove(id));
diff --git a/pkg/analysis_server/benchmark/integration/operation.dart b/pkg/analysis_server/benchmark/integration/operation.dart
index 569092b..3f45df7 100644
--- a/pkg/analysis_server/benchmark/integration/operation.dart
+++ b/pkg/analysis_server/benchmark/integration/operation.dart
@@ -103,7 +103,7 @@
   final CommonInputConverter converter;
   final Map<String, Object?> requestJson;
   final Map<String, Object?> responseJson;
-  final Completer completer = Completer();
+  final Completer<void> completer = Completer();
   late Driver driver;
 
   ResponseOperation(this.converter, this.requestJson, this.responseJson) {
diff --git a/pkg/analysis_server/benchmark/perf/memory_tests.dart b/pkg/analysis_server/benchmark/perf/memory_tests.dart
index 0877461..903d4a5 100644
--- a/pkg/analysis_server/benchmark/perf/memory_tests.dart
+++ b/pkg/analysis_server/benchmark/perf/memory_tests.dart
@@ -31,8 +31,8 @@
   Future<void> updateFile(String filePath, String contents);
 }
 
-/// An implementation of [AbstractBenchmarkTest] for a original protocol memory
-/// test.
+/// An implementation of [AbstractBenchmarkTest] for an 'original protocol'
+/// memory test.
 class AnalysisServerBenchmarkTest extends AbstractBenchmarkTest {
   final _test = AnalysisServerMemoryUsageTest();
 
@@ -87,12 +87,12 @@
     extends AbstractAnalysisServerIntegrationTest with ServerMemoryUsageMixin {
   /// Send the server an 'analysis.setAnalysisRoots' command directing it to
   /// analyze [sourceDirectory].
-  Future setAnalysisRoot() =>
+  Future<void> setAnalysisRoot() =>
       sendAnalysisSetAnalysisRoots([sourceDirectory.path], []);
 
   /// The server is automatically started before every test.
   @override
-  Future setUp() async {
+  Future<void> setUp() async {
     _vmServicePort = await ServiceProtocol._findAvailableSocketPort();
 
     onAnalysisErrors.listen((AnalysisErrorsParams params) {
@@ -102,7 +102,7 @@
       // A server error should never happen during an integration test.
       fail('${params.message}\n${params.stackTrace}');
     });
-    var serverConnected = Completer();
+    var serverConnected = Completer<void>();
     onServerConnected.listen((_) {
       outOfTestExpect(serverConnected.isCompleted, isFalse);
       serverConnected.complete();
@@ -117,11 +117,11 @@
   }
 
   /// After every test, the server is stopped.
-  Future shutdown() async => await shutdownIfNeeded();
+  Future<void> shutdown() async => await shutdownIfNeeded();
 
   /// Enable [ServerService.STATUS] notifications so that [analysisFinished]
   /// can be used.
-  Future subscribeToStatusNotifications() async {
+  Future<void> subscribeToStatusNotifications() async {
     await sendServerSetSubscriptions([ServerService.STATUS]);
   }
 }
@@ -234,7 +234,7 @@
   }
 
   /// After every test, the server is stopped.
-  Future shutdown() async => this.tearDown();
+  Future<void> shutdown() async => this.tearDown();
 }
 
 mixin ServerMemoryUsageMixin {
@@ -248,10 +248,14 @@
     var total = 0;
 
     var isolateGroupsRefs = vm['isolateGroups'] as List<Object?>;
-    for (var isolateGroupRef in isolateGroupsRefs.cast<Map>()) {
-      final heapUsage = await service.call('getIsolateGroupMemoryUsage',
+    for (var isolateGroupRef
+        in isolateGroupsRefs.cast<Map<Object?, Object?>>()) {
+      final isolateGroupMemoryUsage = await service.call(
+          'getIsolateGroupMemoryUsage',
           {'isolateGroupId': isolateGroupRef['id']});
-      total += heapUsage['heapUsage'] + heapUsage['externalUsage'] as int;
+      var heapUsage = isolateGroupMemoryUsage['heapUsage'] as int;
+      var externalUsage = isolateGroupMemoryUsage['externalUsage'] as int;
+      total += heapUsage + externalUsage;
     }
 
     await service.dispose();
@@ -264,15 +268,16 @@
   final WebSocket socket;
 
   int _id = 0;
-  final Map<String, Completer<Map>> _completers = {};
+  final Map<String, Completer<Map<Object?, Object?>>> _completers = {};
 
   ServiceProtocol._(this.socket) {
     socket.listen(_handleMessage);
   }
 
-  Future<Map> call(String method, [Map args = const {}]) {
+  Future<Map<Object?, Object?>> call(String method,
+      [Map<Object?, Object?> args = const {}]) {
     var id = '${++_id}';
-    var completer = Completer<Map>();
+    var completer = Completer<Map<Object?, Object?>>();
     _completers[id] = completer;
     var messageMap = <String, dynamic>{
       'jsonrpc': '2.0',
diff --git a/pkg/analysis_server/lib/src/channel/byte_stream_channel.dart b/pkg/analysis_server/lib/src/channel/byte_stream_channel.dart
index 1b7cbc3..3e795c4 100644
--- a/pkg/analysis_server/lib/src/channel/byte_stream_channel.dart
+++ b/pkg/analysis_server/lib/src/channel/byte_stream_channel.dart
@@ -56,7 +56,7 @@
   );
 
   @override
-  Future close() {
+  Future<void> close() {
     return output.close();
   }
 
@@ -80,7 +80,7 @@
   final RequestStatisticsHelper? _requestStatistics;
 
   /// Completer that will be signalled when the input stream is closed.
-  final Completer _closed = Completer();
+  final Completer<void> _closed = Completer();
 
   /// True if [close] has been called.
   bool _closeRequested = false;
@@ -103,7 +103,7 @@
   }
 
   /// Future that will be completed when the input stream is closed.
-  Future get closed {
+  Future<void> get closed {
     return _closed.future;
   }
 
diff --git a/pkg/analysis_server/test/tool/lsp_spec/matchers.dart b/pkg/analysis_server/test/tool/lsp_spec/matchers.dart
index 26716a0..a983d09 100644
--- a/pkg/analysis_server/test/tool/lsp_spec/matchers.dart
+++ b/pkg/analysis_server/test/tool/lsp_spec/matchers.dart
@@ -34,8 +34,8 @@
       description.add('an array of ').addDescriptionOf(_elementTypeMatcher);
 
   @override
-  Description describeMismatch(
-      item, Description mismatchDescription, Map matchState, bool verbose) {
+  Description describeMismatch(item, Description mismatchDescription,
+      Map<dynamic, dynamic> matchState, bool verbose) {
     if (item is ArrayType) {
       return _elementTypeMatcher.describeMismatch(
           item, mismatchDescription, matchState, verbose);
@@ -45,7 +45,7 @@
   }
 
   @override
-  bool matches(item, Map matchState) {
+  bool matches(item, Map<dynamic, dynamic> matchState) {
     return item is ArrayType &&
         _elementTypeMatcher.matches(item.elementType, matchState);
   }
@@ -63,7 +63,7 @@
       .add(' and value is $_value');
 
   @override
-  bool matches(item, Map matchState) {
+  bool matches(item, Map<dynamic, dynamic> matchState) {
     return item is LiteralType &&
         _typeMatcher.matches(item.type, matchState) &&
         item.valueAsLiteral == _value;
@@ -82,7 +82,7 @@
       .addDescriptionOf(_valueMatcher);
 
   @override
-  bool matches(item, Map matchState) {
+  bool matches(item, Map<dynamic, dynamic> matchState) {
     return item is MapType &&
         _indexMatcher.matches(item.indexType, matchState) &&
         _valueMatcher.matches(item.valueType, matchState);
@@ -98,8 +98,8 @@
       description.add('a type with the name $_expectedName');
 
   @override
-  Description describeMismatch(
-      item, Description mismatchDescription, Map matchState, bool verbose) {
+  Description describeMismatch(item, Description mismatchDescription,
+      Map<dynamic, dynamic> matchState, bool verbose) {
     if (item is TypeReference) {
       return mismatchDescription
           .add('has the name ')
@@ -110,7 +110,7 @@
   }
 
   @override
-  bool matches(item, Map matchState) {
+  bool matches(item, Map<dynamic, dynamic> matchState) {
     return item is TypeReference && item.name == _expectedName;
   }
 }
diff --git a/pkg/analysis_server/tool/spec/api.dart b/pkg/analysis_server/tool/spec/api.dart
index b0f4555..c430bd7 100644
--- a/pkg/analysis_server/tool/spec/api.dart
+++ b/pkg/analysis_server/tool/spec/api.dart
@@ -63,7 +63,7 @@
 }
 
 /// API visitor that visits the entire API hierarchically by default.
-class HierarchicalApiVisitor extends ApiVisitor {
+class HierarchicalApiVisitor extends ApiVisitor<void> {
   /// The API to visit.
   final Api api;