@@ -277,6 +277,46 @@ public extension SyntaxProtocol {
277
277
}
278
278
}
279
279
280
+ // MARK: - MissingNodeSyntax
281
+
282
+ /// Represents a layout node that is missing in the source file.
283
+ ///
284
+ /// See the types conforming to this protocol for examples of where missing nodes can occur.
285
+ public protocol MissingNodeSyntax : SyntaxProtocol {
286
+ /// A placeholder, i.e. `<#placeholder#>`, that can be inserted into the source code to represent the missing node.
287
+ var placeholder : TokenSyntax {
288
+ get
289
+ set
290
+ }
291
+ }
292
+
293
+ public extension MissingNodeSyntax {
294
+ /// Without this function, the `with` function defined on `SyntaxProtocol`
295
+ /// does not work on existentials of this protocol type.
296
+ @_disfavoredOverload
297
+ func with< T> ( _ keyPath: WritableKeyPath < MissingNodeSyntax , T > , _ newChild: T ) -> MissingNodeSyntax {
298
+ var copy : MissingNodeSyntax = self
299
+ copy [ keyPath: keyPath] = newChild
300
+ return copy
301
+ }
302
+ }
303
+
304
+ public extension SyntaxProtocol {
305
+ /// Check whether the non-type erased version of this syntax node conforms to
306
+ /// `MissingNodeSyntax`.
307
+ /// Note that this will incur an existential conversion.
308
+ func isProtocol( _: MissingNodeSyntax . Protocol ) -> Bool {
309
+ return self . asProtocol ( MissingNodeSyntax . self) != nil
310
+ }
311
+
312
+ /// Return the non-type erased version of this syntax node if it conforms to
313
+ /// `MissingNodeSyntax`. Otherwise return `nil`.
314
+ /// Note that this will incur an existential conversion.
315
+ func asProtocol( _: MissingNodeSyntax . Protocol ) -> MissingNodeSyntax ? {
316
+ return Syntax ( self ) . asProtocol ( SyntaxProtocol . self) as? MissingNodeSyntax
317
+ }
318
+ }
319
+
280
320
// MARK: - ParenthesizedSyntax
281
321
282
322
@@ -393,6 +433,52 @@ public extension SyntaxProtocol {
393
433
}
394
434
}
395
435
436
+ // MARK: - WithGenericParametersSyntax
437
+
438
+ /// Syntax nodes that have generic parameters.
439
+ ///
440
+ /// For example, functions or nominal types like `class` or `struct` can have generic parameters and have a generic where clause that restricts these generic parameters.
441
+ public protocol WithGenericParametersSyntax : SyntaxProtocol {
442
+ /// The parameter clause that defines the generic parameters.
443
+ var genericParameterClause : GenericParameterClauseSyntax ? {
444
+ get
445
+ set
446
+ }
447
+
448
+ /// A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.
449
+ var genericWhereClause : GenericWhereClauseSyntax ? {
450
+ get
451
+ set
452
+ }
453
+ }
454
+
455
+ public extension WithGenericParametersSyntax {
456
+ /// Without this function, the `with` function defined on `SyntaxProtocol`
457
+ /// does not work on existentials of this protocol type.
458
+ @_disfavoredOverload
459
+ func with< T> ( _ keyPath: WritableKeyPath < WithGenericParametersSyntax , T > , _ newChild: T ) -> WithGenericParametersSyntax {
460
+ var copy : WithGenericParametersSyntax = self
461
+ copy [ keyPath: keyPath] = newChild
462
+ return copy
463
+ }
464
+ }
465
+
466
+ public extension SyntaxProtocol {
467
+ /// Check whether the non-type erased version of this syntax node conforms to
468
+ /// `WithGenericParametersSyntax`.
469
+ /// Note that this will incur an existential conversion.
470
+ func isProtocol( _: WithGenericParametersSyntax . Protocol ) -> Bool {
471
+ return self . asProtocol ( WithGenericParametersSyntax . self) != nil
472
+ }
473
+
474
+ /// Return the non-type erased version of this syntax node if it conforms to
475
+ /// `WithGenericParametersSyntax`. Otherwise return `nil`.
476
+ /// Note that this will incur an existential conversion.
477
+ func asProtocol( _: WithGenericParametersSyntax . Protocol ) -> WithGenericParametersSyntax ? {
478
+ return Syntax ( self ) . asProtocol ( SyntaxProtocol . self) as? WithGenericParametersSyntax
479
+ }
480
+ }
481
+
396
482
// MARK: - WithModifiersSyntax
397
483
398
484
@@ -504,46 +590,6 @@ public extension SyntaxProtocol {
504
590
}
505
591
}
506
592
507
- // MARK: - MissingNodeSyntax
508
-
509
- /// Represents a layout node that is missing in the source file.
510
- ///
511
- /// See the types conforming to this protocol for examples of where missing nodes can occur.
512
- public protocol MissingNodeSyntax : SyntaxProtocol {
513
- /// A placeholder, i.e. `<#placeholder#>`, that can be inserted into the source code to represent the missing node.
514
- var placeholder : TokenSyntax {
515
- get
516
- set
517
- }
518
- }
519
-
520
- public extension MissingNodeSyntax {
521
- /// Without this function, the `with` function defined on `SyntaxProtocol`
522
- /// does not work on existentials of this protocol type.
523
- @_disfavoredOverload
524
- func with< T> ( _ keyPath: WritableKeyPath < MissingNodeSyntax , T > , _ newChild: T ) -> MissingNodeSyntax {
525
- var copy : MissingNodeSyntax = self
526
- copy [ keyPath: keyPath] = newChild
527
- return copy
528
- }
529
- }
530
-
531
- public extension SyntaxProtocol {
532
- /// Check whether the non-type erased version of this syntax node conforms to
533
- /// `MissingNodeSyntax`.
534
- /// Note that this will incur an existential conversion.
535
- func isProtocol( _: MissingNodeSyntax . Protocol ) -> Bool {
536
- return self . asProtocol ( MissingNodeSyntax . self) != nil
537
- }
538
-
539
- /// Return the non-type erased version of this syntax node if it conforms to
540
- /// `MissingNodeSyntax`. Otherwise return `nil`.
541
- /// Note that this will incur an existential conversion.
542
- func asProtocol( _: MissingNodeSyntax . Protocol ) -> MissingNodeSyntax ? {
543
- return Syntax ( self ) . asProtocol ( SyntaxProtocol . self) as? MissingNodeSyntax
544
- }
545
- }
546
-
547
593
extension AccessorBlockSyntax : BracedSyntax { }
548
594
549
595
extension AccessorDeclSyntax : WithAttributesSyntax { }
@@ -552,7 +598,7 @@ extension AccessorEffectSpecifiersSyntax: EffectSpecifiersSyntax {}
552
598
553
599
extension AccessorParameterSyntax : ParenthesizedSyntax { }
554
600
555
- extension ActorDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
601
+ extension ActorDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
556
602
557
603
extension ArrayElementSyntax : WithTrailingCommaSyntax { }
558
604
@@ -570,7 +616,7 @@ extension CatchClauseSyntax: WithCodeBlockSyntax {}
570
616
571
617
extension CatchItemSyntax : WithTrailingCommaSyntax { }
572
618
573
- extension ClassDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
619
+ extension ClassDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
574
620
575
621
extension ClosureCaptureItemSyntax : WithTrailingCommaSyntax { }
576
622
@@ -614,15 +660,15 @@ extension EnumCaseParameterClauseSyntax: ParenthesizedSyntax {}
614
660
615
661
extension EnumCaseParameterSyntax : WithTrailingCommaSyntax , WithModifiersSyntax { }
616
662
617
- extension EnumDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
663
+ extension EnumDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
618
664
619
665
extension ExpressionSegmentSyntax : ParenthesizedSyntax { }
620
666
621
667
extension ExtensionDeclSyntax : DeclGroupSyntax , WithAttributesSyntax , WithModifiersSyntax { }
622
668
623
669
extension ForInStmtSyntax : WithCodeBlockSyntax { }
624
670
625
- extension FunctionDeclSyntax : IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
671
+ extension FunctionDeclSyntax : IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
626
672
627
673
extension FunctionEffectSpecifiersSyntax : EffectSpecifiersSyntax { }
628
674
@@ -644,11 +690,11 @@ extension ImportDeclSyntax: WithAttributesSyntax, WithModifiersSyntax {}
644
690
645
691
extension InheritedTypeSyntax : WithTrailingCommaSyntax { }
646
692
647
- extension InitializerDeclSyntax : WithAttributesSyntax , WithModifiersSyntax { }
693
+ extension InitializerDeclSyntax : WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
648
694
649
695
extension LabeledSpecializeEntrySyntax : WithTrailingCommaSyntax { }
650
696
651
- extension MacroDeclSyntax : IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
697
+ extension MacroDeclSyntax : IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
652
698
653
699
extension MacroExpansionDeclSyntax : FreestandingMacroExpansionSyntax , WithAttributesSyntax , WithModifiersSyntax { }
654
700
@@ -688,9 +734,9 @@ extension RepeatWhileStmtSyntax: WithCodeBlockSyntax {}
688
734
689
735
extension SourceFileSyntax : WithStatementsSyntax { }
690
736
691
- extension StructDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
737
+ extension StructDeclSyntax : DeclGroupSyntax , IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
692
738
693
- extension SubscriptDeclSyntax : WithAttributesSyntax , WithModifiersSyntax { }
739
+ extension SubscriptDeclSyntax : WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
694
740
695
741
extension SwitchCaseSyntax : WithStatementsSyntax { }
696
742
@@ -712,7 +758,7 @@ extension TupleTypeSyntax: ParenthesizedSyntax {}
712
758
713
759
extension TypeEffectSpecifiersSyntax : EffectSpecifiersSyntax { }
714
760
715
- extension TypealiasDeclSyntax : IdentifiedDeclSyntax , WithAttributesSyntax , WithModifiersSyntax { }
761
+ extension TypealiasDeclSyntax : IdentifiedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
716
762
717
763
extension VariableDeclSyntax : WithAttributesSyntax , WithModifiersSyntax { }
718
764
0 commit comments