@@ -16,88 +16,57 @@ final Version dart3_3 = Version(3, 3, 0);
1616@Deprecated ("Prefer to use 'RuleState'" )
1717typedef State = RuleState ;
1818
19- /// A state that marks an analysis rule as deprecated.
20- final class DeprecatedRuleState extends RuleState {
21- /// The optional name of an analysis rule which replaces the rule with this
22- /// state.
23- final String ? replacedBy;
24-
25- const DeprecatedRuleState ._({super .since, this .replacedBy});
26-
27- @override
28- String get label => 'deprecated' ;
29- }
30-
31- /// A state that marks an analysis rule as experimental.
32- final class ExperimentalRuleState extends RuleState {
33- const ExperimentalRuleState ._({super .since});
34-
35- @override
36- String get label => 'experimental' ;
37- }
38-
39- /// A state that marks an analysis rule as for internal (Dart SDK) use only.
40- final class InternalRuleState extends RuleState {
41- const InternalRuleState ._({super .since});
19+ /// Describes the state of an analysis rule.
20+ final class RuleState {
21+ /// An Optional Dart language version that identifies the start of this state.
22+ final Version ? since;
4223
43- @override
44- String get label => 'internal' ;
45- }
24+ final _RuleStateType _type;
4625
47- /// A state that identifies an analysis rule as having been removed.
48- final class RemovedRuleState extends RuleState {
49- /// An optional lint name that replaces the rule with this state.
26+ /// The optional name of an analysis rule which replaces the rule with this
27+ /// state.
5028 final String ? replacedBy;
5129
52- const RemovedRuleState ._({super .since, this .replacedBy});
30+ /// Initializes a state that marks an analysis rule as deprecated.
31+ const RuleState .deprecated ({this .since, this .replacedBy})
32+ : _type = _RuleStateType .deprecated;
5333
54- @override
55- String get label => 'removed' ;
56- }
34+ /// Initializes a state that marks an analysis rule as experimental.
35+ const RuleState .experimental ({this .since})
36+ : _type = _RuleStateType .experimental,
37+ replacedBy = null ;
5738
58- /// Describes the state of a lint.
59- sealed class RuleState {
60- /// An Optional Dart language version that identifies the start of this state.
61- final Version ? since;
39+ /// Initializes a state that marks an analysis rule as for internal (Dart SDK)
40+ /// use only.
41+ const RuleState .internal ({this .since})
42+ : _type = _RuleStateType .internal,
43+ replacedBy = null ;
6244
63- /// Initialize a newly created State object.
64- const RuleState ({this .since});
45+ /// Initializes a state that identifies an analysis rule as having been removed.
46+ const RuleState .removed ({this .since, this .replacedBy})
47+ : _type = _RuleStateType .removed;
6548
66- /// Initialize a newly created deprecated state with given values.
67- const factory RuleState .deprecated ({Version ? since, String ? replacedBy}) =
68- DeprecatedRuleState ._;
49+ /// Initializes a state that marks an analysis rule as stable.
50+ const RuleState .stable ({this .since})
51+ : _type = _RuleStateType .stable,
52+ replacedBy = null ;
6953
70- /// Initialize a newly created experimental state with given values.
71- const factory RuleState .experimental ({Version ? since}) =
72- ExperimentalRuleState ._;
54+ /// Whether this state marks an analysis rule as deprecated.
55+ bool get isDeprecated => _type == _RuleStateType .deprecated;
7356
74- /// Initialize a newly created internal state with given values .
75- const factory RuleState . internal ({ Version ? since}) = InternalRuleState ._ ;
57+ /// Whether this state marks an analysis rule as experimental .
58+ bool get isExperimental => _type == _RuleStateType .experimental ;
7659
77- /// Initialize a newly created removed state with given values.
78- const factory RuleState .removed ({Version ? since, String ? replacedBy}) =
79- RemovedRuleState ._;
60+ /// Whether this state marks an analysis rule as internal.
61+ bool get isInternal => _type == _RuleStateType .internal;
8062
81- /// Initialize a newly created stable state with given values .
82- const factory RuleState . stable ({ Version ? since}) = StableRuleState ._ ;
63+ /// Whether this state marks an analysis rule as removed .
64+ bool get isRemoved => _type == _RuleStateType .removed ;
8365
8466 /// A short description, suitable for displaying in documentation or a
8567 /// diagnostic message.
86- String get label;
68+ String get label => _type.name ;
8769}
8870
89- /// A state that marks an analysis rule as stable.
90- final class StableRuleState extends RuleState {
91- const StableRuleState ._({super .since});
92-
93- @override
94- String get label => 'stable' ;
95- }
96-
97- extension StateExtension on RuleState {
98- bool get isDeprecated => this is DeprecatedRuleState ;
99- bool get isExperimental => this is ExperimentalRuleState ;
100- bool get isInternal => this is InternalRuleState ;
101- bool get isRemoved => this is RemovedRuleState ;
102- bool get isStable => this is StableRuleState ;
103- }
71+ /// The type of a rule state.
72+ enum _RuleStateType { deprecated, experimental, internal, removed, stable }
0 commit comments