@@ -29,103 +29,95 @@ class Target {
29
29
30
30
/// An enumeration of the kinds of targets to which an annotation can be
31
31
/// applied.
32
- ///
33
- /// More values will be added in the future, as the Dart language evolves.
34
- class TargetKind {
35
- // This class is not meant to be instantiated or extended; this constructor
36
- // prevents instantiation and extension.
37
- const TargetKind ._(this .displayString, this .name);
38
-
39
- /// A numeric identifier for the enumerated value.
40
- int get index => values.indexOf (this );
41
-
42
- /// A user visible string used to describe this target kind.
43
- final String displayString;
44
-
45
- /// The name of the [TargetKind] value.
46
- ///
47
- /// The name is a string containing the source identifier used to declare the [TargetKind] value.
48
- /// For example, the result of `TargetKind.classType.name` is the string "classType".
49
- final String name;
50
-
32
+ enum TargetKind {
51
33
/// Indicates that an annotation is valid on any class declaration.
52
- static const classType = TargetKind ._( 'classes' , 'classType' );
34
+ classType,
53
35
54
36
/// Indicates that an annotation is valid on any enum declaration.
55
- static const enumType = TargetKind ._( 'enums' , 'enumType' );
37
+ enumType,
56
38
57
39
/// Indicates that an annotation is valid on any extension declaration.
58
- static const extension = TargetKind ._( 'extensions' , 'extension' );
40
+ extension ,
59
41
60
42
/// Indicates that an annotation is valid on any field declaration, both
61
43
/// instance and static fields, whether it's in a class, mixin or extension.
62
- static const field = TargetKind ._( 'fields' , 'field' );
44
+ field,
63
45
64
46
/// Indicates that an annotation is valid on any top-level function
65
47
/// declaration.
66
- static const function = TargetKind ._( 'top-level functions' , 'function' );
48
+ function,
67
49
68
50
/// Indicates that an annotation is valid on the first directive in a library,
69
51
/// whether that's a `library` , `import` , `export` or `part` directive. This
70
52
/// doesn't include the `part of` directive in a part file.
71
- static const library = TargetKind ._( 'libraries' , 'library' );
53
+ library,
72
54
73
55
/// Indicates that an annotation is valid on any getter declaration, both
74
56
/// instance or static getters, whether it's in a class, mixin, extension, or
75
57
/// at the top-level of a library.
76
- static const getter = TargetKind ._( 'getters' , 'getter' );
58
+ getter,
77
59
78
60
/// Indicates that an annotation is valid on any method declaration, both
79
61
/// instance and static methods, whether it's in a class, mixin or extension.
80
- static const method = TargetKind ._( 'methods' , 'method' );
62
+ method,
81
63
82
64
/// Indicates that an annotation is valid on any mixin declaration.
83
- static const mixinType = TargetKind ._( 'mixins' , 'mixinType' );
65
+ mixinType,
84
66
85
67
/// Indicates that an annotation is valid on any formal parameter declaration,
86
68
/// whether it's in a function, method, constructor, or closure.
87
- static const parameter = TargetKind ._( 'parameters' , 'parameter' );
69
+ parameter,
88
70
89
71
/// Indicates that an annotation is valid on any setter declaration, both
90
72
/// instance or static setters, whether it's in a class, mixin, extension, or
91
73
/// at the top-level of a library.
92
- static const setter = TargetKind ._( 'setters' , 'setter' );
74
+ setter,
93
75
94
76
/// Indicates that an annotation is valid on any top-level variable
95
77
/// declaration.
96
- static const topLevelVariable =
97
- TargetKind ._('top-level variables' , 'topLevelVariable' );
78
+ topLevelVariable,
98
79
99
80
/// Indicates that an annotation is valid on any declaration that introduces a
100
81
/// type. This includes classes, enums, mixins and typedefs, but does not
101
82
/// include extensions because extensions don't introduce a type.
102
- static const type =
103
- TargetKind ._('types (classes, enums, mixins, or typedefs)' , 'type' );
104
-
105
- /// Indicates that an annotation is valid on any typedef declaration.`
106
- static const typedefType = TargetKind ._('typedefs' , 'typedefType' );
107
-
108
- /// Indicates that an annotation is valid on any type parameter declaration.
109
- static const typeParameter = TargetKind ._('type parameters' , 'typeParameter' );
110
-
111
- static const values = [
112
- classType,
113
- enumType,
114
- extension ,
115
- field,
116
- function,
117
- library,
118
- getter,
119
- method,
120
- mixinType,
121
- parameter,
122
- setter,
123
- topLevelVariable,
124
- type,
125
- typedefType,
126
- typeParameter,
127
- ];
128
-
129
- @override
130
- String toString () => 'TargetKind.$name ' ;
83
+ type,
84
+
85
+ /// Indicates that an annotation is valid on any typedef declaration.
86
+ typedefType,
87
+ }
88
+
89
+ extension TargetKindExtension on TargetKind {
90
+ /// Return a user visible string used to describe this target kind.
91
+ String get displayString {
92
+ switch (this ) {
93
+ case TargetKind .classType:
94
+ return 'classes' ;
95
+ case TargetKind .enumType:
96
+ return 'enums' ;
97
+ case TargetKind .extension :
98
+ return 'extensions' ;
99
+ case TargetKind .field:
100
+ return 'fields' ;
101
+ case TargetKind .function:
102
+ return 'top-level functions' ;
103
+ case TargetKind .library:
104
+ return 'libraries' ;
105
+ case TargetKind .getter:
106
+ return 'getters' ;
107
+ case TargetKind .method:
108
+ return 'methods' ;
109
+ case TargetKind .mixinType:
110
+ return 'mixins' ;
111
+ case TargetKind .parameter:
112
+ return 'parameters' ;
113
+ case TargetKind .setter:
114
+ return 'setters' ;
115
+ case TargetKind .topLevelVariable:
116
+ return 'top-level variables' ;
117
+ case TargetKind .type:
118
+ return 'types (classes, enums, mixins, or typedefs)' ;
119
+ case TargetKind .typedefType:
120
+ return 'typedefs' ;
121
+ }
122
+ }
131
123
}
0 commit comments