From ad498f34dc6527ff82f49700a75715f4fac31601 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 6 Apr 2021 22:58:53 +0000 Subject: [PATCH] Migrate a few test/tool/completion_metrics/ libraries. R=brianwilkerson@google.com Change-Id: I8221b0c2f97ada211b101d31420e60062f30887d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194115 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- .../completion_metrics/metrics_util_test.dart | 4 ---- .../tool/completion_metrics/test_all.dart | 2 -- .../implicit_type_declarations.dart | 23 +++++-------------- .../tool/code_completion/metrics_util.dart | 14 +++++------ 4 files changed, 12 insertions(+), 31 deletions(-) diff --git a/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart b/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart index 9b0865df599..8c83b04cf29 100644 --- a/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart +++ b/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.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.9 - import 'package:test/test.dart'; import '../../../tool/code_completion/metrics_util.dart'; @@ -172,8 +170,6 @@ class _DoubleEquals extends Matcher { @override bool matches(item, Map matchState) { return item is num && - item != null && - _value != null && num.parse(item.toStringAsFixed(fractionDigits)) == num.parse(_value.toStringAsFixed(fractionDigits)); } diff --git a/pkg/analysis_server/test/tool/completion_metrics/test_all.dart b/pkg/analysis_server/test/tool/completion_metrics/test_all.dart index 2a7e8b3d716..8ca30d96a48 100644 --- a/pkg/analysis_server/test/tool/completion_metrics/test_all.dart +++ b/pkg/analysis_server/test/tool/completion_metrics/test_all.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.9 - import 'package:test_reflective_loader/test_reflective_loader.dart'; import 'metrics_util_test.dart' as metrics_util_test; diff --git a/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart b/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart index 3204eebb00f..baa7300622f 100644 --- a/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart +++ b/pkg/analysis_server/tool/code_completion/implicit_type_declarations.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.9 - import 'dart:io' as io; import 'package:analysis_server/src/status/pages.dart'; @@ -17,7 +15,6 @@ import 'package:analyzer/diagnostic/diagnostic.dart'; import 'package:analyzer/file_system/physical_file_system.dart'; import 'package:analyzer/src/util/file_paths.dart' as file_paths; import 'package:args/args.dart'; -import 'package:meta/meta.dart'; /// Compute metrics to determine which untyped variable declarations can be used /// to imply an expected context type, i.e. the RHS of 'var string = ^' could be @@ -63,7 +60,7 @@ ArgParser createArgParser() { } /// Print usage information for this tool. -void printUsage(ArgParser parser, {String error}) { +void printUsage(ArgParser parser, {String? error}) { if (error != null) { print(error); print(''); @@ -104,7 +101,7 @@ class ImpliedTypeCollector extends RecursiveAstVisitor { /// [data]. ImpliedTypeCollector(this.data); - void handleVariableDeclaration(VariableDeclaration node, DartType dartType) { + void handleVariableDeclaration(VariableDeclaration node, DartType? dartType) { // If some untyped variable declaration if (node.equals != null && dartType == null || (dartType != null && (dartType.isDynamic || dartType.isVoid))) { @@ -141,7 +138,7 @@ class ImpliedTypeComputer { /// Compute the metrics for the file(s) in the [rootPath]. /// If [corpus] is true, treat rootPath as a container of packages, creating /// a new context collection for each subdirectory. - Future compute(String rootPath, {@required bool verbose}) async { + Future compute(String rootPath, {required bool verbose}) async { final collection = AnalysisContextCollection( includedPaths: [rootPath], resourceProvider: PhysicalResourceProvider.INSTANCE, @@ -174,7 +171,7 @@ class ImpliedTypeComputer { /// output if [verbose] is `true`. Future _computeInContext( ContextRoot root, ImpliedTypeCollector collector, - {@required bool verbose}) async { + {required bool verbose}) async { // Create a new collection to avoid consuming large quantities of memory. final collection = AnalysisContextCollection( includedPaths: root.includedPaths.toList(), @@ -191,13 +188,7 @@ class ImpliedTypeComputer { // // Check for errors that cause the file to be skipped. // - if (resolvedUnitResult == null) { - print('File $filePath skipped because resolved unit was null.'); - if (verbose) { - print(''); - } - continue; - } else if (resolvedUnitResult.state != ResultState.VALID) { + if (resolvedUnitResult.state != ResultState.VALID) { print('File $filePath skipped because it could not be analyzed.'); if (verbose) { print(''); @@ -217,7 +208,7 @@ class ImpliedTypeComputer { continue; } - resolvedUnitResult.unit.accept(collector); + resolvedUnitResult.unit!.accept(collector); } catch (exception, stacktrace) { print('Exception caught analyzing: "$filePath"'); print(exception); @@ -243,8 +234,6 @@ class ImpliedTypeData { /// Record the variable name with the type. void recordImpliedType(String name, String displayString) { - assert(name != null); - assert(displayString != null); var nameMap = impliedTypesMap.putIfAbsent(name, () => {}); nameMap[displayString] = (nameMap[displayString] ?? 0) + 1; } diff --git a/pkg/analysis_server/tool/code_completion/metrics_util.dart b/pkg/analysis_server/tool/code_completion/metrics_util.dart index 47671f0241a..00364e90a27 100644 --- a/pkg/analysis_server/tool/code_completion/metrics_util.dart +++ b/pkg/analysis_server/tool/code_completion/metrics_util.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.9 - import 'package:analysis_server/src/status/pages.dart'; import 'package:analyzer/src/generated/utilities_general.dart'; @@ -96,12 +94,12 @@ class Counter { } void count(String id, [int countNumber = 1]) { - assert(id != null && id.isNotEmpty && 1 <= countNumber); - if (_buckets.containsKey(id)) { - _buckets[id] += countNumber; - } else { - _buckets.putIfAbsent(id, () => countNumber); - } + assert(id.isNotEmpty && 1 <= countNumber); + _buckets.update( + id, + (value) => value + countNumber, + ifAbsent: () => countNumber, + ); _totalCount += countNumber; }