Skip to content

Commit 062771b

Browse files
authored
Drop pkg:collection usage in lib (#1488)
1 parent cd1cf2e commit 062771b

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

json_serializable/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.9.6-wip
2+
3+
- Move `package:collection` to a dev dependency.
4+
15
## 6.9.5
26

37
- Support the `analyzer: '>=6.9.0 <8.0.0'`.

json_serializable/lib/src/type_helpers/json_converter_helper.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:analyzer/dart/constant/value.dart';
66
import 'package:analyzer/dart/element/element.dart';
77
import 'package:analyzer/dart/element/type.dart';
8-
import 'package:collection/collection.dart';
98
import 'package:json_annotation/json_annotation.dart';
109
import 'package:source_gen/source_gen.dart';
1110
import 'package:source_helper/source_helper.dart';
@@ -280,10 +279,11 @@ _ConverterMatch? _compatibleMatch(
280279
) {
281280
final converterClassElement = constantValue.type!.element as ClassElement;
282281

283-
final jsonConverterSuper =
284-
converterClassElement.allSupertypes.singleWhereOrNull(
285-
(e) => _jsonConverterChecker.isExactly(e.element),
286-
);
282+
final jsonConverterSuper = converterClassElement.allSupertypes
283+
.where(
284+
(e) => _jsonConverterChecker.isExactly(e.element),
285+
)
286+
.singleOrNull;
287287

288288
if (jsonConverterSuper == null) {
289289
return null;

json_serializable/lib/src/type_helpers/json_helper.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'package:analyzer/dart/element/element.dart';
66
import 'package:analyzer/dart/element/type.dart';
7-
import 'package:collection/collection.dart';
87
import 'package:json_annotation/json_annotation.dart';
98
import 'package:source_gen/source_gen.dart';
109
import 'package:source_helper/source_helper.dart';
@@ -79,7 +78,8 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> {
7978
final classElement = targetType.element;
8079

8180
final fromJsonCtor = classElement.constructors
82-
.singleWhereOrNull((ce) => ce.name == 'fromJson');
81+
.where((ce) => ce.name == 'fromJson')
82+
.singleOrNull;
8383

8484
var output = expression;
8585
if (fromJsonCtor != null) {
@@ -291,4 +291,5 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {
291291

292292
MethodElement? _toJsonMethod(DartType type) => type.typeImplementations
293293
.map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null)
294-
.firstWhereOrNull((me) => me != null);
294+
.where((me) => me != null)
295+
.firstOrNull;

json_serializable/lib/src/type_helpers/map_helper.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/element/type.dart';
6-
import 'package:collection/collection.dart';
76
import 'package:source_helper/source_helper.dart';
87

98
import '../constants.dart';
@@ -147,7 +146,7 @@ final _instances = [
147146
];
148147

149148
ToFromStringHelper? _forType(DartType type) =>
150-
_instances.singleWhereOrNull((i) => i.matches(type));
149+
_instances.where((i) => i.matches(type)).singleOrNull;
151150

152151
/// Returns `true` if [keyType] can be automatically converted to/from String –
153152
/// and is therefor usable as a key in a [Map].

json_serializable/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 6.9.5
2+
version: 6.9.6-wip
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.
@@ -19,7 +19,6 @@ dependencies:
1919
async: ^2.10.0
2020
build: ^2.4.1
2121
build_config: ^1.1.0
22-
collection: ^1.17.0
2322
dart_style: '>=2.3.7 <4.0.0'
2423

2524
# Use a tight version constraint to ensure that a constraint on
@@ -37,6 +36,7 @@ dev_dependencies:
3736
path: ../shared_test
3837
build_runner: ^2.4.6
3938
build_verify: ^3.0.0
39+
collection: ^1.17.0
4040
logging: ^1.0.0
4141
source_gen_test: ^1.0.6
4242
test: ^1.24.4

json_serializable/test/generic_files/generic_class.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// ignore_for_file: inference_failure_on_instance_creation
66

7-
import 'package:collection/collection.dart';
87
import 'package:json_annotation/json_annotation.dart';
98

109
import '../test_utils.dart';
@@ -146,7 +145,7 @@ class Issue980ParentClass {
146145
other is Issue980ParentClass && deepEquals(list, other.list);
147146

148147
@override
149-
int get hashCode => const DeepCollectionEquality().hash(list);
148+
int get hashCode => deepHash(list);
150149
}
151150

152151
@JsonSerializable(genericArgumentFactories: true)

json_serializable/test/test_utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import 'package:collection/collection.dart';
66

77
export 'package:_json_serial_shared_test/shared_test.dart';
88

9+
int deepHash(List value) => const DeepCollectionEquality().hash(value);
10+
911
bool deepEquals(dynamic a, dynamic b) =>
1012
const DeepCollectionEquality().equals(a, b);

0 commit comments

Comments
 (0)