Skip to content

Commit 58509d1

Browse files
authored
Merge pull request #1589 from andrewjl/ajlb/struct-decl-node-description
SyntaxSupport Node Documentation: StructDecl
2 parents 18bd544 + 6ca0913 commit 58509d1

File tree

3 files changed

+186
-4
lines changed

3 files changed

+186
-4
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,63 @@ public let DECL_NODES: [Node] = [
18051805
Node(
18061806
name: "StructDecl",
18071807
nameForDiagnostics: "struct",
1808+
description: """
1809+
A struct declaration like the following.
1810+
1811+
```swift
1812+
struct SomeStruct {
1813+
let someMember: String
1814+
var anotherMember: Int
1815+
1816+
func foo() {
1817+
print(someMember)
1818+
}
1819+
1820+
mutating func bar() {
1821+
anotherMember = 42
1822+
}
1823+
}
1824+
```
1825+
1826+
A struct declaration may be declared without any members.
1827+
1828+
```swift
1829+
struct EmptyStruct {
1830+
1831+
}
1832+
```
1833+
1834+
A struct declaration may include a type inheritance clause listing
1835+
one or more protocols the struct conforms to.
1836+
1837+
The example below uses Hashable and Equatable protocols whose members
1838+
are automatically synthesized by the compiler if the struct contains
1839+
stored members that are themselves `Hashable` and `Equatable`.
1840+
1841+
```swift
1842+
struct AdvancedStruct: Hashable, Equatable {
1843+
let someMember: String
1844+
var anotherMember: Int
1845+
}
1846+
```
1847+
1848+
A struct declaration may include a generic parameter clause as well
1849+
as a generic where clause.
1850+
1851+
```swift
1852+
struct Stack<Element> {
1853+
var items: [Element] = []
1854+
1855+
mutating func push(_ item: Element) {
1856+
items.append(item)
1857+
}
1858+
1859+
mutating func pop() -> Element {
1860+
return items.removeLast()
1861+
}
1862+
}
1863+
```
1864+
""",
18081865
kind: "Decl",
18091866
traits: [
18101867
"DeclGroup",
@@ -1816,43 +1873,51 @@ public let DECL_NODES: [Node] = [
18161873
name: "Attributes",
18171874
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
18181875
nameForDiagnostics: "attributes",
1876+
description: "Attributes that are attached to the struct declaration.",
18191877
isOptional: true
18201878
),
18211879
Child(
18221880
name: "Modifiers",
18231881
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
18241882
nameForDiagnostics: "modifiers",
1883+
description: "Modifiers that are attached to the struct declaration.",
18251884
isOptional: true
18261885
),
18271886
Child(
18281887
name: "StructKeyword",
1829-
kind: .token(choices: [.keyword(text: "struct")])
1888+
kind: .token(choices: [.keyword(text: "struct")]),
1889+
description: "The `struct` keyword for this declaration."
18301890
),
18311891
Child(
18321892
name: "Identifier",
1833-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")])
1893+
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
1894+
description: "Declares the name of this struct. If the name matches a reserved keyword use backticks to escape it."
18341895
),
18351896
Child(
18361897
name: "GenericParameterClause",
18371898
kind: .node(kind: "GenericParameterClause"),
18381899
nameForDiagnostics: "generic parameter clause",
1900+
description: "The generic parameters, if any, of the struct declaration.",
18391901
isOptional: true
18401902
),
18411903
Child(
18421904
name: "InheritanceClause",
18431905
kind: .node(kind: "TypeInheritanceClause"),
18441906
nameForDiagnostics: "type inheritance clause",
1907+
description: "The struct declaration inheritance clause describing one or more conformances for this struct declaration.",
18451908
isOptional: true
18461909
),
18471910
Child(
18481911
name: "GenericWhereClause",
18491912
kind: .node(kind: "GenericWhereClause"),
18501913
nameForDiagnostics: "generic where clause",
1914+
description: "The `where` clause that applies to the generic parameters of this struct declaration.",
18511915
isOptional: true
18521916
),
18531917
Child(
18541918
name: "MemberBlock",
1855-
kind: .node(kind: "MemberDeclBlock")
1919+
kind: .node(kind: "MemberDeclBlock"),
1920+
description: "The members of the struct declaration. Because struct extension declarations may declare additional members the contents of this member block isn't guaranteed to be a complete list of members for this type."
18561921
),
18571922
]
18581923
),

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5117,7 +5117,61 @@ public struct ProtocolDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
51175117

51185118
// MARK: - StructDeclSyntax
51195119

5120-
5120+
/// A struct declaration like the following.
5121+
///
5122+
/// ```swift
5123+
/// struct SomeStruct {
5124+
/// let someMember: String
5125+
/// var anotherMember: Int
5126+
///
5127+
/// func foo() {
5128+
/// print(someMember)
5129+
/// }
5130+
///
5131+
/// mutating func bar() {
5132+
/// anotherMember = 42
5133+
/// }
5134+
/// }
5135+
/// ```
5136+
///
5137+
/// A struct declaration may be declared without any members.
5138+
///
5139+
/// ```swift
5140+
/// struct EmptyStruct {
5141+
///
5142+
/// }
5143+
/// ```
5144+
///
5145+
/// A struct declaration may include a type inheritance clause listing
5146+
/// one or more protocols the struct conforms to.
5147+
///
5148+
/// The example below uses Hashable and Equatable protocols whose members
5149+
/// are automatically synthesized by the compiler if the struct contains
5150+
/// stored members that are themselves `Hashable` and `Equatable`.
5151+
///
5152+
/// ```swift
5153+
/// struct AdvancedStruct: Hashable, Equatable {
5154+
/// let someMember: String
5155+
/// var anotherMember: Int
5156+
/// }
5157+
/// ```
5158+
///
5159+
/// A struct declaration may include a generic parameter clause as well
5160+
/// as a generic where clause.
5161+
///
5162+
/// ```swift
5163+
/// struct Stack<Element> {
5164+
/// var items: [Element] = []
5165+
///
5166+
/// mutating func push(_ item: Element) {
5167+
/// items.append(item)
5168+
/// }
5169+
///
5170+
/// mutating func pop() -> Element {
5171+
/// return items.removeLast()
5172+
/// }
5173+
/// }
5174+
/// ```
51215175
public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
51225176
public let _syntaxNode: Syntax
51235177

@@ -5220,6 +5274,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
52205274
}
52215275
}
52225276

5277+
/// Attributes that are attached to the struct declaration.
52235278
public var attributes: AttributeListSyntax? {
52245279
get {
52255280
return data.child(at: 1, parent: Syntax(self)).map(AttributeListSyntax.init)
@@ -5257,6 +5312,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
52575312
}
52585313
}
52595314

5315+
/// Modifiers that are attached to the struct declaration.
52605316
public var modifiers: ModifierListSyntax? {
52615317
get {
52625318
return data.child(at: 3, parent: Syntax(self)).map(ModifierListSyntax.init)
@@ -5294,6 +5350,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
52945350
}
52955351
}
52965352

5353+
/// The `struct` keyword for this declaration.
52975354
public var structKeyword: TokenSyntax {
52985355
get {
52995356
return TokenSyntax(data.child(at: 5, parent: Syntax(self))!)
@@ -5312,6 +5369,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
53125369
}
53135370
}
53145371

5372+
/// Declares the name of this struct. If the name matches a reserved keyword use backticks to escape it.
53155373
public var identifier: TokenSyntax {
53165374
get {
53175375
return TokenSyntax(data.child(at: 7, parent: Syntax(self))!)
@@ -5330,6 +5388,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
53305388
}
53315389
}
53325390

5391+
/// The generic parameters, if any, of the struct declaration.
53335392
public var genericParameterClause: GenericParameterClauseSyntax? {
53345393
get {
53355394
return data.child(at: 9, parent: Syntax(self)).map(GenericParameterClauseSyntax.init)
@@ -5348,6 +5407,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
53485407
}
53495408
}
53505409

5410+
/// The struct declaration inheritance clause describing one or more conformances for this struct declaration.
53515411
public var inheritanceClause: TypeInheritanceClauseSyntax? {
53525412
get {
53535413
return data.child(at: 11, parent: Syntax(self)).map(TypeInheritanceClauseSyntax.init)
@@ -5366,6 +5426,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
53665426
}
53675427
}
53685428

5429+
/// The `where` clause that applies to the generic parameters of this struct declaration.
53695430
public var genericWhereClause: GenericWhereClauseSyntax? {
53705431
get {
53715432
return data.child(at: 13, parent: Syntax(self)).map(GenericWhereClauseSyntax.init)
@@ -5384,6 +5445,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
53845445
}
53855446
}
53865447

5448+
/// The members of the struct declaration. Because struct extension declarations may declare additional members the contents of this member block isn't guaranteed to be a complete list of members for this type.
53875449
public var memberBlock: MemberDeclBlockSyntax {
53885450
get {
53895451
return MemberDeclBlockSyntax(data.child(at: 15, parent: Syntax(self))!)

Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,61 @@ extension SourceFileSyntax {
11711171
}
11721172
}
11731173

1174+
/// A struct declaration like the following.
1175+
///
1176+
/// ```swift
1177+
/// struct SomeStruct {
1178+
/// let someMember: String
1179+
/// var anotherMember: Int
1180+
///
1181+
/// func foo() {
1182+
/// print(someMember)
1183+
/// }
1184+
///
1185+
/// mutating func bar() {
1186+
/// anotherMember = 42
1187+
/// }
1188+
/// }
1189+
/// ```
1190+
///
1191+
/// A struct declaration may be declared without any members.
1192+
///
1193+
/// ```swift
1194+
/// struct EmptyStruct {
1195+
///
1196+
/// }
1197+
/// ```
1198+
///
1199+
/// A struct declaration may include a type inheritance clause listing
1200+
/// one or more protocols the struct conforms to.
1201+
///
1202+
/// The example below uses Hashable and Equatable protocols whose members
1203+
/// are automatically synthesized by the compiler if the struct contains
1204+
/// stored members that are themselves `Hashable` and `Equatable`.
1205+
///
1206+
/// ```swift
1207+
/// struct AdvancedStruct: Hashable, Equatable {
1208+
/// let someMember: String
1209+
/// var anotherMember: Int
1210+
/// }
1211+
/// ```
1212+
///
1213+
/// A struct declaration may include a generic parameter clause as well
1214+
/// as a generic where clause.
1215+
///
1216+
/// ```swift
1217+
/// struct Stack<Element> {
1218+
/// var items: [Element] = []
1219+
///
1220+
/// mutating func push(_ item: Element) {
1221+
/// items.append(item)
1222+
/// }
1223+
///
1224+
/// mutating func pop() -> Element {
1225+
/// return items.removeLast()
1226+
/// }
1227+
/// }
1228+
/// ```
11741229
extension StructDeclSyntax {
11751230
/// A convenience initializer that allows initializing syntax collections using result builders
11761231
public init(

0 commit comments

Comments
 (0)