19
19
/// DO NOT CONFORM TO THIS PROTOCOL YOURSELF!
20
20
public protocol DeclSyntaxProtocol : SyntaxProtocol { }
21
21
22
+ public extension Syntax {
23
+ /// Check whether the non-type erased version of this syntax node conforms to
24
+ /// DeclSyntaxProtocol.
25
+ func `is`( _: DeclSyntaxProtocol . Protocol ) -> Bool {
26
+ return self . as ( DeclSyntaxProtocol . self) != nil
27
+ }
28
+
29
+ /// Return the non-type erased version of this syntax node if it conforms to
30
+ /// DeclSyntaxProtocol. Otherwise return nil.
31
+ func `as`( _: DeclSyntaxProtocol . Protocol ) -> DeclSyntaxProtocol ? {
32
+ return self . as ( SyntaxProtocol . self) as? DeclSyntaxProtocol
33
+ }
34
+ }
35
+
22
36
public struct DeclSyntax : DeclSyntaxProtocol , SyntaxHashable {
23
37
public let _syntaxNode : Syntax
24
38
@@ -70,7 +84,7 @@ extension DeclSyntax: CustomReflectable {
70
84
/// Reconstructs the real syntax type for this type from the node's kind and
71
85
/// provides a mirror that reflects this type.
72
86
public var customMirror : Mirror {
73
- return Mirror ( reflecting: Syntax ( self ) . _asConcreteType )
87
+ return Mirror ( reflecting: Syntax ( self ) . as ( SyntaxProtocol . self ) )
74
88
}
75
89
}
76
90
@@ -81,6 +95,20 @@ extension DeclSyntax: CustomReflectable {
81
95
/// DO NOT CONFORM TO THIS PROTOCOL YOURSELF!
82
96
public protocol ExprSyntaxProtocol : SyntaxProtocol { }
83
97
98
+ public extension Syntax {
99
+ /// Check whether the non-type erased version of this syntax node conforms to
100
+ /// ExprSyntaxProtocol.
101
+ func `is`( _: ExprSyntaxProtocol . Protocol ) -> Bool {
102
+ return self . as ( ExprSyntaxProtocol . self) != nil
103
+ }
104
+
105
+ /// Return the non-type erased version of this syntax node if it conforms to
106
+ /// ExprSyntaxProtocol. Otherwise return nil.
107
+ func `as`( _: ExprSyntaxProtocol . Protocol ) -> ExprSyntaxProtocol ? {
108
+ return self . as ( SyntaxProtocol . self) as? ExprSyntaxProtocol
109
+ }
110
+ }
111
+
84
112
public struct ExprSyntax : ExprSyntaxProtocol , SyntaxHashable {
85
113
public let _syntaxNode : Syntax
86
114
@@ -132,7 +160,7 @@ extension ExprSyntax: CustomReflectable {
132
160
/// Reconstructs the real syntax type for this type from the node's kind and
133
161
/// provides a mirror that reflects this type.
134
162
public var customMirror : Mirror {
135
- return Mirror ( reflecting: Syntax ( self ) . _asConcreteType )
163
+ return Mirror ( reflecting: Syntax ( self ) . as ( SyntaxProtocol . self ) )
136
164
}
137
165
}
138
166
@@ -143,6 +171,20 @@ extension ExprSyntax: CustomReflectable {
143
171
/// DO NOT CONFORM TO THIS PROTOCOL YOURSELF!
144
172
public protocol StmtSyntaxProtocol : SyntaxProtocol { }
145
173
174
+ public extension Syntax {
175
+ /// Check whether the non-type erased version of this syntax node conforms to
176
+ /// StmtSyntaxProtocol.
177
+ func `is`( _: StmtSyntaxProtocol . Protocol ) -> Bool {
178
+ return self . as ( StmtSyntaxProtocol . self) != nil
179
+ }
180
+
181
+ /// Return the non-type erased version of this syntax node if it conforms to
182
+ /// StmtSyntaxProtocol. Otherwise return nil.
183
+ func `as`( _: StmtSyntaxProtocol . Protocol ) -> StmtSyntaxProtocol ? {
184
+ return self . as ( SyntaxProtocol . self) as? StmtSyntaxProtocol
185
+ }
186
+ }
187
+
146
188
public struct StmtSyntax : StmtSyntaxProtocol , SyntaxHashable {
147
189
public let _syntaxNode : Syntax
148
190
@@ -194,7 +236,7 @@ extension StmtSyntax: CustomReflectable {
194
236
/// Reconstructs the real syntax type for this type from the node's kind and
195
237
/// provides a mirror that reflects this type.
196
238
public var customMirror : Mirror {
197
- return Mirror ( reflecting: Syntax ( self ) . _asConcreteType )
239
+ return Mirror ( reflecting: Syntax ( self ) . as ( SyntaxProtocol . self ) )
198
240
}
199
241
}
200
242
@@ -205,6 +247,20 @@ extension StmtSyntax: CustomReflectable {
205
247
/// DO NOT CONFORM TO THIS PROTOCOL YOURSELF!
206
248
public protocol TypeSyntaxProtocol : SyntaxProtocol { }
207
249
250
+ public extension Syntax {
251
+ /// Check whether the non-type erased version of this syntax node conforms to
252
+ /// TypeSyntaxProtocol.
253
+ func `is`( _: TypeSyntaxProtocol . Protocol ) -> Bool {
254
+ return self . as ( TypeSyntaxProtocol . self) != nil
255
+ }
256
+
257
+ /// Return the non-type erased version of this syntax node if it conforms to
258
+ /// TypeSyntaxProtocol. Otherwise return nil.
259
+ func `as`( _: TypeSyntaxProtocol . Protocol ) -> TypeSyntaxProtocol ? {
260
+ return self . as ( SyntaxProtocol . self) as? TypeSyntaxProtocol
261
+ }
262
+ }
263
+
208
264
public struct TypeSyntax : TypeSyntaxProtocol , SyntaxHashable {
209
265
public let _syntaxNode : Syntax
210
266
@@ -256,7 +312,7 @@ extension TypeSyntax: CustomReflectable {
256
312
/// Reconstructs the real syntax type for this type from the node's kind and
257
313
/// provides a mirror that reflects this type.
258
314
public var customMirror : Mirror {
259
- return Mirror ( reflecting: Syntax ( self ) . _asConcreteType )
315
+ return Mirror ( reflecting: Syntax ( self ) . as ( SyntaxProtocol . self ) )
260
316
}
261
317
}
262
318
@@ -267,6 +323,20 @@ extension TypeSyntax: CustomReflectable {
267
323
/// DO NOT CONFORM TO THIS PROTOCOL YOURSELF!
268
324
public protocol PatternSyntaxProtocol : SyntaxProtocol { }
269
325
326
+ public extension Syntax {
327
+ /// Check whether the non-type erased version of this syntax node conforms to
328
+ /// PatternSyntaxProtocol.
329
+ func `is`( _: PatternSyntaxProtocol . Protocol ) -> Bool {
330
+ return self . as ( PatternSyntaxProtocol . self) != nil
331
+ }
332
+
333
+ /// Return the non-type erased version of this syntax node if it conforms to
334
+ /// PatternSyntaxProtocol. Otherwise return nil.
335
+ func `as`( _: PatternSyntaxProtocol . Protocol ) -> PatternSyntaxProtocol ? {
336
+ return self . as ( SyntaxProtocol . self) as? PatternSyntaxProtocol
337
+ }
338
+ }
339
+
270
340
public struct PatternSyntax : PatternSyntaxProtocol , SyntaxHashable {
271
341
public let _syntaxNode : Syntax
272
342
@@ -318,7 +388,7 @@ extension PatternSyntax: CustomReflectable {
318
388
/// Reconstructs the real syntax type for this type from the node's kind and
319
389
/// provides a mirror that reflects this type.
320
390
public var customMirror : Mirror {
321
- return Mirror ( reflecting: Syntax ( self ) . _asConcreteType )
391
+ return Mirror ( reflecting: Syntax ( self ) . as ( SyntaxProtocol . self ) )
322
392
}
323
393
}
324
394
0 commit comments