refactor!: Seal the Dependency class (dart-lang/pubspec_parse#140)
* fix: Don't use runtimeType for toString
diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md
index 2768cde..251d4cc 100644
--- a/pkgs/pubspec_parse/CHANGELOG.md
+++ b/pkgs/pubspec_parse/CHANGELOG.md
@@ -1,6 +1,7 @@
-## 1.3.1-wip
+## 1.4.0-wip
- Require Dart 3.2
+- Seal the `Dependency` class.
- Set `Pubspec.environment` to non-nullable.
- Remove deprecated package_api_docs rule
diff --git a/pkgs/pubspec_parse/lib/src/dependency.dart b/pkgs/pubspec_parse/lib/src/dependency.dart
index acce598..24c65ea 100644
--- a/pkgs/pubspec_parse/lib/src/dependency.dart
+++ b/pkgs/pubspec_parse/lib/src/dependency.dart
@@ -90,14 +90,7 @@
return null;
}
-abstract class Dependency {
- Dependency._();
-
- String get _info;
-
- @override
- String toString() => '$runtimeType: $_info';
-}
+sealed class Dependency {}
@JsonSerializable()
class SdkDependency extends Dependency {
@@ -106,11 +99,7 @@
final VersionConstraint version;
SdkDependency(this.sdk, {VersionConstraint? version})
- : version = version ?? VersionConstraint.any,
- super._();
-
- @override
- String get _info => sdk;
+ : version = version ?? VersionConstraint.any;
@override
bool operator ==(Object other) =>
@@ -118,6 +107,9 @@
@override
int get hashCode => Object.hash(sdk, version);
+
+ @override
+ String toString() => 'SdkDependency: $sdk';
}
@JsonSerializable()
@@ -127,7 +119,7 @@
final String? ref;
final String? path;
- GitDependency(this.url, {this.ref, this.path}) : super._();
+ GitDependency(this.url, {this.ref, this.path});
factory GitDependency.fromData(Object? data) {
if (data is String) {
@@ -142,9 +134,6 @@
}
@override
- String get _info => 'url@$url';
-
- @override
bool operator ==(Object other) =>
other is GitDependency &&
other.url == url &&
@@ -153,6 +142,9 @@
@override
int get hashCode => Object.hash(url, ref, path);
+
+ @override
+ String toString() => 'GitDependency: url@$url';
}
Uri? parseGitUriOrNull(String? value) =>
@@ -194,7 +186,7 @@
class PathDependency extends Dependency {
final String path;
- PathDependency(this.path) : super._();
+ PathDependency(this.path);
factory PathDependency.fromData(Object? data) {
if (data is String) {
@@ -204,14 +196,14 @@
}
@override
- String get _info => 'path@$path';
-
- @override
bool operator ==(Object other) =>
other is PathDependency && other.path == path;
@override
int get hashCode => path.hashCode;
+
+ @override
+ String toString() => 'PathDependency: path@$path';
}
@JsonSerializable(disallowUnrecognizedKeys: true)
@@ -223,11 +215,7 @@
final HostedDetails? hosted;
HostedDependency({VersionConstraint? version, this.hosted})
- : version = version ?? VersionConstraint.any,
- super._();
-
- @override
- String get _info => version.toString();
+ : version = version ?? VersionConstraint.any;
@override
bool operator ==(Object other) =>
@@ -237,6 +225,9 @@
@override
int get hashCode => Object.hash(version, hosted);
+
+ @override
+ String toString() => 'HostedDependency: $version';
}
@JsonSerializable(disallowUnrecognizedKeys: true)
diff --git a/pkgs/pubspec_parse/pubspec.yaml b/pkgs/pubspec_parse/pubspec.yaml
index 00cf12c..bcdaa31 100644
--- a/pkgs/pubspec_parse/pubspec.yaml
+++ b/pkgs/pubspec_parse/pubspec.yaml
@@ -1,5 +1,5 @@
name: pubspec_parse
-version: 1.3.1-wip
+version: 1.4.0-wip
description: >-
Simple package for parsing pubspec.yaml files with a type-safe API and rich
error reporting.