Skip to content

Commit

Permalink
Add explicit type arguments where they are not inferred (flutter#7088)
Browse files Browse the repository at this point in the history
* Add explicit type arguments where they are not inferred

* Use String as args Map key
  • Loading branch information
srawlins authored Jan 23, 2024
1 parent abbe04a commit 59312ff
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ class Gutter extends StatelessWidget {

@override
Widget build(BuildContext context) {
final bpLineSet = Set.from(breakpoints.map((bp) => bp.line));
final bpLineSet = Set.of(breakpoints.map((bp) => bp.line));
final theme = Theme.of(context);
final coverageLines =
sourceReport.coverageHitLines.union(sourceReport.coverageMissedLines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class FileSearchResults {
return copyWith();
}

final topMatches = [];
final topMatches = <List<ScriptRef>>[];
int matchesLeft = numOfMatchesToShow;
for (final matches in [
_exactFileNameMatches,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AdaptedHeap {
assert(data.allFieldsCalculated);

final result = <HeapClassName, SingleClassStats>{};
for (var i in Iterable.generate(data.objects.length)) {
for (var i in Iterable<int>.generate(data.objects.length)) {
if (_uiReleaser.step()) await _uiReleaser.releaseUi();
final object = data.objects[i];
final className = object.heapClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ClassOnlyHeapPath {
return data.join().trim();
}

late final _listEquality = const ListEquality().equals;
late final _listEquality = const ListEquality<HeapClassName>().equals;

@override
bool operator ==(Object other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Future<void> calculateHeap(AdaptedHeapData heap) async {

Future<void> _setInboundRefs(AdaptedHeapData heap) async {
int totalDartSize = 0;
for (final from in Iterable.generate(heap.objects.length)) {
for (final from in Iterable<int>.generate(heap.objects.length)) {
totalDartSize += heap.objects[from].shallowSize;
if (_uiReleaser.step()) await _uiReleaser.releaseUi();
for (final to in heap.objects[from].outRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FrameHints extends StatelessWidget {
if (intrinsicOperationsCount > 0)
IntrinsicOperationsHint(intrinsicOperationsCount),
]
: [];
: <Widget>[];
final rasterHints = showRasterJankHints
? [
const Text('Raster Jank Detected'),
Expand All @@ -71,7 +71,7 @@ class FrameHints extends StatelessWidget {
const SizedBox(height: denseSpacing),
const RasterStatsHint(),
]
: [];
: <Widget>[];

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ abstract class InspectorObjectGroupBase
WidgetInspectorServiceExtensions.disposeGroup.name,
groupName,
)
: Future.value();
: Future<void>.value();
disposed = true;
return disposeComplete;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AdaptedHeapData {
HeapSnapshotGraph graph,
) async {
final objects = <AdaptedHeapObject>[];
for (final i in Iterable.generate(graph.objects.length)) {
for (final i in Iterable<int>.generate(graph.objects.length)) {
if (_uiReleaser.step()) await _uiReleaser.releaseUi();
final object =
AdaptedHeapObject.fromHeapSnapshotObject(graph.objects[i], i);
Expand Down Expand Up @@ -93,9 +93,9 @@ class AdaptedHeapData {

String snapshotName = '';

/// Heap objects by identityHashCode.
late final _objectsByCode = <IdentityHashCode, int>{
for (var i in Iterable.generate(objects.length)) objects[i].code: i,
/// Heap objects by `identityHashCode`.
late final _objectsByCode = <IdentityHashCode, int?>{
for (var i in Iterable<int>.generate(objects.length)) objects[i].code: i,
};

int? objectIndexByIdentityHashCode(IdentityHashCode code) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/lib/src/shared/ui/hover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class _HoverCardTooltipState extends State<HoverCardTooltip> {
}

Completer _timeoutCompleter(int timeout) {
final completer = Completer();
final completer = Completer<void>();
Timer(Duration(milliseconds: timeout), () {
completer.complete();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DartToolingApiImpl implements DartToolingApi {
if (_enablePostMessageVerboseLogging) {
setDevToolsLoggingLevel(verboseLoggingLevel);
}
final postMessageController = StreamController();
final postMessageController = StreamController<Object?>();
postMessageController.stream.listen((message) {
// TODO(dantup): Using fine here doesn't work even though the
// `setDevToolsLoggingLevel` call above seems like it should show finest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void main() {
});

test('starts empty', () {
expect(evalHistory.evalHistory, []);
expect(evalHistory.evalHistory, <Object?>[]);
expect(evalHistory.currentText, null);
expect(evalHistory.canNavigateDown, false);
expect(evalHistory.canNavigateUp, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DevtoolsManager {
waitForConnection
? tabInstance.onEvent
.firstWhere((msg) => msg.event == 'app.devToolsReady')
: Future.value(),
: Future<void>.value(),
tabInstance.getBrowserChannel(),
]);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/devtools_app/test/network/network_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void main() {
'isRedirect': false,
'persistentConnection': true,
'reasonPhrase': 'OK',
'redirects': [],
'redirects': <Object?>[],
'statusCode': 200,
}),
isTrue,
Expand All @@ -273,7 +273,7 @@ void main() {
'isRedirect': false,
'persistentConnection': true,
'reasonPhrase': 'Created',
'redirects': [],
'redirects': <Object?>[],
'statusCode': 201,
}),
isTrue,
Expand All @@ -293,7 +293,7 @@ void main() {
'isRedirect': false,
'persistentConnection': true,
'reasonPhrase': 'OK',
'redirects': [],
'redirects': <Object?>[],
'statusCode': 200,
}),
isTrue,
Expand All @@ -312,7 +312,7 @@ void main() {
'isRedirect': false,
'persistentConnection': true,
'reasonPhrase': 'OK',
'redirects': [],
'redirects': <Object?>[],
'statusCode': 200,
}),
isTrue,
Expand All @@ -332,7 +332,7 @@ void main() {
'isRedirect': false,
'persistentConnection': true,
'reasonPhrase': 'Switching Protocols',
'redirects': [],
'redirects': <Object?>[],
'statusCode': 101,
}),
isTrue,
Expand All @@ -358,19 +358,19 @@ void main() {
expect(httpGetWithError.requestHeaders, isNull);
expect(
collectionEquals(httpPost.requestHeaders, {
'transfer-encoding': [],
'transfer-encoding': <Object?>[],
}),
isTrue,
);
expect(
collectionEquals(httpPut.requestHeaders, {
'transfer-encoding': [],
'transfer-encoding': <Object?>[],
}),
isTrue,
);
expect(
collectionEquals(httpPatch.requestHeaders, {
'transfer-encoding': [],
'transfer-encoding': <Object?>[],
}),
isTrue,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ void main() {
performanceData.toJson(),
equals({
PerformanceData.selectedFrameIdKey: null,
PerformanceData.flutterFramesKey: [],
PerformanceData.flutterFramesKey: <Object?>[],
PerformanceData.displayRefreshRateKey: 60,
PerformanceData.traceEventsKey: [],
PerformanceData.selectedEventKey: {},
PerformanceData.cpuProfileKey: {},
PerformanceData.rasterStatsKey: {},
PerformanceData.traceEventsKey: <Object?>[],
PerformanceData.selectedEventKey: <Object?, Object?>{},
PerformanceData.cpuProfileKey: <Object?, Object?>{},
PerformanceData.rasterStatsKey: <Object?, Object?>{},
PerformanceData.rebuildCountModelKey: null,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void main() {
'pid': 94955,
'ts': 118039650802,
'ph': 'B',
'args': {},
'args': <String, Object?>{},
});
final animatorBeginFrameEvent = testTraceEventWrapper({
'name': 'Animator::BeginFrame',
Expand All @@ -144,7 +144,7 @@ void main() {
'pid': 94955,
'ts': 118039650802,
'ph': 'B',
'args': {},
'args': <String, Object?>{},
});
traceEvents = [
vsyncEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ final _frameIdentifierEvents = [
'pid': 94955,
'ts': 200,
'ph': 'E',
'args': {},
'args': <String, Object?>{},
}),
testTraceEventWrapper({
'name': 'Animator::BeginFrame',
Expand All @@ -176,7 +176,7 @@ final _frameIdentifierEvents = [
'pid': 94955,
'ts': 400,
'ph': 'E',
'args': {},
'args': <String, Object?>{},
}),
testTraceEventWrapper({
'name': 'Animator::BeginFrame',
Expand All @@ -194,7 +194,7 @@ final _frameIdentifierEvents = [
'pid': 94955,
'ts': 600,
'ph': 'E',
'args': {},
'args': <String, Object?>{},
}),
testTraceEventWrapper({
'name': 'GPURasterizer::Draw',
Expand All @@ -215,7 +215,7 @@ final _frameIdentifierEvents = [
'pid': 94955,
'ts': 250,
'ph': 'E',
'args': {},
'args': <String, Object?>{},
}),
testTraceEventWrapper({
'name': 'GPURasterizer::Draw',
Expand All @@ -236,7 +236,7 @@ final _frameIdentifierEvents = [
'pid': 94955,
'ts': 450,
'ph': 'E',
'args': {},
'args': <String, Object?>{},
}),
testTraceEventWrapper({
'name': 'GPURasterizer::Draw',
Expand All @@ -257,6 +257,6 @@ final _frameIdentifierEvents = [
'pid': 94955,
'ts': 650,
'ph': 'E',
'args': {},
'args': <String, Object?>{},
}),
];
11 changes: 7 additions & 4 deletions packages/devtools_app/test/primitives/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,10 @@ void main() {
subtractor: elementSubtractor,
);

expect(const SetEquality().equals(result.keys.toSet(), {1, 2}), true);
expect(
const SetEquality<int>().equals(result.keys.toSet(), {1, 2}),
true,
);
expect(
result[1],
equals(_SubtractionResult(subtract: 'subtract', from: 1.0)),
Expand All @@ -1411,7 +1414,7 @@ void main() {
subtractor: elementSubtractor,
);

expect(const SetEquality().equals(result.keys.toSet(), {1}), true);
expect(const SetEquality<int>().equals(result.keys.toSet(), {1}), true);
expect(
result[1],
equals(_SubtractionResult(subtract: null, from: 1.0)),
Expand All @@ -1432,7 +1435,7 @@ void main() {
subtractor: elementSubtractor,
);

expect(const SetEquality().equals(result.keys.toSet(), {1}), true);
expect(const SetEquality<int>().equals(result.keys.toSet(), {1}), true);
expect(
result[1],
equals(_SubtractionResult(subtract: 'subtract', from: null)),
Expand All @@ -1443,7 +1446,7 @@ void main() {

group('joinWithTrailing', () {
test('joins no items', () {
expect([].joinWithTrailing(':'), equals(''));
expect(<String>[].joinWithTrailing(':'), equals(''));
});
test(' joins 1 item', () {
expect(['A'].joinWithTrailing(':'), equals('A:'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _MyGarbage {
};

map = {
for (var _ in Iterable.generate(_width))
for (var _ in Iterable<void>.generate(_width))
createInstance(): createInstance(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class FlutterTestEnvironment {

await serviceConnection.serviceManager.vmServiceOpened(
_service,
onClosed: Completer().future,
onClosed: Completer<void>().future,
);
await _preferencesController!.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ AdaptedHeapData _createHeap(Map<String, int> classToInstanceCount) {

// Create objects.
for (var entry in classToInstanceCount.entries) {
for (var _ in Iterable.generate(entry.value)) {
for (var _ in Iterable<void>.generate(entry.value)) {
objects.add(_createObject(entry.key));
leafCount++;
final objectIndex = leafCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _VsCodeFlutterPanelMockEditorState

/// The last [maxLogEvents] communication messages sent between the panel
/// and the "host IDE".
final logRing = DoubleLinkedQueue();
final logRing = DoubleLinkedQueue<String>();

/// A stream that emits each time the log is updated to allow the log widget
/// to be rebuilt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ void main() {
group('Disposer', () {
test('disposes streams', () {
final disposer = Disposer();
final controller1 = StreamController(sync: true);
final controller2 = StreamController(sync: true);
final controller1 = StreamController<void>(sync: true);
final controller2 = StreamController<void>(sync: true);
var c1Events = 0;
var c2Events = 0;
disposer.autoDisposeStreamSubscription(
controller1.stream.listen((data) {
controller1.stream.listen((_) {
c1Events++;
}),
);
disposer.autoDisposeStreamSubscription(
controller2.stream.listen((data) {
controller2.stream.listen((_) {
c2Events++;
}),
);
Expand Down Expand Up @@ -324,7 +324,7 @@ void main() {
testWidgets('Test stream auto dispose', (WidgetTester tester) async {
// Build our app and trigger a frame.
final key = GlobalKey();
final controller = StreamController();
final controller = StreamController<void>();
await tester.pumpWidget(AutoDisposedWidget(controller.stream, key: key));

final state = key.currentState as _AutoDisposedWidgetState;
Expand Down
Loading

0 comments on commit 59312ff

Please sign in to comment.