Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Use library URIs (not names) to look up annotations in the mirror system.
* Loosen version constraint to allow package:build version 0.6
* Fix a bug against the latest SDK checking whether List implements Iterable

## 0.5.1+7

Expand Down
14 changes: 6 additions & 8 deletions lib/generators/json_serializable_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,10 @@ ParameterizedType _typeTest(
if (tester(type)) return type;

if (type is InterfaceType) {
var items = type.interfaces.where(tester).toList();
var tests = type.interfaces.map((type) => _typeTest(type, tester));
var match = _firstNonNull(tests);

if (items.length > 1) {
throw 'weird - more than 1 interface matches the type test - $items';
}

if (items.length == 1) {
return items.single;
}
if (match != null) return match;

if (type.superclass != null) {
return _typeTest(type.superclass, tester);
Expand All @@ -295,6 +290,9 @@ ParameterizedType _typeTest(
return null;
}

/*=T*/ _firstNonNull/*<T>*/(Iterable/*<T>*/ values) =>
values.firstWhere((value) => value != null, orElse: () => null);

bool _isDartIterable(DartType type) {
return type.element.library != null &&
type.element.library.isDartCore &&
Expand Down