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>
This commit is contained in:
Sam Rawlins 2023-03-01 20:40:43 +00:00 committed by Commit Queue
parent c1215061e2
commit 16e935ebad
8 changed files with 41 additions and 33 deletions

View file

@ -3,6 +3,8 @@ include: package:lints/recommended.yaml
analyzer:
language:
strict-casts: true
# TODO(srawlins): Enable this; there are currently ~250 violations.
# strict-raw-types: true
exclude:
- test/mock_packages/**
errors:

View file

@ -20,7 +20,7 @@ import 'perf/dart_analyze.dart';
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 @@ abstract class FlutterBenchmark {
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 ListCommand extends Command {
}
}
class RunCommand extends Command {
class RunCommand extends Command<void> {
final List<Benchmark> benchmarks;
RunCommand(this.benchmarks) {
@ -225,7 +225,7 @@ class RunCommand extends Command {
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');

View file

@ -31,7 +31,7 @@ abstract class CommonInputConverter extends Converter<String, Operation?> {
/// 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 @@ abstract class CommonInputConverter extends Converter<String, Operation?> {
/// 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));

View file

@ -103,7 +103,7 @@ class ResponseOperation extends Operation {
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) {

View file

@ -31,8 +31,8 @@ abstract class AbstractBenchmarkTest {
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 @@ class AnalysisServerMemoryUsageTest
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 @@ class AnalysisServerMemoryUsageTest
// 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 @@ class AnalysisServerMemoryUsageTest
}
/// 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 @@ class LspAnalysisServerMemoryUsageTest
}
/// After every test, the server is stopped.
Future shutdown() async => this.tearDown();
Future<void> shutdown() async => this.tearDown();
}
mixin ServerMemoryUsageMixin {
@ -248,10 +248,14 @@ mixin ServerMemoryUsageMixin {
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 @@ class ServiceProtocol {
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',

View file

@ -56,7 +56,7 @@ class ByteStreamClientChannel implements ClientCommunicationChannel {
);
@override
Future close() {
Future<void> close() {
return output.close();
}
@ -80,7 +80,7 @@ abstract class ByteStreamServerChannel implements ServerCommunicationChannel {
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 @@ abstract class ByteStreamServerChannel implements ServerCommunicationChannel {
}
/// Future that will be completed when the input stream is closed.
Future get closed {
Future<void> get closed {
return _closed.future;
}

View file

@ -34,8 +34,8 @@ class ArrayTypeMatcher extends Matcher {
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 @@ class ArrayTypeMatcher extends Matcher {
}
@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 @@ class LiteralTypeMatcher extends Matcher {
.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 @@ class MapTypeMatcher extends Matcher {
.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 @@ class SimpleTypeMatcher extends Matcher {
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 @@ class SimpleTypeMatcher extends Matcher {
}
@override
bool matches(item, Map matchState) {
bool matches(item, Map<dynamic, dynamic> matchState) {
return item is TypeReference && item.name == _expectedName;
}
}

View file

@ -63,7 +63,7 @@ class Domain extends ApiNode {
}
/// 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;