From a68216cef797a68e0a64883b15e91f76c1b79d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ba=CC=A8k?= Date: Thu, 14 Sep 2023 19:26:16 +0200 Subject: [PATCH] Prevent Unrelated Casts on Child Choice Node --- .../swiftsyntax/SyntaxCollectionsFile.swift | 5 + .../swiftsyntax/SyntaxNodeCasting.swift | 88 +++ .../swiftsyntax/SyntaxNodesFile.swift | 4 + Release Notes/510.md | 8 + Sources/SwiftSyntax/SyntaxProtocol.swift | 35 ++ .../generated/SyntaxCollections.swift | 286 +++++++++ .../generated/syntaxNodes/SyntaxNodesAB.swift | 594 ++++++++++++++++++ .../generated/syntaxNodes/SyntaxNodesC.swift | 198 ++++++ .../generated/syntaxNodes/SyntaxNodesD.swift | 132 ++++ .../syntaxNodes/SyntaxNodesGHI.swift | 220 +++++++ .../syntaxNodes/SyntaxNodesJKLMN.swift | 66 ++ .../syntaxNodes/SyntaxNodesQRS.swift | 44 ++ .../syntaxNodes/SyntaxNodesTUVWXYZ.swift | 44 ++ 13 files changed, 1724 insertions(+) create mode 100644 CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift index b734e8979a7..35466c1c570 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift @@ -112,6 +112,11 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { StmtSyntax("return .choices(\(choices))") } + + for choiceNodeName in node.elementChoices { + let choiceNode = SYNTAX_NODE_MAP[choiceNodeName]! + choiceNodeCastingMethods(for: choiceNode.kind) + } } } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift new file mode 100644 index 00000000000..7f0b43a78fa --- /dev/null +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftSyntax +import SwiftSyntaxBuilder +import SyntaxSupport + +@MemberBlockItemListBuilder +func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlockItemListSyntax { + if syntaxNodeKind.isBase { + DeclSyntax( + """ + /// Checks if the current syntax node can be cast to the type conforming to the ``\(syntaxNodeKind.protocolType)`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + """ + ) + + DeclSyntax( + """ + /// Attempts to cast the current syntax node to the type conforming to the ``\(syntaxNodeKind.protocolType)`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + """ + ) + + DeclSyntax( + """ + /// Force-casts the current syntax node to the type conforming to the ``\(syntaxNodeKind.protocolType)`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } + """ + ) + } else { + DeclSyntax( + """ + /// Checks if the current syntax node can be cast to ``\(syntaxNodeKind.syntaxType)``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> Bool { + return self.as(syntaxType) != nil + } + """ + ) + + DeclSyntax( + """ + /// Attempts to cast the current syntax node to ``\(syntaxNodeKind.syntaxType)``. + /// + /// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``, or `nil` if the cast fails. + public func `as`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType)? { + return \(syntaxNodeKind.syntaxType).init(self) + } + """ + ) + + DeclSyntax( + """ + /// Force-casts the current syntax node to ``\(syntaxNodeKind.syntaxType)``. + /// + /// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType) { + return self.as(\(syntaxNodeKind.syntaxType).self)! + } + """ + ) + } +} diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift index c9d4389babc..ac7b3172200 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift @@ -289,5 +289,9 @@ private func generateSyntaxChildChoices(for child: Child) throws -> EnumDeclSynt StmtSyntax("return .choices(\(choices))") } + + for choiceNode in choices { + choiceNodeCastingMethods(for: choiceNode.syntaxNodeKind) + } } } diff --git a/Release Notes/510.md b/Release Notes/510.md index 6136888a67b..0b0e3615871 100644 --- a/Release Notes/510.md +++ b/Release Notes/510.md @@ -5,13 +5,16 @@ - `SyntaxStringInterpolation.appendInterpolation(_: (some SyntaxProtocol)?)` - Description: Allows optional syntax nodes to be used inside string interpolation of syntax nodes. If the node is `nil`, nothing will get added to the string interpolation. - Pull Request: https://github.com/apple/swift-syntax/pull/2085 + - `SyntaxCollection.index(at:)` - Description: Returns the index of the n-th element in a `SyntaxCollection`. This computation is in O(n) and `SyntaxCollection` is not subscriptable by an integer. - Pull Request: https://github.com/apple/swift-syntax/pull/2014 + - Convenience initializer `ClosureCaptureSyntax.init()` - Description: Provides a convenience initializer for `ClosureCaptureSyntax` that takes a concrete `name` argument and automatically adds `equal = TokenSyntax.equalToken()` to it. - Issue: https://github.com/apple/swift-syntax/issues/1984 - Pull Request: https://github.com/apple/swift-syntax/pull/2127 + - Convenience initializer `EnumCaseParameterSyntax.init()` - Description: Provides a convenience initializer for `EnumCaseParameterSyntax` that takes a concrete `firstName` value and adds `colon = TokenSyntax.colonToken()` automatically to it. - Issue: https://github.com/apple/swift-syntax/issues/1984 @@ -49,6 +52,11 @@ - Description: `is`, `as`, and `cast` methods on base node protocols with base-type conversions are marked as deprecated. The deprecated methods emit a warning that informs the developer that the cast will always succeed and should be done using the base node's initializer. - Issue: https://github.com/apple/swift-syntax/issues/2092 - Pull Request: https://github.com/apple/swift-syntax/pull/2108 + +- Child Choice Node Casts + - Description: `is`, `as`, and `cast` methods for types not contained in the choice node are marked as deprecated. The deprecated methods will emit a warning, indicating that the cast will always fail. + - Issue: https://github.com/apple/swift-syntax/issues/2092 + - Pull Request: https://github.com/apple/swift-syntax/pull/2184 ## API-Incompatible Changes diff --git a/Sources/SwiftSyntax/SyntaxProtocol.swift b/Sources/SwiftSyntax/SyntaxProtocol.swift index 4b2e7bc09c1..1f54379c9db 100644 --- a/Sources/SwiftSyntax/SyntaxProtocol.swift +++ b/Sources/SwiftSyntax/SyntaxProtocol.swift @@ -698,3 +698,38 @@ public extension SyntaxProtocol { /// Protocol for the enums nested inside ``Syntax`` nodes that enumerate all the /// possible types a child node might have. public protocol SyntaxChildChoices: SyntaxProtocol {} + +public extension SyntaxChildChoices { + + /// Checks if the current ``SyntaxChildChoices`` instance can be cast to a given specialized syntax type. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + /// + /// - Note: This method is marked as deprecated because it is advised not to use it for unrelated casts. + @available(*, deprecated, message: "This cast will always fail") + func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current ``SyntaxChildChoices`` instance to a given specialized syntax type. + /// + /// - Returns: An instance of the specialized syntax type, or `nil` if the cast fails. + /// + /// - Note: This method is marked as deprecated because it is advised not to use it for unrelated casts. + @available(*, deprecated, message: "This cast will always fail") + func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current ``SyntaxChildChoices`` instance to a given specialized syntax type. + /// + /// - Returns: An instance of the specialized syntax type. + /// + /// - Warning: This function will crash if the cast is not possible. Use `as` for a safe attempt. + /// + /// - Note: This method is marked as deprecated because it is advised not to use it for unrelated casts. + @available(*, deprecated, message: "This cast will always fail") + func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } +} diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index 1f8e55e05e5..12d477cd2b8 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -141,6 +141,50 @@ public struct AttributeListSyntax: SyntaxCollection, SyntaxHashable { .node(AttributeSyntax.self), .node(IfConfigDeclSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``AttributeSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: AttributeSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``AttributeSyntax``. + /// + /// - Returns: An instance of ``AttributeSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: AttributeSyntax.Type) -> AttributeSyntax? { + return AttributeSyntax.init(self) + } + + /// Force-casts the current syntax node to ``AttributeSyntax``. + /// + /// - Returns: An instance of ``AttributeSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: AttributeSyntax.Type) -> AttributeSyntax { + return self.as(AttributeSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``IfConfigDeclSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: IfConfigDeclSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``IfConfigDeclSyntax``. + /// + /// - Returns: An instance of ``IfConfigDeclSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: IfConfigDeclSyntax.Type) -> IfConfigDeclSyntax? { + return IfConfigDeclSyntax.init(self) + } + + /// Force-casts the current syntax node to ``IfConfigDeclSyntax``. + /// + /// - Returns: An instance of ``IfConfigDeclSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: IfConfigDeclSyntax.Type) -> IfConfigDeclSyntax { + return self.as(IfConfigDeclSyntax.self)! + } } public let _syntaxNode: Syntax @@ -990,6 +1034,72 @@ public struct PrecedenceGroupAttributeListSyntax: SyntaxCollection, SyntaxHashab .node(PrecedenceGroupAssignmentSyntax.self), .node(PrecedenceGroupAssociativitySyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``PrecedenceGroupRelationSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: PrecedenceGroupRelationSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``PrecedenceGroupRelationSyntax``. + /// + /// - Returns: An instance of ``PrecedenceGroupRelationSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: PrecedenceGroupRelationSyntax.Type) -> PrecedenceGroupRelationSyntax? { + return PrecedenceGroupRelationSyntax.init(self) + } + + /// Force-casts the current syntax node to ``PrecedenceGroupRelationSyntax``. + /// + /// - Returns: An instance of ``PrecedenceGroupRelationSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: PrecedenceGroupRelationSyntax.Type) -> PrecedenceGroupRelationSyntax { + return self.as(PrecedenceGroupRelationSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``PrecedenceGroupAssignmentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: PrecedenceGroupAssignmentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``PrecedenceGroupAssignmentSyntax``. + /// + /// - Returns: An instance of ``PrecedenceGroupAssignmentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: PrecedenceGroupAssignmentSyntax.Type) -> PrecedenceGroupAssignmentSyntax? { + return PrecedenceGroupAssignmentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``PrecedenceGroupAssignmentSyntax``. + /// + /// - Returns: An instance of ``PrecedenceGroupAssignmentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: PrecedenceGroupAssignmentSyntax.Type) -> PrecedenceGroupAssignmentSyntax { + return self.as(PrecedenceGroupAssignmentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``PrecedenceGroupAssociativitySyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: PrecedenceGroupAssociativitySyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``PrecedenceGroupAssociativitySyntax``. + /// + /// - Returns: An instance of ``PrecedenceGroupAssociativitySyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: PrecedenceGroupAssociativitySyntax.Type) -> PrecedenceGroupAssociativitySyntax? { + return PrecedenceGroupAssociativitySyntax.init(self) + } + + /// Force-casts the current syntax node to ``PrecedenceGroupAssociativitySyntax``. + /// + /// - Returns: An instance of ``PrecedenceGroupAssociativitySyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: PrecedenceGroupAssociativitySyntax.Type) -> PrecedenceGroupAssociativitySyntax { + return self.as(PrecedenceGroupAssociativitySyntax.self)! + } } public let _syntaxNode: Syntax @@ -1145,6 +1255,94 @@ public struct SpecializeAttributeArgumentListSyntax: SyntaxCollection, SyntaxHas .node(GenericWhereClauseSyntax.self) ]) } + + /// Checks if the current syntax node can be cast to ``LabeledSpecializeArgumentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: LabeledSpecializeArgumentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``LabeledSpecializeArgumentSyntax``. + /// + /// - Returns: An instance of ``LabeledSpecializeArgumentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: LabeledSpecializeArgumentSyntax.Type) -> LabeledSpecializeArgumentSyntax? { + return LabeledSpecializeArgumentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``LabeledSpecializeArgumentSyntax``. + /// + /// - Returns: An instance of ``LabeledSpecializeArgumentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: LabeledSpecializeArgumentSyntax.Type) -> LabeledSpecializeArgumentSyntax { + return self.as(LabeledSpecializeArgumentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``SpecializeAvailabilityArgumentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SpecializeAvailabilityArgumentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SpecializeAvailabilityArgumentSyntax``. + /// + /// - Returns: An instance of ``SpecializeAvailabilityArgumentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SpecializeAvailabilityArgumentSyntax.Type) -> SpecializeAvailabilityArgumentSyntax? { + return SpecializeAvailabilityArgumentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SpecializeAvailabilityArgumentSyntax``. + /// + /// - Returns: An instance of ``SpecializeAvailabilityArgumentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SpecializeAvailabilityArgumentSyntax.Type) -> SpecializeAvailabilityArgumentSyntax { + return self.as(SpecializeAvailabilityArgumentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``SpecializeTargetFunctionArgumentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SpecializeTargetFunctionArgumentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SpecializeTargetFunctionArgumentSyntax``. + /// + /// - Returns: An instance of ``SpecializeTargetFunctionArgumentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SpecializeTargetFunctionArgumentSyntax.Type) -> SpecializeTargetFunctionArgumentSyntax? { + return SpecializeTargetFunctionArgumentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SpecializeTargetFunctionArgumentSyntax``. + /// + /// - Returns: An instance of ``SpecializeTargetFunctionArgumentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SpecializeTargetFunctionArgumentSyntax.Type) -> SpecializeTargetFunctionArgumentSyntax { + return self.as(SpecializeTargetFunctionArgumentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``GenericWhereClauseSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: GenericWhereClauseSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``GenericWhereClauseSyntax``. + /// + /// - Returns: An instance of ``GenericWhereClauseSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: GenericWhereClauseSyntax.Type) -> GenericWhereClauseSyntax? { + return GenericWhereClauseSyntax.init(self) + } + + /// Force-casts the current syntax node to ``GenericWhereClauseSyntax``. + /// + /// - Returns: An instance of ``GenericWhereClauseSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: GenericWhereClauseSyntax.Type) -> GenericWhereClauseSyntax { + return self.as(GenericWhereClauseSyntax.self)! + } } public let _syntaxNode: Syntax @@ -1205,6 +1403,50 @@ public struct StringLiteralSegmentListSyntax: SyntaxCollection, SyntaxHashable { .node(StringSegmentSyntax.self), .node(ExpressionSegmentSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``StringSegmentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: StringSegmentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``StringSegmentSyntax``. + /// + /// - Returns: An instance of ``StringSegmentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: StringSegmentSyntax.Type) -> StringSegmentSyntax? { + return StringSegmentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``StringSegmentSyntax``. + /// + /// - Returns: An instance of ``StringSegmentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: StringSegmentSyntax.Type) -> StringSegmentSyntax { + return self.as(StringSegmentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ExpressionSegmentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ExpressionSegmentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ExpressionSegmentSyntax``. + /// + /// - Returns: An instance of ``ExpressionSegmentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ExpressionSegmentSyntax.Type) -> ExpressionSegmentSyntax? { + return ExpressionSegmentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ExpressionSegmentSyntax``. + /// + /// - Returns: An instance of ``ExpressionSegmentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ExpressionSegmentSyntax.Type) -> ExpressionSegmentSyntax { + return self.as(ExpressionSegmentSyntax.self)! + } } public let _syntaxNode: Syntax @@ -1288,6 +1530,50 @@ public struct SwitchCaseListSyntax: SyntaxCollection, SyntaxHashable { .node(SwitchCaseSyntax.self), .node(IfConfigDeclSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``SwitchCaseSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SwitchCaseSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SwitchCaseSyntax``. + /// + /// - Returns: An instance of ``SwitchCaseSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SwitchCaseSyntax.Type) -> SwitchCaseSyntax? { + return SwitchCaseSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SwitchCaseSyntax``. + /// + /// - Returns: An instance of ``SwitchCaseSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SwitchCaseSyntax.Type) -> SwitchCaseSyntax { + return self.as(SwitchCaseSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``IfConfigDeclSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: IfConfigDeclSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``IfConfigDeclSyntax``. + /// + /// - Returns: An instance of ``IfConfigDeclSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: IfConfigDeclSyntax.Type) -> IfConfigDeclSyntax? { + return IfConfigDeclSyntax.init(self) + } + + /// Force-casts the current syntax node to ``IfConfigDeclSyntax``. + /// + /// - Returns: An instance of ``IfConfigDeclSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: IfConfigDeclSyntax.Type) -> IfConfigDeclSyntax { + return self.as(IfConfigDeclSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index 796d77d69ef..1f51076e6b9 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -61,6 +61,50 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo public static var structure: SyntaxNodeStructure { return .choices([.node(AccessorDeclListSyntax.self), .node(CodeBlockItemListSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``AccessorDeclListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: AccessorDeclListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``AccessorDeclListSyntax``. + /// + /// - Returns: An instance of ``AccessorDeclListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: AccessorDeclListSyntax.Type) -> AccessorDeclListSyntax? { + return AccessorDeclListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``AccessorDeclListSyntax``. + /// + /// - Returns: An instance of ``AccessorDeclListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: AccessorDeclListSyntax.Type) -> AccessorDeclListSyntax { + return self.as(AccessorDeclListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``CodeBlockItemListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: CodeBlockItemListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``CodeBlockItemListSyntax``. + /// + /// - Returns: An instance of ``CodeBlockItemListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: CodeBlockItemListSyntax.Type) -> CodeBlockItemListSyntax? { + return CodeBlockItemListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``CodeBlockItemListSyntax``. + /// + /// - Returns: An instance of ``CodeBlockItemListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: CodeBlockItemListSyntax.Type) -> CodeBlockItemListSyntax { + return self.as(CodeBlockItemListSyntax.self)! + } } public let _syntaxNode: Syntax @@ -2433,6 +2477,446 @@ public struct AttributeSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodePr .node(DocumentationAttributeArgumentListSyntax.self) ]) } + + /// Checks if the current syntax node can be cast to ``LabeledExprListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: LabeledExprListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``LabeledExprListSyntax``. + /// + /// - Returns: An instance of ``LabeledExprListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: LabeledExprListSyntax.Type) -> LabeledExprListSyntax? { + return LabeledExprListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``LabeledExprListSyntax``. + /// + /// - Returns: An instance of ``LabeledExprListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: LabeledExprListSyntax.Type) -> LabeledExprListSyntax { + return self.as(LabeledExprListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``TokenSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: TokenSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: TokenSyntax.Type) -> TokenSyntax? { + return TokenSyntax.init(self) + } + + /// Force-casts the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: TokenSyntax.Type) -> TokenSyntax { + return self.as(TokenSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``StringLiteralExprSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: StringLiteralExprSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``StringLiteralExprSyntax``. + /// + /// - Returns: An instance of ``StringLiteralExprSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: StringLiteralExprSyntax.Type) -> StringLiteralExprSyntax? { + return StringLiteralExprSyntax.init(self) + } + + /// Force-casts the current syntax node to ``StringLiteralExprSyntax``. + /// + /// - Returns: An instance of ``StringLiteralExprSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: StringLiteralExprSyntax.Type) -> StringLiteralExprSyntax { + return self.as(StringLiteralExprSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``AvailabilityArgumentListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: AvailabilityArgumentListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``AvailabilityArgumentListSyntax``. + /// + /// - Returns: An instance of ``AvailabilityArgumentListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: AvailabilityArgumentListSyntax.Type) -> AvailabilityArgumentListSyntax? { + return AvailabilityArgumentListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``AvailabilityArgumentListSyntax``. + /// + /// - Returns: An instance of ``AvailabilityArgumentListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: AvailabilityArgumentListSyntax.Type) -> AvailabilityArgumentListSyntax { + return self.as(AvailabilityArgumentListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``SpecializeAttributeArgumentListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SpecializeAttributeArgumentListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SpecializeAttributeArgumentListSyntax``. + /// + /// - Returns: An instance of ``SpecializeAttributeArgumentListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SpecializeAttributeArgumentListSyntax.Type) -> SpecializeAttributeArgumentListSyntax? { + return SpecializeAttributeArgumentListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SpecializeAttributeArgumentListSyntax``. + /// + /// - Returns: An instance of ``SpecializeAttributeArgumentListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SpecializeAttributeArgumentListSyntax.Type) -> SpecializeAttributeArgumentListSyntax { + return self.as(SpecializeAttributeArgumentListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ObjCSelectorPieceListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ObjCSelectorPieceListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ObjCSelectorPieceListSyntax``. + /// + /// - Returns: An instance of ``ObjCSelectorPieceListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ObjCSelectorPieceListSyntax.Type) -> ObjCSelectorPieceListSyntax? { + return ObjCSelectorPieceListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ObjCSelectorPieceListSyntax``. + /// + /// - Returns: An instance of ``ObjCSelectorPieceListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ObjCSelectorPieceListSyntax.Type) -> ObjCSelectorPieceListSyntax { + return self.as(ObjCSelectorPieceListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ImplementsAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ImplementsAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ImplementsAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ImplementsAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ImplementsAttributeArgumentsSyntax.Type) -> ImplementsAttributeArgumentsSyntax? { + return ImplementsAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ImplementsAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ImplementsAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ImplementsAttributeArgumentsSyntax.Type) -> ImplementsAttributeArgumentsSyntax { + return self.as(ImplementsAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``DifferentiableAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DifferentiableAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DifferentiableAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``DifferentiableAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DifferentiableAttributeArgumentsSyntax.Type) -> DifferentiableAttributeArgumentsSyntax? { + return DifferentiableAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DifferentiableAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``DifferentiableAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DifferentiableAttributeArgumentsSyntax.Type) -> DifferentiableAttributeArgumentsSyntax { + return self.as(DifferentiableAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``DerivativeAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DerivativeAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DerivativeAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``DerivativeAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DerivativeAttributeArgumentsSyntax.Type) -> DerivativeAttributeArgumentsSyntax? { + return DerivativeAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DerivativeAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``DerivativeAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DerivativeAttributeArgumentsSyntax.Type) -> DerivativeAttributeArgumentsSyntax { + return self.as(DerivativeAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``BackDeployedAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: BackDeployedAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``BackDeployedAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``BackDeployedAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: BackDeployedAttributeArgumentsSyntax.Type) -> BackDeployedAttributeArgumentsSyntax? { + return BackDeployedAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``BackDeployedAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``BackDeployedAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: BackDeployedAttributeArgumentsSyntax.Type) -> BackDeployedAttributeArgumentsSyntax { + return self.as(BackDeployedAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ConventionAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ConventionAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ConventionAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ConventionAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ConventionAttributeArgumentsSyntax.Type) -> ConventionAttributeArgumentsSyntax? { + return ConventionAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ConventionAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ConventionAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ConventionAttributeArgumentsSyntax.Type) -> ConventionAttributeArgumentsSyntax { + return self.as(ConventionAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ConventionWitnessMethodAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ConventionWitnessMethodAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ConventionWitnessMethodAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ConventionWitnessMethodAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ConventionWitnessMethodAttributeArgumentsSyntax.Type) -> ConventionWitnessMethodAttributeArgumentsSyntax? { + return ConventionWitnessMethodAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ConventionWitnessMethodAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ConventionWitnessMethodAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ConventionWitnessMethodAttributeArgumentsSyntax.Type) -> ConventionWitnessMethodAttributeArgumentsSyntax { + return self.as(ConventionWitnessMethodAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``OpaqueReturnTypeOfAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: OpaqueReturnTypeOfAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``OpaqueReturnTypeOfAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``OpaqueReturnTypeOfAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: OpaqueReturnTypeOfAttributeArgumentsSyntax.Type) -> OpaqueReturnTypeOfAttributeArgumentsSyntax? { + return OpaqueReturnTypeOfAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``OpaqueReturnTypeOfAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``OpaqueReturnTypeOfAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: OpaqueReturnTypeOfAttributeArgumentsSyntax.Type) -> OpaqueReturnTypeOfAttributeArgumentsSyntax { + return self.as(OpaqueReturnTypeOfAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ExposeAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ExposeAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ExposeAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ExposeAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ExposeAttributeArgumentsSyntax.Type) -> ExposeAttributeArgumentsSyntax? { + return ExposeAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ExposeAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``ExposeAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ExposeAttributeArgumentsSyntax.Type) -> ExposeAttributeArgumentsSyntax { + return self.as(ExposeAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``OriginallyDefinedInAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: OriginallyDefinedInAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``OriginallyDefinedInAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``OriginallyDefinedInAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: OriginallyDefinedInAttributeArgumentsSyntax.Type) -> OriginallyDefinedInAttributeArgumentsSyntax? { + return OriginallyDefinedInAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``OriginallyDefinedInAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``OriginallyDefinedInAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: OriginallyDefinedInAttributeArgumentsSyntax.Type) -> OriginallyDefinedInAttributeArgumentsSyntax { + return self.as(OriginallyDefinedInAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``UnderscorePrivateAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: UnderscorePrivateAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``UnderscorePrivateAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``UnderscorePrivateAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: UnderscorePrivateAttributeArgumentsSyntax.Type) -> UnderscorePrivateAttributeArgumentsSyntax? { + return UnderscorePrivateAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``UnderscorePrivateAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``UnderscorePrivateAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: UnderscorePrivateAttributeArgumentsSyntax.Type) -> UnderscorePrivateAttributeArgumentsSyntax { + return self.as(UnderscorePrivateAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``DynamicReplacementAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DynamicReplacementAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DynamicReplacementAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``DynamicReplacementAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DynamicReplacementAttributeArgumentsSyntax.Type) -> DynamicReplacementAttributeArgumentsSyntax? { + return DynamicReplacementAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DynamicReplacementAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``DynamicReplacementAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DynamicReplacementAttributeArgumentsSyntax.Type) -> DynamicReplacementAttributeArgumentsSyntax { + return self.as(DynamicReplacementAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``UnavailableFromAsyncAttributeArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: UnavailableFromAsyncAttributeArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``UnavailableFromAsyncAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``UnavailableFromAsyncAttributeArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: UnavailableFromAsyncAttributeArgumentsSyntax.Type) -> UnavailableFromAsyncAttributeArgumentsSyntax? { + return UnavailableFromAsyncAttributeArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``UnavailableFromAsyncAttributeArgumentsSyntax``. + /// + /// - Returns: An instance of ``UnavailableFromAsyncAttributeArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: UnavailableFromAsyncAttributeArgumentsSyntax.Type) -> UnavailableFromAsyncAttributeArgumentsSyntax { + return self.as(UnavailableFromAsyncAttributeArgumentsSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``EffectsAttributeArgumentListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: EffectsAttributeArgumentListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``EffectsAttributeArgumentListSyntax``. + /// + /// - Returns: An instance of ``EffectsAttributeArgumentListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: EffectsAttributeArgumentListSyntax.Type) -> EffectsAttributeArgumentListSyntax? { + return EffectsAttributeArgumentListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``EffectsAttributeArgumentListSyntax``. + /// + /// - Returns: An instance of ``EffectsAttributeArgumentListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: EffectsAttributeArgumentListSyntax.Type) -> EffectsAttributeArgumentListSyntax { + return self.as(EffectsAttributeArgumentListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``DocumentationAttributeArgumentListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DocumentationAttributeArgumentListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DocumentationAttributeArgumentListSyntax``. + /// + /// - Returns: An instance of ``DocumentationAttributeArgumentListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DocumentationAttributeArgumentListSyntax.Type) -> DocumentationAttributeArgumentListSyntax? { + return DocumentationAttributeArgumentListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DocumentationAttributeArgumentListSyntax``. + /// + /// - Returns: An instance of ``DocumentationAttributeArgumentListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DocumentationAttributeArgumentListSyntax.Type) -> DocumentationAttributeArgumentListSyntax { + return self.as(DocumentationAttributeArgumentListSyntax.self)! + } } public let _syntaxNode: Syntax @@ -2859,6 +3343,72 @@ public struct AvailabilityArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafS public static var structure: SyntaxNodeStructure { return .choices([.node(TokenSyntax.self), .node(PlatformVersionSyntax.self), .node(AvailabilityLabeledArgumentSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``TokenSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: TokenSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: TokenSyntax.Type) -> TokenSyntax? { + return TokenSyntax.init(self) + } + + /// Force-casts the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: TokenSyntax.Type) -> TokenSyntax { + return self.as(TokenSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``PlatformVersionSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: PlatformVersionSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``PlatformVersionSyntax``. + /// + /// - Returns: An instance of ``PlatformVersionSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: PlatformVersionSyntax.Type) -> PlatformVersionSyntax? { + return PlatformVersionSyntax.init(self) + } + + /// Force-casts the current syntax node to ``PlatformVersionSyntax``. + /// + /// - Returns: An instance of ``PlatformVersionSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: PlatformVersionSyntax.Type) -> PlatformVersionSyntax { + return self.as(PlatformVersionSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``AvailabilityLabeledArgumentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: AvailabilityLabeledArgumentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``AvailabilityLabeledArgumentSyntax``. + /// + /// - Returns: An instance of ``AvailabilityLabeledArgumentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: AvailabilityLabeledArgumentSyntax.Type) -> AvailabilityLabeledArgumentSyntax? { + return AvailabilityLabeledArgumentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``AvailabilityLabeledArgumentSyntax``. + /// + /// - Returns: An instance of ``AvailabilityLabeledArgumentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: AvailabilityLabeledArgumentSyntax.Type) -> AvailabilityLabeledArgumentSyntax { + return self.as(AvailabilityLabeledArgumentSyntax.self)! + } } public let _syntaxNode: Syntax @@ -3219,6 +3769,50 @@ public struct AvailabilityLabeledArgumentSyntax: SyntaxProtocol, SyntaxHashable, public static var structure: SyntaxNodeStructure { return .choices([.node(SimpleStringLiteralExprSyntax.self), .node(VersionTupleSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``SimpleStringLiteralExprSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SimpleStringLiteralExprSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SimpleStringLiteralExprSyntax``. + /// + /// - Returns: An instance of ``SimpleStringLiteralExprSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SimpleStringLiteralExprSyntax.Type) -> SimpleStringLiteralExprSyntax? { + return SimpleStringLiteralExprSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SimpleStringLiteralExprSyntax``. + /// + /// - Returns: An instance of ``SimpleStringLiteralExprSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SimpleStringLiteralExprSyntax.Type) -> SimpleStringLiteralExprSyntax { + return self.as(SimpleStringLiteralExprSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``VersionTupleSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: VersionTupleSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``VersionTupleSyntax``. + /// + /// - Returns: An instance of ``VersionTupleSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: VersionTupleSyntax.Type) -> VersionTupleSyntax? { + return VersionTupleSyntax.init(self) + } + + /// Force-casts the current syntax node to ``VersionTupleSyntax``. + /// + /// - Returns: An instance of ``VersionTupleSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: VersionTupleSyntax.Type) -> VersionTupleSyntax { + return self.as(VersionTupleSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift index cb998ff9392..bed5c598be5 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift @@ -2567,6 +2567,50 @@ public struct ClosureSignatureSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta public static var structure: SyntaxNodeStructure { return .choices([.node(ClosureShorthandParameterListSyntax.self), .node(ClosureParameterClauseSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``ClosureShorthandParameterListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ClosureShorthandParameterListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ClosureShorthandParameterListSyntax``. + /// + /// - Returns: An instance of ``ClosureShorthandParameterListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ClosureShorthandParameterListSyntax.Type) -> ClosureShorthandParameterListSyntax? { + return ClosureShorthandParameterListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ClosureShorthandParameterListSyntax``. + /// + /// - Returns: An instance of ``ClosureShorthandParameterListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ClosureShorthandParameterListSyntax.Type) -> ClosureShorthandParameterListSyntax { + return self.as(ClosureShorthandParameterListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ClosureParameterClauseSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ClosureParameterClauseSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ClosureParameterClauseSyntax``. + /// + /// - Returns: An instance of ``ClosureParameterClauseSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ClosureParameterClauseSyntax.Type) -> ClosureParameterClauseSyntax? { + return ClosureParameterClauseSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ClosureParameterClauseSyntax``. + /// + /// - Returns: An instance of ``ClosureParameterClauseSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ClosureParameterClauseSyntax.Type) -> ClosureParameterClauseSyntax { + return self.as(ClosureParameterClauseSyntax.self)! + } } public let _syntaxNode: Syntax @@ -2866,6 +2910,72 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo public static var structure: SyntaxNodeStructure { return .choices([.node(DeclSyntax.self), .node(StmtSyntax.self), .node(ExprSyntax.self)]) } + + /// Checks if the current syntax node can be cast to the type conforming to the ``DeclSyntaxProtocol`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to the type conforming to the ``DeclSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current syntax node to the type conforming to the ``DeclSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } + + /// Checks if the current syntax node can be cast to the type conforming to the ``StmtSyntaxProtocol`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to the type conforming to the ``StmtSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current syntax node to the type conforming to the ``StmtSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } + + /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } } public let _syntaxNode: Syntax @@ -3453,6 +3563,94 @@ public struct ConditionElementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta .node(OptionalBindingConditionSyntax.self) ]) } + + /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } + + /// Checks if the current syntax node can be cast to ``AvailabilityConditionSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: AvailabilityConditionSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``AvailabilityConditionSyntax``. + /// + /// - Returns: An instance of ``AvailabilityConditionSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: AvailabilityConditionSyntax.Type) -> AvailabilityConditionSyntax? { + return AvailabilityConditionSyntax.init(self) + } + + /// Force-casts the current syntax node to ``AvailabilityConditionSyntax``. + /// + /// - Returns: An instance of ``AvailabilityConditionSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: AvailabilityConditionSyntax.Type) -> AvailabilityConditionSyntax { + return self.as(AvailabilityConditionSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``MatchingPatternConditionSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: MatchingPatternConditionSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``MatchingPatternConditionSyntax``. + /// + /// - Returns: An instance of ``MatchingPatternConditionSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: MatchingPatternConditionSyntax.Type) -> MatchingPatternConditionSyntax? { + return MatchingPatternConditionSyntax.init(self) + } + + /// Force-casts the current syntax node to ``MatchingPatternConditionSyntax``. + /// + /// - Returns: An instance of ``MatchingPatternConditionSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: MatchingPatternConditionSyntax.Type) -> MatchingPatternConditionSyntax { + return self.as(MatchingPatternConditionSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``OptionalBindingConditionSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: OptionalBindingConditionSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``OptionalBindingConditionSyntax``. + /// + /// - Returns: An instance of ``OptionalBindingConditionSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: OptionalBindingConditionSyntax.Type) -> OptionalBindingConditionSyntax? { + return OptionalBindingConditionSyntax.init(self) + } + + /// Force-casts the current syntax node to ``OptionalBindingConditionSyntax``. + /// + /// - Returns: An instance of ``OptionalBindingConditionSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: OptionalBindingConditionSyntax.Type) -> OptionalBindingConditionSyntax { + return self.as(OptionalBindingConditionSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift index d9bdf34420c..db727fe87e2 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift @@ -1735,6 +1735,50 @@ public struct DictionaryExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExp public static var structure: SyntaxNodeStructure { return .choices([.node(TokenSyntax.self), .node(DictionaryElementListSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``TokenSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: TokenSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: TokenSyntax.Type) -> TokenSyntax? { + return TokenSyntax.init(self) + } + + /// Force-casts the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: TokenSyntax.Type) -> TokenSyntax { + return self.as(TokenSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``DictionaryElementListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DictionaryElementListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DictionaryElementListSyntax``. + /// + /// - Returns: An instance of ``DictionaryElementListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DictionaryElementListSyntax.Type) -> DictionaryElementListSyntax? { + return DictionaryElementListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DictionaryElementListSyntax``. + /// + /// - Returns: An instance of ``DictionaryElementListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DictionaryElementListSyntax.Type) -> DictionaryElementListSyntax { + return self.as(DictionaryElementListSyntax.self)! + } } public let _syntaxNode: Syntax @@ -2409,6 +2453,50 @@ public struct DifferentiabilityWithRespectToArgumentSyntax: SyntaxProtocol, Synt public static var structure: SyntaxNodeStructure { return .choices([.node(DifferentiabilityArgumentSyntax.self), .node(DifferentiabilityArgumentsSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``DifferentiabilityArgumentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DifferentiabilityArgumentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DifferentiabilityArgumentSyntax``. + /// + /// - Returns: An instance of ``DifferentiabilityArgumentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DifferentiabilityArgumentSyntax.Type) -> DifferentiabilityArgumentSyntax? { + return DifferentiabilityArgumentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DifferentiabilityArgumentSyntax``. + /// + /// - Returns: An instance of ``DifferentiabilityArgumentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DifferentiabilityArgumentSyntax.Type) -> DifferentiabilityArgumentSyntax { + return self.as(DifferentiabilityArgumentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``DifferentiabilityArgumentsSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: DifferentiabilityArgumentsSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``DifferentiabilityArgumentsSyntax``. + /// + /// - Returns: An instance of ``DifferentiabilityArgumentsSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: DifferentiabilityArgumentsSyntax.Type) -> DifferentiabilityArgumentsSyntax? { + return DifferentiabilityArgumentsSyntax.init(self) + } + + /// Force-casts the current syntax node to ``DifferentiabilityArgumentsSyntax``. + /// + /// - Returns: An instance of ``DifferentiabilityArgumentsSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: DifferentiabilityArgumentsSyntax.Type) -> DifferentiabilityArgumentsSyntax { + return self.as(DifferentiabilityArgumentsSyntax.self)! + } } public let _syntaxNode: Syntax @@ -3156,6 +3244,50 @@ public struct DocumentationAttributeArgumentSyntax: SyntaxProtocol, SyntaxHashab public static var structure: SyntaxNodeStructure { return .choices([.node(TokenSyntax.self), .node(StringLiteralExprSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``TokenSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: TokenSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: TokenSyntax.Type) -> TokenSyntax? { + return TokenSyntax.init(self) + } + + /// Force-casts the current syntax node to ``TokenSyntax``. + /// + /// - Returns: An instance of ``TokenSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: TokenSyntax.Type) -> TokenSyntax { + return self.as(TokenSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``StringLiteralExprSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: StringLiteralExprSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``StringLiteralExprSyntax``. + /// + /// - Returns: An instance of ``StringLiteralExprSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: StringLiteralExprSyntax.Type) -> StringLiteralExprSyntax? { + return StringLiteralExprSyntax.init(self) + } + + /// Force-casts the current syntax node to ``StringLiteralExprSyntax``. + /// + /// - Returns: An instance of ``StringLiteralExprSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: StringLiteralExprSyntax.Type) -> StringLiteralExprSyntax { + return self.as(StringLiteralExprSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift index 9c972f62156..89972ebef47 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift @@ -833,6 +833,72 @@ public struct GenericRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyn public static var structure: SyntaxNodeStructure { return .choices([.node(SameTypeRequirementSyntax.self), .node(ConformanceRequirementSyntax.self), .node(LayoutRequirementSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``SameTypeRequirementSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SameTypeRequirementSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SameTypeRequirementSyntax``. + /// + /// - Returns: An instance of ``SameTypeRequirementSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SameTypeRequirementSyntax.Type) -> SameTypeRequirementSyntax? { + return SameTypeRequirementSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SameTypeRequirementSyntax``. + /// + /// - Returns: An instance of ``SameTypeRequirementSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SameTypeRequirementSyntax.Type) -> SameTypeRequirementSyntax { + return self.as(SameTypeRequirementSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``ConformanceRequirementSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: ConformanceRequirementSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``ConformanceRequirementSyntax``. + /// + /// - Returns: An instance of ``ConformanceRequirementSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: ConformanceRequirementSyntax.Type) -> ConformanceRequirementSyntax? { + return ConformanceRequirementSyntax.init(self) + } + + /// Force-casts the current syntax node to ``ConformanceRequirementSyntax``. + /// + /// - Returns: An instance of ``ConformanceRequirementSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: ConformanceRequirementSyntax.Type) -> ConformanceRequirementSyntax { + return self.as(ConformanceRequirementSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``LayoutRequirementSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: LayoutRequirementSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``LayoutRequirementSyntax``. + /// + /// - Returns: An instance of ``LayoutRequirementSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: LayoutRequirementSyntax.Type) -> LayoutRequirementSyntax? { + return LayoutRequirementSyntax.init(self) + } + + /// Force-casts the current syntax node to ``LayoutRequirementSyntax``. + /// + /// - Returns: An instance of ``LayoutRequirementSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: LayoutRequirementSyntax.Type) -> LayoutRequirementSyntax { + return self.as(LayoutRequirementSyntax.self)! + } } public let _syntaxNode: Syntax @@ -1686,6 +1752,116 @@ public struct IfConfigClauseSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxN .node(AttributeListSyntax.self) ]) } + + /// Checks if the current syntax node can be cast to ``CodeBlockItemListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: CodeBlockItemListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``CodeBlockItemListSyntax``. + /// + /// - Returns: An instance of ``CodeBlockItemListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: CodeBlockItemListSyntax.Type) -> CodeBlockItemListSyntax? { + return CodeBlockItemListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``CodeBlockItemListSyntax``. + /// + /// - Returns: An instance of ``CodeBlockItemListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: CodeBlockItemListSyntax.Type) -> CodeBlockItemListSyntax { + return self.as(CodeBlockItemListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``SwitchCaseListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SwitchCaseListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SwitchCaseListSyntax``. + /// + /// - Returns: An instance of ``SwitchCaseListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SwitchCaseListSyntax.Type) -> SwitchCaseListSyntax? { + return SwitchCaseListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SwitchCaseListSyntax``. + /// + /// - Returns: An instance of ``SwitchCaseListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SwitchCaseListSyntax.Type) -> SwitchCaseListSyntax { + return self.as(SwitchCaseListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``MemberBlockItemListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: MemberBlockItemListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``MemberBlockItemListSyntax``. + /// + /// - Returns: An instance of ``MemberBlockItemListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: MemberBlockItemListSyntax.Type) -> MemberBlockItemListSyntax? { + return MemberBlockItemListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``MemberBlockItemListSyntax``. + /// + /// - Returns: An instance of ``MemberBlockItemListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: MemberBlockItemListSyntax.Type) -> MemberBlockItemListSyntax { + return self.as(MemberBlockItemListSyntax.self)! + } + + /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } + + /// Checks if the current syntax node can be cast to ``AttributeListSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: AttributeListSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``AttributeListSyntax``. + /// + /// - Returns: An instance of ``AttributeListSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: AttributeListSyntax.Type) -> AttributeListSyntax? { + return AttributeListSyntax.init(self) + } + + /// Force-casts the current syntax node to ``AttributeListSyntax``. + /// + /// - Returns: An instance of ``AttributeListSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: AttributeListSyntax.Type) -> AttributeListSyntax { + return self.as(AttributeListSyntax.self)! + } } public let _syntaxNode: Syntax @@ -2016,6 +2192,50 @@ public struct IfExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxN public static var structure: SyntaxNodeStructure { return .choices([.node(IfExprSyntax.self), .node(CodeBlockSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``IfExprSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: IfExprSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``IfExprSyntax``. + /// + /// - Returns: An instance of ``IfExprSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: IfExprSyntax.Type) -> IfExprSyntax? { + return IfExprSyntax.init(self) + } + + /// Force-casts the current syntax node to ``IfExprSyntax``. + /// + /// - Returns: An instance of ``IfExprSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: IfExprSyntax.Type) -> IfExprSyntax { + return self.as(IfExprSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``CodeBlockSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: CodeBlockSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``CodeBlockSyntax``. + /// + /// - Returns: An instance of ``CodeBlockSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: CodeBlockSyntax.Type) -> CodeBlockSyntax? { + return CodeBlockSyntax.init(self) + } + + /// Force-casts the current syntax node to ``CodeBlockSyntax``. + /// + /// - Returns: An instance of ``CodeBlockSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: CodeBlockSyntax.Type) -> CodeBlockSyntax { + return self.as(CodeBlockSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index a5564a5849e..c40da676fe8 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -70,6 +70,72 @@ public struct KeyPathComponentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta public static var structure: SyntaxNodeStructure { return .choices([.node(KeyPathPropertyComponentSyntax.self), .node(KeyPathSubscriptComponentSyntax.self), .node(KeyPathOptionalComponentSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``KeyPathPropertyComponentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: KeyPathPropertyComponentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``KeyPathPropertyComponentSyntax``. + /// + /// - Returns: An instance of ``KeyPathPropertyComponentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: KeyPathPropertyComponentSyntax.Type) -> KeyPathPropertyComponentSyntax? { + return KeyPathPropertyComponentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``KeyPathPropertyComponentSyntax``. + /// + /// - Returns: An instance of ``KeyPathPropertyComponentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: KeyPathPropertyComponentSyntax.Type) -> KeyPathPropertyComponentSyntax { + return self.as(KeyPathPropertyComponentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``KeyPathSubscriptComponentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: KeyPathSubscriptComponentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``KeyPathSubscriptComponentSyntax``. + /// + /// - Returns: An instance of ``KeyPathSubscriptComponentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: KeyPathSubscriptComponentSyntax.Type) -> KeyPathSubscriptComponentSyntax? { + return KeyPathSubscriptComponentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``KeyPathSubscriptComponentSyntax``. + /// + /// - Returns: An instance of ``KeyPathSubscriptComponentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: KeyPathSubscriptComponentSyntax.Type) -> KeyPathSubscriptComponentSyntax { + return self.as(KeyPathSubscriptComponentSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``KeyPathOptionalComponentSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: KeyPathOptionalComponentSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``KeyPathOptionalComponentSyntax``. + /// + /// - Returns: An instance of ``KeyPathOptionalComponentSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: KeyPathOptionalComponentSyntax.Type) -> KeyPathOptionalComponentSyntax? { + return KeyPathOptionalComponentSyntax.init(self) + } + + /// Force-casts the current syntax node to ``KeyPathOptionalComponentSyntax``. + /// + /// - Returns: An instance of ``KeyPathOptionalComponentSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: KeyPathOptionalComponentSyntax.Type) -> KeyPathOptionalComponentSyntax { + return self.as(KeyPathOptionalComponentSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift index 9ddab3d3b12..d14d46d8243 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift @@ -3570,6 +3570,50 @@ public struct SwitchCaseSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeP public static var structure: SyntaxNodeStructure { return .choices([.node(SwitchDefaultLabelSyntax.self), .node(SwitchCaseLabelSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``SwitchDefaultLabelSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SwitchDefaultLabelSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SwitchDefaultLabelSyntax``. + /// + /// - Returns: An instance of ``SwitchDefaultLabelSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SwitchDefaultLabelSyntax.Type) -> SwitchDefaultLabelSyntax? { + return SwitchDefaultLabelSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SwitchDefaultLabelSyntax``. + /// + /// - Returns: An instance of ``SwitchDefaultLabelSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SwitchDefaultLabelSyntax.Type) -> SwitchDefaultLabelSyntax { + return self.as(SwitchDefaultLabelSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``SwitchCaseLabelSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SwitchCaseLabelSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SwitchCaseLabelSyntax``. + /// + /// - Returns: An instance of ``SwitchCaseLabelSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SwitchCaseLabelSyntax.Type) -> SwitchCaseLabelSyntax? { + return SwitchCaseLabelSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SwitchCaseLabelSyntax``. + /// + /// - Returns: An instance of ``SwitchCaseLabelSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SwitchCaseLabelSyntax.Type) -> SwitchCaseLabelSyntax { + return self.as(SwitchCaseLabelSyntax.self)! + } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index cfd4d0d8c9a..d9c90433f92 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -3958,6 +3958,50 @@ public struct YieldStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSynt public static var structure: SyntaxNodeStructure { return .choices([.node(YieldedExpressionsClauseSyntax.self), .node(ExprSyntax.self)]) } + + /// Checks if the current syntax node can be cast to ``YieldedExpressionsClauseSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: YieldedExpressionsClauseSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``YieldedExpressionsClauseSyntax``. + /// + /// - Returns: An instance of ``YieldedExpressionsClauseSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: YieldedExpressionsClauseSyntax.Type) -> YieldedExpressionsClauseSyntax? { + return YieldedExpressionsClauseSyntax.init(self) + } + + /// Force-casts the current syntax node to ``YieldedExpressionsClauseSyntax``. + /// + /// - Returns: An instance of ``YieldedExpressionsClauseSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: YieldedExpressionsClauseSyntax.Type) -> YieldedExpressionsClauseSyntax { + return self.as(YieldedExpressionsClauseSyntax.self)! + } + + /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: S.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + public func `as`(_ syntaxType: S.Type) -> S? { + return S.init(self) + } + + /// Force-casts the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. + /// + /// - Returns: An instance of the specialized type. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: S.Type) -> S { + return self.as(S.self)! + } } public let _syntaxNode: Syntax