@@ -65,6 +65,12 @@ extension UnknownDeclSyntax: CustomReflectable {
65
65
// MARK: - MissingDeclSyntax
66
66
67
67
public struct MissingDeclSyntax : DeclSyntaxProtocol , SyntaxHashable {
68
+ enum Cursor : Int {
69
+ case garbageBeforeAttributes
70
+ case attributes
71
+ case garbageBetweenAttributesAndModifiers
72
+ case modifiers
73
+ }
68
74
69
75
public let _syntaxNode : Syntax
70
76
@@ -97,16 +103,178 @@ public struct MissingDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
97
103
return Swift . type ( of: self )
98
104
}
99
105
106
+ public var garbageBeforeAttributes : GarbageNodesSyntax ? {
107
+ get {
108
+ let childData = data. child ( at: Cursor . garbageBeforeAttributes,
109
+ parent: Syntax ( self ) )
110
+ if childData == nil { return nil }
111
+ return GarbageNodesSyntax ( childData!)
112
+ }
113
+ set ( value) {
114
+ self = withGarbageBeforeAttributes ( value)
115
+ }
116
+ }
117
+
118
+ /// Returns a copy of the receiver with its `garbageBeforeAttributes` replaced.
119
+ /// - param newChild: The new `garbageBeforeAttributes` to replace the node's
120
+ /// current `garbageBeforeAttributes`, if present.
121
+ public func withGarbageBeforeAttributes(
122
+ _ newChild: GarbageNodesSyntax ? ) -> MissingDeclSyntax {
123
+ let raw = newChild? . raw
124
+ let newData = data. replacingChild ( raw, at: Cursor . garbageBeforeAttributes)
125
+ return MissingDeclSyntax ( newData)
126
+ }
127
+
128
+ public var attributes : AttributeListSyntax ? {
129
+ get {
130
+ let childData = data. child ( at: Cursor . attributes,
131
+ parent: Syntax ( self ) )
132
+ if childData == nil { return nil }
133
+ return AttributeListSyntax ( childData!)
134
+ }
135
+ set ( value) {
136
+ self = withAttributes ( value)
137
+ }
138
+ }
139
+
140
+ /// Adds the provided `Attribute` to the node's `attributes`
141
+ /// collection.
142
+ /// - param element: The new `Attribute` to add to the node's
143
+ /// `attributes` collection.
144
+ /// - returns: A copy of the receiver with the provided `Attribute`
145
+ /// appended to its `attributes` collection.
146
+ public func addAttribute( _ element: Syntax ) -> MissingDeclSyntax {
147
+ var collection : RawSyntax
148
+ if let col = raw [ Cursor . attributes] {
149
+ collection = col. appending ( element. raw)
150
+ } else {
151
+ collection = RawSyntax . create ( kind: SyntaxKind . attributeList,
152
+ layout: [ element. raw] , length: element. raw. totalLength, presence: . present)
153
+ }
154
+ let newData = data. replacingChild ( collection,
155
+ at: Cursor . attributes)
156
+ return MissingDeclSyntax ( newData)
157
+ }
158
+
159
+ /// Returns a copy of the receiver with its `attributes` replaced.
160
+ /// - param newChild: The new `attributes` to replace the node's
161
+ /// current `attributes`, if present.
162
+ public func withAttributes(
163
+ _ newChild: AttributeListSyntax ? ) -> MissingDeclSyntax {
164
+ let raw = newChild? . raw
165
+ let newData = data. replacingChild ( raw, at: Cursor . attributes)
166
+ return MissingDeclSyntax ( newData)
167
+ }
168
+
169
+ public var garbageBetweenAttributesAndModifiers : GarbageNodesSyntax ? {
170
+ get {
171
+ let childData = data. child ( at: Cursor . garbageBetweenAttributesAndModifiers,
172
+ parent: Syntax ( self ) )
173
+ if childData == nil { return nil }
174
+ return GarbageNodesSyntax ( childData!)
175
+ }
176
+ set ( value) {
177
+ self = withGarbageBetweenAttributesAndModifiers ( value)
178
+ }
179
+ }
180
+
181
+ /// Returns a copy of the receiver with its `garbageBetweenAttributesAndModifiers` replaced.
182
+ /// - param newChild: The new `garbageBetweenAttributesAndModifiers` to replace the node's
183
+ /// current `garbageBetweenAttributesAndModifiers`, if present.
184
+ public func withGarbageBetweenAttributesAndModifiers(
185
+ _ newChild: GarbageNodesSyntax ? ) -> MissingDeclSyntax {
186
+ let raw = newChild? . raw
187
+ let newData = data. replacingChild ( raw, at: Cursor . garbageBetweenAttributesAndModifiers)
188
+ return MissingDeclSyntax ( newData)
189
+ }
190
+
191
+ public var modifiers : ModifierListSyntax ? {
192
+ get {
193
+ let childData = data. child ( at: Cursor . modifiers,
194
+ parent: Syntax ( self ) )
195
+ if childData == nil { return nil }
196
+ return ModifierListSyntax ( childData!)
197
+ }
198
+ set ( value) {
199
+ self = withModifiers ( value)
200
+ }
201
+ }
202
+
203
+ /// Adds the provided `Modifier` to the node's `modifiers`
204
+ /// collection.
205
+ /// - param element: The new `Modifier` to add to the node's
206
+ /// `modifiers` collection.
207
+ /// - returns: A copy of the receiver with the provided `Modifier`
208
+ /// appended to its `modifiers` collection.
209
+ public func addModifier( _ element: DeclModifierSyntax ) -> MissingDeclSyntax {
210
+ var collection : RawSyntax
211
+ if let col = raw [ Cursor . modifiers] {
212
+ collection = col. appending ( element. raw)
213
+ } else {
214
+ collection = RawSyntax . create ( kind: SyntaxKind . modifierList,
215
+ layout: [ element. raw] , length: element. raw. totalLength, presence: . present)
216
+ }
217
+ let newData = data. replacingChild ( collection,
218
+ at: Cursor . modifiers)
219
+ return MissingDeclSyntax ( newData)
220
+ }
221
+
222
+ /// Returns a copy of the receiver with its `modifiers` replaced.
223
+ /// - param newChild: The new `modifiers` to replace the node's
224
+ /// current `modifiers`, if present.
225
+ public func withModifiers(
226
+ _ newChild: ModifierListSyntax ? ) -> MissingDeclSyntax {
227
+ let raw = newChild? . raw
228
+ let newData = data. replacingChild ( raw, at: Cursor . modifiers)
229
+ return MissingDeclSyntax ( newData)
230
+ }
231
+
100
232
101
233
public func _validateLayout( ) {
102
234
let rawChildren = Array ( RawSyntaxChildren ( Syntax ( self ) ) )
103
- assert ( rawChildren. count == 0 )
235
+ assert ( rawChildren. count == 4 )
236
+ // Check child #0 child is GarbageNodesSyntax or missing
237
+ if let raw = rawChildren [ 0 ] . raw {
238
+ let info = rawChildren [ 0 ] . syntaxInfo
239
+ let absoluteRaw = AbsoluteRawSyntax ( raw: raw, info: info)
240
+ let syntaxData = SyntaxData ( absoluteRaw, parent: Syntax ( self ) )
241
+ let syntaxChild = Syntax ( syntaxData)
242
+ assert ( syntaxChild. is ( GarbageNodesSyntax . self) )
243
+ }
244
+ // Check child #1 child is AttributeListSyntax or missing
245
+ if let raw = rawChildren [ 1 ] . raw {
246
+ let info = rawChildren [ 1 ] . syntaxInfo
247
+ let absoluteRaw = AbsoluteRawSyntax ( raw: raw, info: info)
248
+ let syntaxData = SyntaxData ( absoluteRaw, parent: Syntax ( self ) )
249
+ let syntaxChild = Syntax ( syntaxData)
250
+ assert ( syntaxChild. is ( AttributeListSyntax . self) )
251
+ }
252
+ // Check child #2 child is GarbageNodesSyntax or missing
253
+ if let raw = rawChildren [ 2 ] . raw {
254
+ let info = rawChildren [ 2 ] . syntaxInfo
255
+ let absoluteRaw = AbsoluteRawSyntax ( raw: raw, info: info)
256
+ let syntaxData = SyntaxData ( absoluteRaw, parent: Syntax ( self ) )
257
+ let syntaxChild = Syntax ( syntaxData)
258
+ assert ( syntaxChild. is ( GarbageNodesSyntax . self) )
259
+ }
260
+ // Check child #3 child is ModifierListSyntax or missing
261
+ if let raw = rawChildren [ 3 ] . raw {
262
+ let info = rawChildren [ 3 ] . syntaxInfo
263
+ let absoluteRaw = AbsoluteRawSyntax ( raw: raw, info: info)
264
+ let syntaxData = SyntaxData ( absoluteRaw, parent: Syntax ( self ) )
265
+ let syntaxChild = Syntax ( syntaxData)
266
+ assert ( syntaxChild. is ( ModifierListSyntax . self) )
267
+ }
104
268
}
105
269
}
106
270
107
271
extension MissingDeclSyntax : CustomReflectable {
108
272
public var customMirror : Mirror {
109
273
return Mirror ( self , children: [
274
+ " garbageBeforeAttributes " : garbageBeforeAttributes. map ( Syntax . init) ? . asProtocol ( SyntaxProtocol . self) as Any ,
275
+ " attributes " : attributes. map ( Syntax . init) ? . asProtocol ( SyntaxProtocol . self) as Any ,
276
+ " garbageBetweenAttributesAndModifiers " : garbageBetweenAttributesAndModifiers. map ( Syntax . init) ? . asProtocol ( SyntaxProtocol . self) as Any ,
277
+ " modifiers " : modifiers. map ( Syntax . init) ? . asProtocol ( SyntaxProtocol . self) as Any ,
110
278
] )
111
279
}
112
280
}
0 commit comments