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 <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
1469f984fc
commit
ad498f34dc
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<void> {
|
||||
/// [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<void> compute(String rootPath, {@required bool verbose}) async {
|
||||
Future<void> 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<void> _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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user