mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

As per the recent fix to the `always_specify_types` lint (https://github.com/dart-lang/linter/issues/199), literal maps and lists are now expected to be explicitly typed. Running that lint on the repo identifies quite a few spots to update. This focuses on `flutter_driver` and `flutter_sprites` (somewhat arbitrarily) but the changes are fairly representative. Note there are a number of places where I made a quick judgement on how specific to make the types. Feedback on those is welcome. (Especially as we move forward with more.)
83 lines
2.0 KiB
Dart
83 lines
2.0 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:matcher/matcher.dart';
|
|
|
|
/// Matches [value] against the [matcher].
|
|
MatchResult match(dynamic value, Matcher matcher) {
|
|
Map<dynamic, dynamic> matchState = <dynamic, dynamic>{};
|
|
if (matcher.matches(value, matchState)) {
|
|
return new MatchResult._matched();
|
|
} else {
|
|
Description description =
|
|
matcher.describeMismatch(value, new _TextDescription(), matchState, false);
|
|
return new MatchResult._mismatched(description.toString());
|
|
}
|
|
}
|
|
|
|
/// Result of matching a value against a matcher.
|
|
class MatchResult {
|
|
MatchResult._matched()
|
|
: hasMatched = true,
|
|
mismatchDescription = null;
|
|
|
|
MatchResult._mismatched(String mismatchDescription)
|
|
: hasMatched = false,
|
|
mismatchDescription = mismatchDescription;
|
|
|
|
/// Whether the match succeeded.
|
|
final bool hasMatched;
|
|
|
|
/// If the match did not succeed, this field contains the explanation.
|
|
final String mismatchDescription;
|
|
}
|
|
|
|
/// Writes description into a string.
|
|
class _TextDescription implements Description {
|
|
final StringBuffer _text = new StringBuffer();
|
|
|
|
@override
|
|
int get length => _text.length;
|
|
|
|
@override
|
|
Description add(String text) {
|
|
_text.write(text);
|
|
return this;
|
|
}
|
|
|
|
@override
|
|
Description replace(String text) {
|
|
_text.clear();
|
|
_text.write(text);
|
|
return this;
|
|
}
|
|
|
|
@override
|
|
Description addDescriptionOf(dynamic value) {
|
|
if (value is Matcher) {
|
|
value.describe(this);
|
|
return this;
|
|
} else {
|
|
return add('$value');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Description addAll(String start, String separator, String end, Iterable<dynamic> list) {
|
|
add(start);
|
|
if (list.isNotEmpty) {
|
|
addDescriptionOf(list.first);
|
|
for (dynamic item in list.skip(1)) {
|
|
add(separator);
|
|
addDescriptionOf(item);
|
|
}
|
|
}
|
|
add(end);
|
|
return this;
|
|
}
|
|
|
|
@override
|
|
String toString() => '$_text';
|
|
}
|