Skip to content

Commit

Permalink
Remove equatable
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Sep 3, 2024
1 parent 621088c commit da6d5db
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 77 deletions.
16 changes: 12 additions & 4 deletions pkgs/record_use/lib/src/internal/definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,5 +45,15 @@ class Definition extends Equatable {
};

@override
List<Object?> 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);
}
16 changes: 13 additions & 3 deletions pkgs/record_use/lib/src/internal/usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Reference> extends Equatable {
class Usage<T extends Reference> {
final Definition definition;
final List<T> references;

Expand Down Expand Up @@ -43,5 +43,15 @@ class Usage<T extends Reference> extends Equatable {
};

@override
List<Object?> get props => [definition, references];
bool operator ==(Object other) {
if (identical(this, other)) return true;
final listEquals = const DeepCollectionEquality().equals;

return other is Usage<T> &&
other.definition == definition &&
listEquals(other.references, references);
}

@override
int get hashCode => Object.hash(definition, references);
}
17 changes: 14 additions & 3 deletions pkgs/record_use/lib/src/internal/usage_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Usage<CallReference>> calls;
final List<Usage<InstanceReference>> instances;
Expand Down Expand Up @@ -83,5 +83,16 @@ class UsageRecord extends Equatable {
}

@override
List<Object?> 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);
}
34 changes: 0 additions & 34 deletions pkgs/record_use/lib/src/public/annotation.dart

This file was deleted.

45 changes: 37 additions & 8 deletions pkgs/record_use/lib/src/public/arguments.dart
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -38,10 +38,19 @@ class Arguments extends Equatable {
}

@override
List<Object?> 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<int, dynamic> positional;
final Map<String, dynamic> named;

Expand All @@ -66,10 +75,20 @@ class ConstArguments extends Equatable {
};

@override
List<Object?> 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<int> positional;
final List<String> named;

Expand All @@ -90,5 +109,15 @@ class NonConstArguments extends Equatable {
};

@override
List<Object?> 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);
}
13 changes: 9 additions & 4 deletions pkgs/record_use/lib/src/public/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,5 +26,12 @@ class Field extends Equatable {
}

@override
List<Object?> 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);
}
16 changes: 12 additions & 4 deletions pkgs/record_use/lib/src/public/identifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,5 +27,15 @@ class Identifier extends Equatable {
};

@override
List<Object?> 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);
}
18 changes: 14 additions & 4 deletions pkgs/record_use/lib/src/public/instance.dart
Original file line number Diff line number Diff line change
@@ -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<String, Object?> fields;

Instance({required this.className, required this.fields});

@override
List<Object?> 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);
}
16 changes: 12 additions & 4 deletions pkgs/record_use/lib/src/public/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,5 +31,15 @@ class Location extends Equatable {
}

@override
List<Object?> 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);
}
14 changes: 11 additions & 3 deletions pkgs/record_use/lib/src/public/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -35,5 +34,14 @@ Metadata(
}

@override
List<Object?> 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);
}
Loading

0 comments on commit da6d5db

Please sign in to comment.