File tree 4 files changed +10
-283
lines changed
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder
Sources/SwiftSyntaxBuilder
4 files changed +10
-283
lines changed Original file line number Diff line number Diff line change @@ -23,38 +23,14 @@ let buildableNodesFile = SourceFileSyntax {
23
23
24
24
for node in SYNTAX_NODES where node. isBuildable {
25
25
let type = node. type
26
- let hasTrailingComma = node. traits. contains ( " WithTrailingComma " )
27
26
28
- let convenienceInit = createConvenienceInitializer ( node: node)
29
- if convenienceInit != nil || hasTrailingComma {
27
+ if let convenienceInit = createConvenienceInitializer ( node: node) {
30
28
let docComment : SwiftSyntax . Trivia = node. documentation. isEmpty ? [ ] : . docLineComment( " /// \( node. documentation) " ) + . newline
31
29
ExtensionDeclSyntax (
32
30
leadingTrivia: docComment,
33
- extendedType: SimpleTypeIdentifierSyntax ( name: . identifier( type. syntaxBaseName) ) ,
34
- inheritanceClause: hasTrailingComma ? TypeInheritanceClauseSyntax { InheritedTypeSyntax ( typeName: TypeSyntax ( " HasTrailingComma " ) ) } : nil
31
+ extendedType: SimpleTypeIdentifierSyntax ( name: . identifier( type. syntaxBaseName) )
35
32
) {
36
- if let convenienceInit = convenienceInit {
37
- convenienceInit
38
- }
39
-
40
- if hasTrailingComma {
41
- VariableDeclSyntax (
42
- """
43
- var hasTrailingComma: Bool {
44
- return trailingComma != nil
45
- }
46
- """
47
- )
48
-
49
- FunctionDeclSyntax (
50
- """
51
- /// Conformance to `HasTrailingComma`.
52
- public func withTrailingComma(_ withComma: Bool) -> Self {
53
- return withTrailingComma(withComma ? .commaToken() : nil)
54
- }
55
- """
56
- )
57
- }
33
+ convenienceInit
58
34
}
59
35
}
60
36
}
Original file line number Diff line number Diff line change 8
8
9
9
add_swift_host_library(SwiftSyntaxBuilder
10
10
ConvenienceInitializers.swift
11
- HasTrailingComma.swift
12
11
Indenter.swift
13
12
ResultBuilderExtensions.swift
14
13
Syntax+StringInterpolation.swift
15
14
SyntaxNodeWithBody.swift
15
+ WithTrailingCommaSyntax+EnsuringTrailingComma.swift
16
16
17
17
18
18
generated /BuildableCollectionNodes.swift
Original file line number Diff line number Diff line change 12
12
13
13
import SwiftSyntax
14
14
15
- protocol HasTrailingComma {
16
- var hasTrailingComma : Bool { get }
17
-
18
- /// Returns this node overriding presence of the trailing comma
19
- func withTrailingComma( _ withComma: Bool ) -> Self
20
- }
21
-
22
- extension HasTrailingComma {
15
+ extension WithTrailingCommaSyntax {
23
16
func ensuringTrailingComma( ) -> Self {
24
- hasTrailingComma ? self : withTrailingComma ( true )
17
+ if trailingComma == nil {
18
+ return self . withTrailingComma ( . commaToken( ) )
19
+ } else {
20
+ return self
21
+ }
25
22
}
26
23
}
You can’t perform that action at this time.
0 commit comments