[dart2js] Migrate some files in dart2js_info/bin to nnbd.

Change-Id: I35d902b177e4ce6812803c9e8c6f07dbfc3935e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/248164
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
diff --git a/pkg/dart2js_info/bin/src/code_deps.dart b/pkg/dart2js_info/bin/src/code_deps.dart
index 5a57686..d11a043 100644
--- a/pkg/dart2js_info/bin/src/code_deps.dart
+++ b/pkg/dart2js_info/bin/src/code_deps.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.11
-
 /// Command to query for code dependencies. Currently this tool only
 /// supports the `some_path` query, which gives you the shortest path for how
 /// one function depends on another.
@@ -30,6 +28,7 @@
 import 'dart:collection';
 
 import 'package:args/command_runner.dart';
+import 'package:collection/collection.dart';
 
 import 'package:dart2js_info/info.dart';
 import 'package:dart2js_info/src/graph.dart';
@@ -57,7 +56,7 @@
 
   @override
   void run() async {
-    var args = argResults.rest;
+    var args = argResults!.rest;
     if (args.length < 3) {
       usageException("Missing arguments for some_path, expected: "
           "info.data <element-regexp-1> <element-regexp-2>");
@@ -66,10 +65,10 @@
     var info = await infoFromFile(args.first);
     var graph = graphFromInfo(info);
 
-    var source = info.functions
-        .firstWhere(_longNameMatcher(RegExp(args[1])), orElse: () => null);
-    var target = info.functions
-        .firstWhere(_longNameMatcher(RegExp(args[2])), orElse: () => null);
+    final source =
+        info.functions.firstWhereOrNull(_longNameMatcher(RegExp(args[1])));
+    final target =
+        info.functions.firstWhereOrNull(_longNameMatcher(RegExp(args[2])));
     print('query: some_path');
     if (source == null) {
       usageException("source '${args[1]}' not found in '${args[0]}'");
@@ -106,9 +105,9 @@
 
   SomePathQuery(this.source, this.target);
 
-  List<Info> run(Graph<Info> graph) {
-    var seen = <Info, Info>{source: null};
-    var queue = Queue<Info>();
+  List<Info> run(Graph<Info?> graph) {
+    var seen = <Info?, Info?>{source: null};
+    var queue = Queue<Info?>();
     queue.addLast(source);
     while (queue.isNotEmpty) {
       var node = queue.removeFirst();
diff --git a/pkg/dart2js_info/bin/src/common_command.dart b/pkg/dart2js_info/bin/src/common_command.dart
index e8cba55..8e2aa48 100644
--- a/pkg/dart2js_info/bin/src/common_command.dart
+++ b/pkg/dart2js_info/bin/src/common_command.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.11
-
 import 'package:args/command_runner.dart';
 
 import 'package:dart2js_info/info.dart';
@@ -33,7 +31,8 @@
 
   @override
   void run() async {
-    var args = argResults.rest;
+    final argRes = argResults!;
+    final args = argRes.rest;
     if (args.length < 2) {
       usageException(
           'Missing arguments, expected two dump-info files to compare');
@@ -41,8 +40,8 @@
 
     var oldInfo = await infoFromFile(args[0]);
     var newInfo = await infoFromFile(args[1]);
-    var packagesOnly = argResults['packages-only'];
-    var orderBySize = argResults['order-by-size'];
+    var packagesOnly = argRes['packages-only'];
+    var orderBySize = argRes['order-by-size'];
 
     var commonElements = findCommonalities(oldInfo, newInfo);
 
@@ -112,7 +111,7 @@
 
   var oldSizeTotal = 0, newSizeTotal = 0;
   oldPackageInfo.forEach((oldPackageName, oldPackageSize) {
-    var newPackageSize = newPackageInfo[oldPackageName];
+    var newPackageSize = newPackageInfo[oldPackageName]!;
     oldSizeTotal += oldPackageSize;
     newSizeTotal += newPackageSize;
   });
@@ -142,7 +141,9 @@
 }
 
 void _section(String title,
-    {int elementCount, int oldSizeTotal, int newSizeTotal}) {
+    {required int elementCount,
+    required int oldSizeTotal,
+    required int newSizeTotal}) {
   if (oldSizeTotal == newSizeTotal) {
     print('$title ($elementCount common elements, $oldSizeTotal bytes)');
   } else {
diff --git a/pkg/dart2js_info/bin/src/coverage_log_server.dart b/pkg/dart2js_info/bin/src/coverage_log_server.dart
index 375731a..683a935 100644
--- a/pkg/dart2js_info/bin/src/coverage_log_server.dart
+++ b/pkg/dart2js_info/bin/src/coverage_log_server.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.11
-
 /// A tool to gather coverage data from an app generated with dart2js. This
 /// depends on code that has been landed in the bleeding_edge version of dart2js
 /// and that we expect to become publicly visible in version 0.13.0 of the Dart
@@ -55,19 +53,20 @@
 
   @override
   void run() async {
-    if (argResults.rest.isEmpty) {
+    final args = argResults!;
+    if (args.rest.isEmpty) {
       usageException('Missing arguments: <dart2js-out-file> [<html-file>]');
     }
 
-    var jsPath = argResults.rest[0];
-    String htmlPath;
-    if (argResults.rest.length > 1) {
-      htmlPath = argResults.rest[1];
+    var jsPath = args.rest[0];
+    String? htmlPath;
+    if (args.rest.length > 1) {
+      htmlPath = args.rest[1];
     }
-    var outPath = argResults['out'];
+    var outPath = args['out'];
     if (outPath == _defaultOutTemplate) outPath = '$jsPath.coverage.json';
-    var server = _Server(argResults['host'], int.parse(argResults['port']),
-        jsPath, htmlPath, outPath, argResults['uri-prefix']);
+    var server = _Server(args['host'], int.parse(args['port']), jsPath,
+        htmlPath, outPath, args['uri-prefix']);
     await server.run();
   }
 }
@@ -85,7 +84,7 @@
   final String jsPath;
 
   /// HTML file to serve, if any.
-  final String htmlPath;
+  final String? htmlPath;
 
   /// Contents of jsPath, adjusted to use the appropriate server url.
   String jsCode;
@@ -115,7 +114,7 @@
   run() async {
     await shelf.serve(_handler, hostname, port);
     var urlBase = "http://$hostname:$port${prefix == '' ? '/' : '/$prefix/'}";
-    var htmlFilename = htmlPath == null ? '' : path.basename(htmlPath);
+    var htmlFilename = htmlPath == null ? '' : path.basename(htmlPath!);
     print("Server is listening\n"
         "  - html page: $urlBase$htmlFilename\n"
         "  - js code: $urlBase${path.basename(jsPath)}\n"
@@ -128,7 +127,7 @@
     var urlPath = request.url.path;
     print('received request: $urlPath');
     var baseJsName = path.basename(jsPath);
-    var baseHtmlName = htmlPath == null ? '' : path.basename(htmlPath);
+    var baseHtmlName = htmlPath == null ? '' : path.basename(htmlPath!);
 
     // Serve an HTML file at the default prefix, or a path matching the HTML
     // file name
@@ -137,7 +136,7 @@
         urlPath == _expectedPath(baseHtmlName)) {
       var contents = htmlPath == null
           ? '<html><script src="$baseJsName"></script>'
-          : await File(htmlPath).readAsString();
+          : await File(htmlPath!).readAsString();
       return shelf.Response.ok(contents, headers: _htmlHeaders);
     }
 
diff --git a/pkg/dart2js_info/bin/src/deferred_library_check.dart b/pkg/dart2js_info/bin/src/deferred_library_check.dart
index 2aba53c..ce3da3c 100644
--- a/pkg/dart2js_info/bin/src/deferred_library_check.dart
+++ b/pkg/dart2js_info/bin/src/deferred_library_check.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.11
-
 /// A command that verifies that deferred libraries split the code as expected.
 ///
 /// This tool checks that the output from dart2js meets a given specification,
@@ -57,7 +55,7 @@
 
   @override
   void run() async {
-    var args = argResults.rest;
+    var args = argResults!.rest;
     if (args.length < 2) {
       usageException('Missing arguments, expected: info.data manifest.yaml');
     }
diff --git a/pkg/dart2js_info/bin/src/show_inferred_types.dart b/pkg/dart2js_info/bin/src/show_inferred_types.dart
index 7c43318..417d839 100644
--- a/pkg/dart2js_info/bin/src/show_inferred_types.dart
+++ b/pkg/dart2js_info/bin/src/show_inferred_types.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.11
-
 /// Simple script that shows the inferred types of a function.
 library compiler.tool.show_inferred_types;
 
@@ -29,12 +27,13 @@
 
   @override
   void run() async {
-    var args = argResults.rest;
+    final argRes = argResults!;
+    var args = argRes.rest;
     if (args.length < 2) {
       usageException(
           'Missing arguments, expected: info.data <function-name-regex>');
     }
-    _showInferredTypes(args[0], args[1], argResults['long-names']);
+    _showInferredTypes(args[0], args[1], argRes['long-names']);
   }
 }
 
diff --git a/pkg/dart2js_info/lib/src/io.dart b/pkg/dart2js_info/lib/src/io.dart
index f006e87..a80da7c 100644
--- a/pkg/dart2js_info/lib/src/io.dart
+++ b/pkg/dart2js_info/lib/src/io.dart
@@ -1,4 +1,6 @@
-// @dart = 2.11
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
 
 import 'dart:convert';
 import 'dart:io';