@@ -26,17 +26,9 @@ class DogStructureField extends RetainedAnnotationHolder
26
26
/// Declared type of the structure.
27
27
final QualifiedTypeTree type;
28
28
29
- /// Serial type of the structure.
30
- /// If the declared type is [Iterable] , [List] or [Set] , the type argument
31
- /// of the iterable will be the serial type.
32
- final TypeCapture serial;
33
-
34
29
/// Optional converter type override.
35
30
final Type ? converterType;
36
31
37
- /// Type of the iterable, if this field is iterable.
38
- final IterableKind iterableKind;
39
-
40
32
/// The name of the field.
41
33
final String name;
42
34
@@ -49,18 +41,39 @@ class DogStructureField extends RetainedAnnotationHolder
49
41
@override
50
42
final List <RetainedAnnotation > annotations;
51
43
44
+ /// The kind of iterable this field is.
45
+ ///
46
+ /// NOTE: Originally, this was a custom field that has since been removed and
47
+ /// replaced with this getter for compatibility reasons.
48
+ IterableKind get iterableKind {
49
+ if (type.arguments.length == 1 ) {
50
+ final base = type.base .typeArgument;
51
+ if (base == List ) {
52
+ return IterableKind .list;
53
+ } else if (base == Set ) {
54
+ return IterableKind .set ;
55
+ }
56
+ }
57
+ return IterableKind .none;
58
+ }
59
+
60
+ /// Returns the serial type of this field.
61
+ ///
62
+ /// NOTE: Originally, this was a custom field that has since been removed and
63
+ /// replaced with this getter for compatibility reasons.
64
+ TypeCapture get serial {
65
+ if (iterableKind == IterableKind .none) {
66
+ return type.qualified;
67
+ } else {
68
+ return type.arguments[0 ].qualified;
69
+ }
70
+ }
71
+
52
72
/// Creates a new [DogStructureField] .
53
73
///
54
74
/// See also: https://dogs.helight.dev/advanced/structures
55
- const DogStructureField (
56
- this .type,
57
- this .serial,
58
- this .converterType,
59
- this .iterableKind,
60
- this .name,
61
- this .optional,
62
- this .structure,
63
- this .annotations);
75
+ const DogStructureField (this .type, this .converterType, this .name,
76
+ this .optional, this .structure, this .annotations);
64
77
65
78
@override
66
79
String toString () {
@@ -70,80 +83,80 @@ class DogStructureField extends RetainedAnnotationHolder
70
83
/// Creates a synthetic [String] field.
71
84
factory DogStructureField .string (String name,
72
85
{bool optional = false ,
73
- IterableKind iterable = IterableKind .none,
74
- Type ? converterType,
75
- List <RetainedAnnotation > annotations = const []}) {
86
+ IterableKind iterable = IterableKind .none,
87
+ Type ? converterType,
88
+ List <RetainedAnnotation > annotations = const []}) {
76
89
var type = QualifiedTypeTree .terminal <String >();
77
90
if (iterable == IterableKind .list) {
78
91
type = QualifiedTypeTree .list <String >();
79
92
} else if (iterable == IterableKind .set ) {
80
93
type = QualifiedTypeTree .set <String >();
81
94
}
82
- return DogStructureField (type, TypeToken < String >(), converterType, iterable,
83
- name, optional, false , annotations);
95
+ return DogStructureField (
96
+ type, converterType, name, optional, false , annotations);
84
97
}
85
98
86
99
/// Creates a synthetic [int] field.
87
100
factory DogStructureField .int (String name,
88
101
{bool optional = false ,
89
- IterableKind iterable = IterableKind .none,
90
- Type ? converterType,
91
- List <RetainedAnnotation > annotations = const []}) {
102
+ IterableKind iterable = IterableKind .none,
103
+ Type ? converterType,
104
+ List <RetainedAnnotation > annotations = const []}) {
92
105
var type = QualifiedTypeTree .terminal <int >();
93
106
if (iterable == IterableKind .list) {
94
107
type = QualifiedTypeTree .list <int >();
95
108
} else if (iterable == IterableKind .set ) {
96
109
type = QualifiedTypeTree .set <int >();
97
110
}
98
- return DogStructureField (type, TypeToken < int >(), converterType, iterable,
99
- name, optional, false , annotations);
111
+ return DogStructureField (
112
+ type, converterType, name, optional, false , annotations);
100
113
}
101
114
102
115
/// Creates a synthetic [double] field.
103
116
factory DogStructureField .double (String name,
104
117
{bool optional = false ,
105
- IterableKind iterable = IterableKind .none,
106
- Type ? converterType,
107
- List <RetainedAnnotation > annotations = const []}) {
118
+ IterableKind iterable = IterableKind .none,
119
+ Type ? converterType,
120
+ List <RetainedAnnotation > annotations = const []}) {
108
121
var type = QualifiedTypeTree .terminal <double >();
109
122
if (iterable == IterableKind .list) {
110
123
type = QualifiedTypeTree .list <double >();
111
124
} else if (iterable == IterableKind .set ) {
112
125
type = QualifiedTypeTree .set <double >();
113
126
}
114
- return DogStructureField (type, TypeToken < double >(), converterType, iterable,
115
- name, optional, false , annotations);
127
+ return DogStructureField (
128
+ type, converterType, name, optional, false , annotations);
116
129
}
117
130
118
131
/// Creates a synthetic [bool] field.
119
132
factory DogStructureField .bool (String name,
120
133
{bool optional = false ,
121
- IterableKind iterable = IterableKind .none,
122
- Type ? converterType,
123
- List <RetainedAnnotation > annotations = const []}) {
134
+ IterableKind iterable = IterableKind .none,
135
+ Type ? converterType,
136
+ List <RetainedAnnotation > annotations = const []}) {
124
137
var type = QualifiedTypeTree .terminal <bool >();
125
138
if (iterable == IterableKind .list) {
126
139
type = QualifiedTypeTree .list <bool >();
127
140
} else if (iterable == IterableKind .set ) {
128
141
type = QualifiedTypeTree .set <bool >();
129
142
}
130
- return DogStructureField (type, TypeToken < bool >(), converterType, iterable,
131
- name, optional, false , annotations);
143
+ return DogStructureField (
144
+ type, converterType, name, optional, false , annotations);
132
145
}
133
146
134
147
/// Creates a synthetic field for a terminal serial type.
135
148
static DogStructureField create <TYPE >(String name,
136
149
{bool optional = false ,
137
- IterableKind iterable = IterableKind .none,
138
- Type ? converterType,
139
- List <RetainedAnnotation > annotations = const []}) {
150
+ IterableKind iterable = IterableKind .none,
151
+ Type ? converterType,
152
+ List <RetainedAnnotation > annotations = const []}) {
140
153
var type = QualifiedTypeTree .terminal <TYPE >();
141
154
if (iterable == IterableKind .list) {
142
155
type = QualifiedTypeTree .list <TYPE >();
143
156
} else if (iterable == IterableKind .set ) {
144
157
type = QualifiedTypeTree .set <TYPE >();
145
158
}
146
- return DogStructureField (type, TypeToken < TYPE >(), converterType, iterable,
147
- name, optional, false , annotations);
159
+ return DogStructureField (
160
+ type, converterType, name, optional, false , annotations);
148
161
}
149
162
}
0 commit comments