4
4
5
5
import 'dart:typed_data' ;
6
6
7
+ import 'package:meta/meta.dart' show sealed;
8
+
7
9
import 'errors.dart' ;
8
10
import 'package_config_json.dart' ;
9
11
import 'util.dart' ;
@@ -15,7 +17,8 @@ import 'util.dart';
15
17
/// More members may be added to this class in the future,
16
18
/// so classes outside of this package must not implement [PackageConfig]
17
19
/// or any subclass of it.
18
- abstract final class PackageConfig {
20
+ @sealed
21
+ abstract class PackageConfig {
19
22
/// The lowest configuration version currently supported.
20
23
static const int minVersion = 2 ;
21
24
@@ -213,7 +216,8 @@ abstract final class PackageConfig {
213
216
}
214
217
215
218
/// Configuration data for a single package.
216
- abstract final class Package {
219
+ @sealed
220
+ abstract class Package {
217
221
/// Creates a package with the provided properties.
218
222
///
219
223
/// The [name] must be a valid package name.
@@ -301,7 +305,8 @@ abstract final class Package {
301
305
/// If errors during parsing are handled using an `onError` handler,
302
306
/// then an *invalid* language version may be represented by an
303
307
/// [InvalidLanguageVersion] object.
304
- abstract final class LanguageVersion implements Comparable <LanguageVersion > {
308
+ @sealed
309
+ abstract class LanguageVersion implements Comparable <LanguageVersion > {
305
310
/// The maximal value allowed by [major] and [minor] values;
306
311
static const int maxValue = 0x7FFFFFFF ;
307
312
@@ -368,40 +373,6 @@ abstract final class LanguageVersion implements Comparable<LanguageVersion> {
368
373
@override
369
374
int compareTo (LanguageVersion other);
370
375
371
- /// Whether this language version is less than [other] .
372
- ///
373
- /// If either version being compared is an [InvalidLanguageVersion] ,
374
- /// a [StateError] is thrown. Verify versions are valid before comparing them.
375
- ///
376
- /// For details on how valid language versions are compared,
377
- /// check out [LanguageVersion.compareTo] .
378
- bool operator < (LanguageVersion other);
379
-
380
- /// Whether this language version is less than or equal to [other] .
381
- ///
382
- /// If either version being compared is an [InvalidLanguageVersion] ,
383
- /// a [StateError] is thrown. Verify versions are valid before comparing them.
384
- ///
385
- /// For details on how valid language versions are compared,
386
- /// check out [LanguageVersion.compareTo] .
387
- bool operator <= (LanguageVersion other);
388
-
389
- /// Whether this language version is greater than [other] .
390
- ///
391
- /// Neither version being compared must be an [InvalidLanguageVersion] .
392
- ///
393
- /// For details on how valid language versions are compared,
394
- /// check out [LanguageVersion.compareTo] .
395
- bool operator > (LanguageVersion other);
396
-
397
- /// Whether this language version is greater than or equal to [other] .
398
- ///
399
- /// Neither version being compared must be an [InvalidLanguageVersion] .
400
- ///
401
- /// For details on how valid language versions are compared,
402
- /// check out [LanguageVersion.compareTo] .
403
- bool operator >= (LanguageVersion other);
404
-
405
376
/// Valid language versions with the same [major] and [minor] values are
406
377
/// equal.
407
378
///
@@ -428,7 +399,8 @@ abstract final class LanguageVersion implements Comparable<LanguageVersion> {
428
399
/// which did not throw on an error.
429
400
/// The caller which provided the `onError` handler which was called
430
401
/// should be prepared to encounter invalid values.
431
- abstract final class InvalidLanguageVersion implements LanguageVersion {
402
+ @sealed
403
+ abstract class InvalidLanguageVersion implements LanguageVersion {
432
404
/// The value -1 for an invalid language version.
433
405
@override
434
406
int get major;
@@ -449,14 +421,83 @@ abstract final class InvalidLanguageVersion implements LanguageVersion {
449
421
String toString ();
450
422
}
451
423
424
+ /// Relational operators for [LanguageVersion] .
425
+ ///
426
+ /// Compares valid versions with [LanguageVersion.compareTo] ,
427
+ /// and rejects invalid versions.
428
+ ///
429
+ /// Versions should be verified as valid before using them.
430
+ extension LanguageVersionRelationalOperators on LanguageVersion {
431
+ /// Whether this language version is less than [other] .
432
+ ///
433
+ /// Neither version being compared must be an [InvalidLanguageVersion] .
434
+ ///
435
+ /// For details on how valid language versions are compared,
436
+ /// check out [LanguageVersion.compareTo] .
437
+ bool operator < (LanguageVersion other) {
438
+ // Throw an error if comparing an invalid language version.
439
+ if (this is InvalidLanguageVersion ) _throwThisInvalid ();
440
+ if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
441
+ return compareTo (other) < 0 ;
442
+ }
443
+
444
+ /// Whether this language version is less than or equal to [other] .
445
+ ///
446
+ /// Neither version being compared must be an [InvalidLanguageVersion] .
447
+ ///
448
+ /// For details on how valid language versions are compared,
449
+ /// check out [LanguageVersion.compareTo] .
450
+ bool operator <= (LanguageVersion other) {
451
+ // Throw an error if comparing an invalid language version.
452
+ if (this is InvalidLanguageVersion ) _throwThisInvalid ();
453
+ if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
454
+ return compareTo (other) <= 0 ;
455
+ }
456
+
457
+ /// Whether this language version is greater than [other] .
458
+ ///
459
+ /// Neither version being compared must be an [InvalidLanguageVersion] .
460
+ ///
461
+ /// For details on how valid language versions are compared,
462
+ /// check out [LanguageVersion.compareTo] .
463
+ bool operator > (LanguageVersion other) {
464
+ // Throw an error if comparing an invalid language version.
465
+ if (this is InvalidLanguageVersion ) _throwThisInvalid ();
466
+ if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
467
+ return compareTo (other) > 0 ;
468
+ }
469
+
470
+ /// Whether this language version is greater than or equal to [other] .
471
+ ///
472
+ /// If either version being compared is an [InvalidLanguageVersion] ,
473
+ /// a [StateError] is thrown. Verify versions are valid before comparing them.
474
+ ///
475
+ /// For details on how valid language versions are compared,
476
+ /// check out [LanguageVersion.compareTo] .
477
+ bool operator >= (LanguageVersion other) {
478
+ // Throw an error if comparing an invalid language version.
479
+ if (this is InvalidLanguageVersion ) _throwThisInvalid ();
480
+ if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
481
+ return compareTo (other) >= 0 ;
482
+ }
483
+
484
+ static Never _throwThisInvalid () => throw UnsupportedError (
485
+ 'Can\' t compare an invalid language version to another language version. '
486
+ 'Verify language versions are valid before use.' );
487
+ static Never _throwOtherInvalid () => throw UnsupportedError (
488
+ 'Can\' t compare a language version to an invalid language version. '
489
+ 'Verify language versions are valid before use.' );
490
+ }
491
+
452
492
// --------------------------------------------------------------------
453
- // Implementation of interfaces.
493
+ // Implementation of interfaces. Not exported by top-level libraries.
454
494
455
495
const bool _disallowPackagesInsidePackageUriRoot = false ;
456
496
457
497
// Implementations of the main data types exposed by the API of this package.
458
498
459
- final class SimplePackageConfig implements PackageConfig {
499
+ @sealed
500
+ class SimplePackageConfig implements PackageConfig {
460
501
@override
461
502
final int version;
462
503
final Map <String , Package > _packages;
@@ -620,7 +661,8 @@ final class SimplePackageConfig implements PackageConfig {
620
661
}
621
662
622
663
/// Configuration data for a single package.
623
- final class SimplePackage implements Package {
664
+ @sealed
665
+ class SimplePackage implements Package {
624
666
@override
625
667
final String name;
626
668
@override
@@ -779,7 +821,8 @@ LanguageVersion parseLanguageVersion(
779
821
return SimpleLanguageVersion (major, minor, source);
780
822
}
781
823
782
- abstract final class _SimpleLanguageVersionBase implements LanguageVersion {
824
+ @sealed
825
+ abstract class _SimpleLanguageVersionBase implements LanguageVersion {
783
826
@override
784
827
int compareTo (LanguageVersion other) {
785
828
var result = major - other.major;
@@ -788,7 +831,8 @@ abstract final class _SimpleLanguageVersionBase implements LanguageVersion {
788
831
}
789
832
}
790
833
791
- final class SimpleLanguageVersion extends _SimpleLanguageVersionBase {
834
+ @sealed
835
+ class SimpleLanguageVersion extends _SimpleLanguageVersionBase {
792
836
@override
793
837
final int major;
794
838
@override
@@ -805,66 +849,10 @@ final class SimpleLanguageVersion extends _SimpleLanguageVersionBase {
805
849
806
850
@override
807
851
String toString () => _source ?? = '$major .$minor ' ;
808
-
809
- /// Whether this language version is less than [other] .
810
- ///
811
- /// Neither version being compared must be an [InvalidLanguageVersion] .
812
- ///
813
- /// For details on how valid language versions are compared,
814
- /// check out [LanguageVersion.compareTo] .
815
- @override
816
- bool operator < (LanguageVersion other) {
817
- // Throw an error if comparing with an invalid language version.
818
- if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
819
-
820
- return compareTo (other) < 0 ;
821
- }
822
-
823
- /// Whether this language version is less than or equal to [other] .
824
- ///
825
- /// Neither version being compared must be an [InvalidLanguageVersion] .
826
- ///
827
- /// For details on how valid language versions are compared,
828
- /// check out [LanguageVersion.compareTo] .
829
- @override
830
- bool operator <= (LanguageVersion other) {
831
- // Throw an error if comparing with an invalid language version.
832
- if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
833
- return compareTo (other) <= 0 ;
834
- }
835
-
836
- /// Whether this language version is greater than [other] .
837
- ///
838
- /// Neither version being compared must be an [InvalidLanguageVersion] .
839
- ///
840
- /// For details on how valid language versions are compared,
841
- /// check out [LanguageVersion.compareTo] .
842
- @override
843
- bool operator > (LanguageVersion other) {
844
- if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
845
- return compareTo (other) > 0 ;
846
- }
847
-
848
- /// Whether this language version is greater than or equal to [other] .
849
- ///
850
- /// If either version being compared is an [InvalidLanguageVersion] ,
851
- /// a [StateError] is thrown. Verify versions are valid before comparing them.
852
- ///
853
- /// For details on how valid language versions are compared,
854
- /// check out [LanguageVersion.compareTo] .
855
- @override
856
- bool operator >= (LanguageVersion other) {
857
- // Throw an error if comparing with an invalid language version.
858
- if (other is InvalidLanguageVersion ) _throwOtherInvalid ();
859
- return compareTo (other) >= 0 ;
860
- }
861
-
862
- static Never _throwOtherInvalid () => throw StateError (
863
- 'Can\' t compare a language version to an invalid language version. '
864
- 'Verify language versions are valid after parsing.' );
865
852
}
866
853
867
- final class SimpleInvalidLanguageVersion extends _SimpleLanguageVersionBase
854
+ @sealed
855
+ class SimpleInvalidLanguageVersion extends _SimpleLanguageVersionBase
868
856
implements InvalidLanguageVersion {
869
857
final String ? _source;
870
858
SimpleInvalidLanguageVersion (this ._source);
@@ -873,32 +861,8 @@ final class SimpleInvalidLanguageVersion extends _SimpleLanguageVersionBase
873
861
@override
874
862
int get minor => - 1 ;
875
863
876
- @override
877
- bool operator < (LanguageVersion other) {
878
- _throwThisInvalid ();
879
- }
880
-
881
- @override
882
- bool operator <= (LanguageVersion other) {
883
- _throwThisInvalid ();
884
- }
885
-
886
- @override
887
- bool operator > (LanguageVersion other) {
888
- _throwThisInvalid ();
889
- }
890
-
891
- @override
892
- bool operator >= (LanguageVersion other) {
893
- _throwThisInvalid ();
894
- }
895
-
896
864
@override
897
865
String toString () => _source! ;
898
-
899
- static Never _throwThisInvalid () => throw StateError (
900
- 'Can\' t compare an invalid language version to another language version. '
901
- 'Verify language versions are valid after parsing.' );
902
866
}
903
867
904
868
abstract class PackageTree {
0 commit comments