@@ -570,6 +570,43 @@ public extension SyntaxProtocol {
570
570
}
571
571
}
572
572
573
+ // MARK: - WithOptionalCodeBlockSyntax
574
+
575
+
576
+ public protocol WithOptionalCodeBlockSyntax : SyntaxProtocol {
577
+ var body : CodeBlockSyntax ? {
578
+ get
579
+ set
580
+ }
581
+ }
582
+
583
+ public extension WithOptionalCodeBlockSyntax {
584
+ /// Without this function, the `with` function defined on `SyntaxProtocol`
585
+ /// does not work on existentials of this protocol type.
586
+ @_disfavoredOverload
587
+ func with< T> ( _ keyPath: WritableKeyPath < WithOptionalCodeBlockSyntax , T > , _ newChild: T ) -> WithOptionalCodeBlockSyntax {
588
+ var copy : WithOptionalCodeBlockSyntax = self
589
+ copy [ keyPath: keyPath] = newChild
590
+ return copy
591
+ }
592
+ }
593
+
594
+ public extension SyntaxProtocol {
595
+ /// Check whether the non-type erased version of this syntax node conforms to
596
+ /// `WithOptionalCodeBlockSyntax`.
597
+ /// Note that this will incur an existential conversion.
598
+ func isProtocol( _: WithOptionalCodeBlockSyntax . Protocol ) -> Bool {
599
+ return self . asProtocol ( WithOptionalCodeBlockSyntax . self) != nil
600
+ }
601
+
602
+ /// Return the non-type erased version of this syntax node if it conforms to
603
+ /// `WithOptionalCodeBlockSyntax`. Otherwise return `nil`.
604
+ /// Note that this will incur an existential conversion.
605
+ func asProtocol( _: WithOptionalCodeBlockSyntax . Protocol ) -> WithOptionalCodeBlockSyntax ? {
606
+ return Syntax ( self ) . asProtocol ( SyntaxProtocol . self) as? WithOptionalCodeBlockSyntax
607
+ }
608
+ }
609
+
573
610
// MARK: - WithStatementsSyntax
574
611
575
612
@@ -649,7 +686,7 @@ public extension SyntaxProtocol {
649
686
650
687
extension AccessorBlockSyntax : BracedSyntax { }
651
688
652
- extension AccessorDeclSyntax : WithAttributesSyntax { }
689
+ extension AccessorDeclSyntax : WithOptionalCodeBlockSyntax , WithAttributesSyntax { }
653
690
654
691
extension AccessorEffectSpecifiersSyntax : EffectSpecifiersSyntax { }
655
692
@@ -693,7 +730,7 @@ extension DeclNameArgumentsSyntax: ParenthesizedSyntax {}
693
730
694
731
extension DeferStmtSyntax : WithCodeBlockSyntax { }
695
732
696
- extension DeinitializerDeclSyntax : WithAttributesSyntax , WithModifiersSyntax { }
733
+ extension DeinitializerDeclSyntax : WithAttributesSyntax , WithModifiersSyntax , WithOptionalCodeBlockSyntax { }
697
734
698
735
extension DictionaryElementSyntax : WithTrailingCommaSyntax { }
699
736
@@ -723,7 +760,7 @@ extension ExtensionDeclSyntax: DeclGroupSyntax, WithAttributesSyntax, WithModifi
723
760
724
761
extension ForStmtSyntax : WithCodeBlockSyntax { }
725
762
726
- extension FunctionDeclSyntax : NamedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
763
+ extension FunctionDeclSyntax : NamedDeclSyntax , WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax , WithOptionalCodeBlockSyntax { }
727
764
728
765
extension FunctionEffectSpecifiersSyntax : EffectSpecifiersSyntax { }
729
766
@@ -747,7 +784,7 @@ extension ImportDeclSyntax: WithAttributesSyntax, WithModifiersSyntax {}
747
784
748
785
extension InheritedTypeSyntax : WithTrailingCommaSyntax { }
749
786
750
- extension InitializerDeclSyntax : WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax { }
787
+ extension InitializerDeclSyntax : WithAttributesSyntax , WithGenericParametersSyntax , WithModifiersSyntax , WithOptionalCodeBlockSyntax { }
751
788
752
789
extension LabeledExprSyntax : WithTrailingCommaSyntax { }
753
790
0 commit comments