-
Notifications
You must be signed in to change notification settings - Fork 78
Change classes and constructors to new/primary syntax. #2233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lrhn
wants to merge
4
commits into
main
Choose a base branch
from
package-config-new-constructors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ import 'util.dart'; | |
| /// so classes outside of this package must not implement [PackageConfig] | ||
| /// or any subclass of it. | ||
| @sealed | ||
| abstract class PackageConfig { | ||
| abstract interface class PackageConfig { | ||
| /// The lowest configuration version currently supported. | ||
| static const int minVersion = 2; | ||
|
|
||
|
|
@@ -56,7 +56,7 @@ abstract class PackageConfig { | |
| /// [PackageConfig.extraData] of the created configuration. | ||
| /// | ||
| /// The version of the resulting configuration is always [maxVersion]. | ||
| factory PackageConfig(Iterable<Package> packages, {Object? extraData}) => | ||
| factory(Iterable<Package> packages, {Object? extraData}) => | ||
| SimplePackageConfig(maxVersion, packages, extraData); | ||
|
|
||
| /// Parses a package configuration file. | ||
|
|
@@ -230,7 +230,7 @@ abstract class PackageConfig { | |
|
|
||
| /// Configuration data for a single package. | ||
| @sealed | ||
| abstract class Package { | ||
| abstract interface class Package { | ||
| /// Creates a package with the provided properties. | ||
| /// | ||
| /// The [name] must be a valid package name. | ||
|
|
@@ -251,7 +251,7 @@ abstract class Package { | |
| /// | ||
| /// If [extraData] is supplied, it will be available as the | ||
| /// [Package.extraData] of the created package. | ||
| factory Package( | ||
| factory( | ||
| String name, | ||
| Uri root, { | ||
| Uri? packageUriRoot, | ||
|
|
@@ -329,7 +329,8 @@ abstract class Package { | |
| /// then an *invalid* language version may be represented by an | ||
| /// [InvalidLanguageVersion] object. | ||
| @sealed | ||
| abstract class LanguageVersion implements Comparable<LanguageVersion> { | ||
| abstract interface class LanguageVersion | ||
| implements Comparable<LanguageVersion> { | ||
| /// The maximal value allowed by [major] and [minor] values; | ||
| static const int maxValue = 0x7FFFFFFF; | ||
|
|
||
|
|
@@ -338,7 +339,7 @@ abstract class LanguageVersion implements Comparable<LanguageVersion> { | |
| /// | ||
| /// Both [major] and [minor] must be greater than or equal to 0 | ||
| /// and less than or equal to [maxValue]. | ||
| factory LanguageVersion(int major, int minor) => SimpleLanguageVersion( | ||
| factory(int major, int minor) => SimpleLanguageVersion( | ||
| RangeError.checkValueInInterval(major, 0, maxValue, 'major'), | ||
| RangeError.checkValueInInterval(minor, 0, maxValue, 'minor'), | ||
| null, | ||
|
|
@@ -424,7 +425,7 @@ abstract class LanguageVersion implements Comparable<LanguageVersion> { | |
| /// The caller which provided the non-throwing `onError` handler | ||
| /// should be prepared to encounter invalid values. | ||
| @sealed | ||
| abstract class InvalidLanguageVersion implements LanguageVersion { | ||
| abstract interface class InvalidLanguageVersion implements LanguageVersion { | ||
| /// The value -1 for an invalid language version. | ||
| @override | ||
| int get major; | ||
|
|
@@ -526,15 +527,21 @@ const bool _disallowPackagesInsidePackageUriRoot = false; | |
| // Implementations of the main data types exposed by the API of this package. | ||
|
|
||
| @sealed | ||
| class SimplePackageConfig implements PackageConfig { | ||
| class SimplePackageConfig._( | ||
| this.version, | ||
| this._packageTree, | ||
| this._packages, | ||
| this.extraData, | ||
| ) implements PackageConfig { | ||
|
|
||
| @override | ||
| final int version; | ||
| final Map<String, Package> _packages; | ||
| final PackageTree _packageTree; | ||
| @override | ||
| final Object? extraData; | ||
|
|
||
| factory SimplePackageConfig( | ||
| factory( | ||
| int version, | ||
| Iterable<Package> packages, [ | ||
| Object? extraData, | ||
|
|
@@ -549,13 +556,6 @@ class SimplePackageConfig implements PackageConfig { | |
| }, extraData); | ||
| } | ||
|
|
||
| SimplePackageConfig._( | ||
| this.version, | ||
| this._packageTree, | ||
| this._packages, | ||
| this.extraData, | ||
| ); | ||
|
|
||
| /// Creates empty configuration. | ||
| /// | ||
| /// The empty configuration can be used in cases where no configuration is | ||
|
|
@@ -738,28 +738,20 @@ class SimplePackageConfig implements PackageConfig { | |
|
|
||
| /// Configuration data for a single package. | ||
| @sealed | ||
| class SimplePackage implements Package { | ||
| class SimplePackage._( | ||
| @override | ||
| final String name; | ||
| final String name, | ||
| @override | ||
| final Uri root; | ||
| final Uri root, | ||
| @override | ||
| final Uri packageUriRoot; | ||
| final Uri packageUriRoot, | ||
| @override | ||
| final LanguageVersion? languageVersion; | ||
| final LanguageVersion? languageVersion, | ||
| @override | ||
| final Object? extraData; | ||
| final Object? extraData, | ||
| @override | ||
| final bool relativeRoot; | ||
|
|
||
| SimplePackage._( | ||
| this.name, | ||
| this.root, | ||
| this.packageUriRoot, | ||
| this.languageVersion, | ||
| this.extraData, | ||
| this.relativeRoot, | ||
| ); | ||
| final bool relativeRoot, | ||
| ) implements Package { | ||
|
|
||
| /// Creates a [SimplePackage] with the provided content. | ||
| /// | ||
|
|
@@ -941,19 +933,17 @@ LanguageVersion parseLanguageVersion( | |
| } | ||
|
|
||
| @sealed | ||
| class SimpleLanguageVersion implements LanguageVersion { | ||
| class SimpleLanguageVersion( | ||
| @override | ||
| final int major; | ||
| final int major, | ||
| @override | ||
| final int minor; | ||
|
|
||
| final int minor, | ||
| /// A cache for `toString`, pre-filled with source if created by parsing. | ||
| /// | ||
| /// Also used by [SimpleInvalidLanguageVersion] for its invalid source | ||
| /// or a suitably invalid `toString` value. | ||
| String? _source; | ||
|
|
||
| SimpleLanguageVersion(this.major, this.minor, this._source); | ||
| String? _source, | ||
| ) implements LanguageVersion { | ||
|
|
||
| @override | ||
| bool operator ==(Object other) => | ||
|
|
@@ -974,22 +964,22 @@ class SimpleLanguageVersion implements LanguageVersion { | |
| } | ||
|
|
||
| @sealed | ||
| class SimpleInvalidLanguageVersion extends SimpleLanguageVersion | ||
| class SimpleInvalidLanguageVersion(String source) | ||
| extends SimpleLanguageVersion(-1, -1, source) | ||
lrhn marked this conversation as resolved.
Show resolved
Hide resolved
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without super-class arguments, this will be an in-body new(String source): super(-1, -1, source);Just wanted to show what it would look like with super-class arguments. (Because I probably wouldn't use a primary constructor without it.) |
||
| implements InvalidLanguageVersion { | ||
| SimpleInvalidLanguageVersion(String source) : super(-1, -1, source); | ||
|
|
||
| @override | ||
| int get hashCode => identityHashCode(this); | ||
| @override | ||
| bool operator ==(Object other) => identical(this, other); | ||
| } | ||
|
|
||
| abstract class PackageTree { | ||
| abstract interface class PackageTree { | ||
| Iterable<Package> get allPackages; | ||
| SimplePackage? packageOf(Uri file); | ||
| } | ||
|
|
||
| class _PackageTrieNode { | ||
| class _PackageTrieNode() { | ||
| SimplePackage? package; | ||
|
|
||
| /// Indexed by path segment. | ||
|
|
@@ -1008,7 +998,7 @@ class _PackageTrieNode { | |
| /// The package root path of a package must not be inside another package's | ||
| /// root path. | ||
| /// Entire other packages are allowed inside a package's root. | ||
| class TriePackageTree implements PackageTree { | ||
| class TriePackageTree() implements PackageTree { | ||
| /// Indexed by URI scheme. | ||
| final Map<String, _PackageTrieNode> _map = {}; | ||
|
|
||
|
|
@@ -1155,9 +1145,7 @@ class TriePackageTree implements PackageTree { | |
| } | ||
| } | ||
|
|
||
| class EmptyPackageTree implements PackageTree { | ||
| const EmptyPackageTree(); | ||
|
|
||
| class const EmptyPackageTree() implements PackageTree { | ||
| @override | ||
| Iterable<Package> get allPackages => const Iterable<Package>.empty(); | ||
|
|
||
|
|
@@ -1184,18 +1172,16 @@ enum ConflictType { sameRoots, interleaving, insidePackageRoot } | |
| /// The [package] conflicts with [existingPackage] if it has | ||
| /// the same root path or the package URI root path | ||
| /// of [existingPackage] is inside the root path of [package]. | ||
| class ConflictException { | ||
| class ConflictException( | ||
| /// The existing package that [package] conflicts with. | ||
| final SimplePackage existingPackage; | ||
|
|
||
| final SimplePackage existingPackage, | ||
| /// The package that could not be added without a conflict. | ||
| final SimplePackage package; | ||
|
|
||
| final SimplePackage package, | ||
| /// Whether the conflict is with the package URI root of [existingPackage]. | ||
| final ConflictType conflictType; | ||
|
|
||
| final ConflictType conflictType, | ||
| ) { | ||
| /// Creates a root conflict between [package] and [existingPackage]. | ||
| ConflictException(this.package, this.existingPackage, this.conflictType); | ||
| this; | ||
| } | ||
|
|
||
| /// Used for sorting packages by root path. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially made this a primary constructor (using super-class arguments), but since all construction needs to go through the primary constructor, and this constructor restricts the types to non-nullable to require a name and message, the
from()constructor could not redirect to it.(That could be an argument for preferring an in-body declaring constructor, if you want other initializing constructors on the same class, which cannot be made to forward to the primary constructor.)