From da6d5dbb9100cdc7e07d529d439a190aa86ecf06 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 3 Sep 2024 14:20:39 +0200 Subject: [PATCH] Remove `equatable` --- .../lib/src/internal/definition.dart | 16 +++++-- pkgs/record_use/lib/src/internal/usage.dart | 16 +++++-- .../lib/src/internal/usage_record.dart | 17 +++++-- .../record_use/lib/src/public/annotation.dart | 34 -------------- pkgs/record_use/lib/src/public/arguments.dart | 45 +++++++++++++++---- pkgs/record_use/lib/src/public/field.dart | 13 ++++-- .../record_use/lib/src/public/identifier.dart | 16 +++++-- pkgs/record_use/lib/src/public/instance.dart | 18 ++++++-- pkgs/record_use/lib/src/public/location.dart | 16 +++++-- pkgs/record_use/lib/src/public/metadata.dart | 14 ++++-- pkgs/record_use/lib/src/public/reference.dart | 39 +++++++++++++--- pkgs/record_use/pubspec.yaml | 1 - 12 files changed, 168 insertions(+), 77 deletions(-) delete mode 100644 pkgs/record_use/lib/src/public/annotation.dart diff --git a/pkgs/record_use/lib/src/internal/definition.dart b/pkgs/record_use/lib/src/internal/definition.dart index 407c4c0f7..b838d0663 100644 --- a/pkgs/record_use/lib/src/internal/definition.dart +++ b/pkgs/record_use/lib/src/internal/definition.dart @@ -2,12 +2,10 @@ // for details. 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:equatable/equatable.dart'; - import '../public/identifier.dart'; import '../public/location.dart'; -class Definition extends Equatable { +class Definition { final Identifier identifier; /// Represents the '@' field in the JSON @@ -47,5 +45,15 @@ class Definition extends Equatable { }; @override - List get props => [identifier, location, loadingUnit]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Definition && + other.identifier == identifier && + other.location == location && + other.loadingUnit == loadingUnit; + } + + @override + int get hashCode => Object.hash(identifier, location, loadingUnit); } diff --git a/pkgs/record_use/lib/src/internal/usage.dart b/pkgs/record_use/lib/src/internal/usage.dart index 7e2532f5a..0f3aa1a66 100644 --- a/pkgs/record_use/lib/src/internal/usage.dart +++ b/pkgs/record_use/lib/src/internal/usage.dart @@ -2,13 +2,13 @@ // for details. 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:equatable/equatable.dart'; +import 'package:collection/collection.dart'; import '../public/identifier.dart'; import '../public/reference.dart'; import 'definition.dart'; -class Usage extends Equatable { +class Usage { final Definition definition; final List references; @@ -43,5 +43,15 @@ class Usage extends Equatable { }; @override - List get props => [definition, references]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + final listEquals = const DeepCollectionEquality().equals; + + return other is Usage && + other.definition == definition && + listEquals(other.references, references); + } + + @override + int get hashCode => Object.hash(definition, references); } diff --git a/pkgs/record_use/lib/src/internal/usage_record.dart b/pkgs/record_use/lib/src/internal/usage_record.dart index aaee5ec31..dc12fc986 100644 --- a/pkgs/record_use/lib/src/internal/usage_record.dart +++ b/pkgs/record_use/lib/src/internal/usage_record.dart @@ -2,14 +2,14 @@ // for details. 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:equatable/equatable.dart'; +import 'package:collection/collection.dart'; import '../public/identifier.dart'; import '../public/metadata.dart'; import '../public/reference.dart'; import 'usage.dart'; -class UsageRecord extends Equatable { +class UsageRecord { final Metadata metadata; final List> calls; final List> instances; @@ -83,5 +83,16 @@ class UsageRecord extends Equatable { } @override - List get props => [metadata, calls, instances]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + final listEquals = const DeepCollectionEquality().equals; + + return other is UsageRecord && + other.metadata == metadata && + listEquals(other.calls, calls) && + listEquals(other.instances, instances); + } + + @override + int get hashCode => Object.hash(metadata, calls, instances); } diff --git a/pkgs/record_use/lib/src/public/annotation.dart b/pkgs/record_use/lib/src/public/annotation.dart deleted file mode 100644 index 58ccd7227..000000000 --- a/pkgs/record_use/lib/src/public/annotation.dart +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file -// for details. 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:equatable/equatable.dart'; - -import 'identifier.dart'; - -class Annotation extends Equatable { - final Identifier identifier; - final Map fields; - - Annotation({ - required this.identifier, - required this.fields, - }); - - factory Annotation.fromJson( - Map json, - List identifiers, - ) => - Annotation( - identifier: identifiers[json['id'] as int], - fields: json['fields'] as Map, - ); - - Map toJson(List identifiers) => { - 'id': identifiers.indexOf(identifier), - 'fields': fields, - }; - - @override - List get props => [identifier, fields]; -} diff --git a/pkgs/record_use/lib/src/public/arguments.dart b/pkgs/record_use/lib/src/public/arguments.dart index 67809ed61..2396db766 100644 --- a/pkgs/record_use/lib/src/public/arguments.dart +++ b/pkgs/record_use/lib/src/public/arguments.dart @@ -1,10 +1,10 @@ +import 'package:collection/collection.dart'; + // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file // for details. 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:equatable/equatable.dart'; - -class Arguments extends Equatable { +class Arguments { final ConstArguments constArguments; final NonConstArguments nonConstArguments; @@ -38,10 +38,19 @@ class Arguments extends Equatable { } @override - List get props => [constArguments, nonConstArguments]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Arguments && + other.constArguments == constArguments && + other.nonConstArguments == nonConstArguments; + } + + @override + int get hashCode => Object.hash(constArguments, nonConstArguments); } -class ConstArguments extends Equatable { +class ConstArguments { final Map positional; final Map named; @@ -66,10 +75,20 @@ class ConstArguments extends Equatable { }; @override - List get props => [positional, named]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + final mapEquals = const DeepCollectionEquality().equals; + + return other is ConstArguments && + mapEquals(other.positional, positional) && + mapEquals(other.named, named); + } + + @override + int get hashCode => Object.hash(positional, named); } -class NonConstArguments extends Equatable { +class NonConstArguments { final List positional; final List named; @@ -90,5 +109,15 @@ class NonConstArguments extends Equatable { }; @override - List get props => [positional, named]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + final listEquals = const DeepCollectionEquality().equals; + + return other is NonConstArguments && + listEquals(other.positional, positional) && + listEquals(other.named, named); + } + + @override + int get hashCode => Object.hash(positional, named); } diff --git a/pkgs/record_use/lib/src/public/field.dart b/pkgs/record_use/lib/src/public/field.dart index 423f91bb9..075ba3017 100644 --- a/pkgs/record_use/lib/src/public/field.dart +++ b/pkgs/record_use/lib/src/public/field.dart @@ -2,9 +2,7 @@ // for details. 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:equatable/equatable.dart'; - -class Field extends Equatable { +class Field { final String name; final Object? value; @@ -28,5 +26,12 @@ class Field extends Equatable { } @override - List get props => [name, value]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Field && other.name == name && other.value == value; + } + + @override + int get hashCode => Object.hash(name, value); } diff --git a/pkgs/record_use/lib/src/public/identifier.dart b/pkgs/record_use/lib/src/public/identifier.dart index 86656d91c..11845cdf9 100644 --- a/pkgs/record_use/lib/src/public/identifier.dart +++ b/pkgs/record_use/lib/src/public/identifier.dart @@ -2,9 +2,7 @@ // for details. 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:equatable/equatable.dart'; - -class Identifier extends Equatable { +class Identifier { final String uri; final String? parent; // Optional since not all elements have parents final String name; @@ -29,5 +27,15 @@ class Identifier extends Equatable { }; @override - List get props => [uri, parent, name]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Identifier && + other.uri == uri && + other.parent == parent && + other.name == name; + } + + @override + int get hashCode => Object.hash(uri, parent, name); } diff --git a/pkgs/record_use/lib/src/public/instance.dart b/pkgs/record_use/lib/src/public/instance.dart index 312d34025..ae4affbf2 100644 --- a/pkgs/record_use/lib/src/public/instance.dart +++ b/pkgs/record_use/lib/src/public/instance.dart @@ -1,15 +1,25 @@ +import 'package:collection/collection.dart'; + // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file // for details. 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:equatable/equatable.dart'; - -class Instance extends Equatable { +class Instance { final String className; final Map fields; Instance({required this.className, required this.fields}); @override - List get props => [fields]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + final mapEquals = const DeepCollectionEquality().equals; + + return other is Instance && + other.className == className && + mapEquals(other.fields, fields); + } + + @override + int get hashCode => Object.hash(className, fields); } diff --git a/pkgs/record_use/lib/src/public/location.dart b/pkgs/record_use/lib/src/public/location.dart index 1a56578a2..b1fe11665 100644 --- a/pkgs/record_use/lib/src/public/location.dart +++ b/pkgs/record_use/lib/src/public/location.dart @@ -2,9 +2,7 @@ // for details. 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:equatable/equatable.dart'; - -class Location extends Equatable { +class Location { final String uri; final int line; final int column; @@ -33,5 +31,15 @@ class Location extends Equatable { } @override - List get props => [uri, line, column]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Location && + other.uri == uri && + other.line == line && + other.column == column; + } + + @override + int get hashCode => Object.hash(uri, line, column); } diff --git a/pkgs/record_use/lib/src/public/metadata.dart b/pkgs/record_use/lib/src/public/metadata.dart index 24d10cea7..37d7351d0 100644 --- a/pkgs/record_use/lib/src/public/metadata.dart +++ b/pkgs/record_use/lib/src/public/metadata.dart @@ -2,10 +2,9 @@ // for details. 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:equatable/equatable.dart'; import 'package:pub_semver/pub_semver.dart'; -class Metadata extends Equatable { +class Metadata { final String? comment; final Version version; @@ -35,5 +34,14 @@ Metadata( } @override - List get props => [comment, version]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Metadata && + other.comment == comment && + other.version == version; + } + + @override + int get hashCode => Object.hash(comment, version); } diff --git a/pkgs/record_use/lib/src/public/reference.dart b/pkgs/record_use/lib/src/public/reference.dart index fc0d1494f..86df50c49 100644 --- a/pkgs/record_use/lib/src/public/reference.dart +++ b/pkgs/record_use/lib/src/public/reference.dart @@ -2,13 +2,13 @@ // for details. 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:equatable/equatable.dart'; +import 'package:collection/collection.dart'; import 'arguments.dart'; import 'field.dart'; import 'location.dart'; -sealed class Reference extends Equatable { +sealed class Reference { final String? loadingUnit; /// Represents the "@" field in the JSON @@ -22,7 +22,16 @@ sealed class Reference extends Equatable { }; @override - List get props => [loadingUnit, location]; + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Reference && + other.loadingUnit == loadingUnit && + other.location == location; + } + + @override + int get hashCode => Object.hash(loadingUnit, location); } final class CallReference extends Reference { @@ -55,7 +64,15 @@ final class CallReference extends Reference { } @override - List get props => super.props..add(arguments); + bool operator ==(Object other) { + if (identical(this, other)) return true; + if (!(super == other)) return false; + + return other is CallReference && other.arguments == arguments; + } + + @override + int get hashCode => Object.hash(arguments, super.hashCode); } final class InstanceReference extends Reference { @@ -89,6 +106,18 @@ final class InstanceReference extends Reference { 'className': className, ...super.toJson(uris), }; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + if (!(super == other)) return false; + final listEquals = const DeepCollectionEquality().equals; + + return other is InstanceReference && + other.className == className && + listEquals(other.fields, fields); + } + @override - List get props => super.props..add([className, fields]); + int get hashCode => Object.hash(className, fields, super.hashCode); } diff --git a/pkgs/record_use/pubspec.yaml b/pkgs/record_use/pubspec.yaml index 96483dd4a..2429a8eb9 100644 --- a/pkgs/record_use/pubspec.yaml +++ b/pkgs/record_use/pubspec.yaml @@ -9,7 +9,6 @@ environment: dependencies: collection: ^1.18.0 - equatable: ^2.0.5 pub_semver: ^2.1.4 dev_dependencies: