Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1121)

Unified Diff: utils/pub/package.dart

Issue 12047096: Get rid of RootSource. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/root_source.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/package.dart
diff --git a/utils/pub/package.dart b/utils/pub/package.dart
index 70f469c0ea6eb69b897cdf1dff427625bafd7fa4..8e0d39e4aeaa011507acbba3df41d246e58763cd 100644
--- a/utils/pub/package.dart
+++ b/utils/pub/package.dart
@@ -82,7 +82,8 @@ class PackageId implements Comparable {
/// The name of the package being identified.
final String name;
- /// The [Source] used to look up this package given its [description].
+ /// The [Source] used to look up this package given its [description]. If
+ /// this is a root package ID, this will be `null`.
Jennifer Messerly 2013/01/24 23:24:37 fwiw, I think Kathy suggested not using code font
Bob Nystrom 2013/01/25 18:22:50 I think you're remembering right, though I persona
final Source source;
/// The package's version.
@@ -96,8 +97,11 @@ class PackageId implements Comparable {
PackageId(this.name, this.source, this.version, this.description);
+ /// Whether this ID identifies the root package.
+ bool get isRoot => source == null;
+
int get hashCode => name.hashCode ^
- source.name.hashCode ^
+ (source != null ? source.name.hashCode : 0) ^
Jennifer Messerly 2013/01/24 23:24:37 Another idea here: you could make Source.hashCode
Bob Nystrom 2013/01/25 18:22:50 Great idea! Done.
version.hashCode;
bool operator ==(other) {
@@ -106,11 +110,12 @@ class PackageId implements Comparable {
// enough to uniquely identify the package and that we don't need to delve
// into the description.
return other.name == name &&
- other.source.name == source.name &&
+ other.source == source &&
Jennifer Messerly 2013/01/24 23:24:37 just checking, source already implements reasonabl
Bob Nystrom 2013/01/25 18:22:50 I'm relying on identity here. Sources are effectiv
other.version == version;
}
String toString() {
+ if (isRoot) return "$name $version (root)";
if (source.isDefault) return "$name $version";
return "$name $version from $source";
}
@@ -141,7 +146,8 @@ class PackageRef {
/// The name of the package being identified.
final String name;
- /// The [Source] used to look up the package.
+ /// The [Source] used to look up the package. If this refers to a root
+ /// package, this will be `null`.
final Source source;
/// The allowed package versions.
@@ -153,7 +159,20 @@ class PackageRef {
PackageRef(this.name, this.source, this.constraint, this.description);
- String toString() => "$name $constraint from $source ($description)";
+ /// Creates a reference to the given root package.
+ PackageRef.root(Package package)
+ : name = package.name,
+ source = null,
+ constraint = package.version,
+ description = package.name;
+
+ /// Whether this refers to the root package.
+ bool get isRoot => source == null;
+
+ String toString() {
+ if (isRoot) return "$name $constraint (root)";
+ return "$name $constraint from $source ($description)";
+ }
/// Returns a [PackageId] generated from this [PackageRef] with the given
/// concrete version.
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/root_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698