Skip to content

Commit 305b5e5

Browse files
authored
Merge pull request #2613 from Matejkob/6.0-no-public-extensions-in-generated-code
[6.0] Move `public` from extension decl to each decl in the extension in generated files
2 parents d7bed36 + ebd96a7 commit 305b5e5

File tree

10 files changed

+313
-313
lines changed

10 files changed

+313
-313
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ let renamedSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3434
}
3535
}
3636

37-
try! ExtensionDeclSyntax("public extension SyntaxKind") {
37+
try! ExtensionDeclSyntax("extension SyntaxKind") {
3838
let syntaxKinds = SyntaxNodeKind.allCases.sorted(by: { $0.deprecatedRawValue ?? "" < $1.deprecatedRawValue ?? "" })
3939
for syntaxKind in syntaxKinds {
4040
if let deprecatedName = syntaxKind.deprecatedRawValue {
4141
DeclSyntax(
4242
"""
4343
\(deprecationAttribute(for: syntaxKind))
44-
static var \(raw: deprecatedName): Self {
44+
public static var \(raw: deprecatedName): Self {
4545
return .\(syntaxKind.varOrCaseName)
4646
}
4747
"""

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
145145
"""#
146146
)
147147

148-
try! ExtensionDeclSyntax("public extension Syntax") {
148+
try! ExtensionDeclSyntax("extension Syntax") {
149149
DeclSyntax(
150150
"""
151151
/// Check whether the non-type erased version of this syntax node conforms to
152152
/// \(node.kind.protocolType).
153153
///
154154
/// - Note: This will incur an existential conversion.
155-
func isProtocol(_: \(node.kind.protocolType).Protocol) -> Bool {
155+
public func isProtocol(_: \(node.kind.protocolType).Protocol) -> Bool {
156156
return self.asProtocol(\(node.kind.protocolType).self) != nil
157157
}
158158
"""
@@ -164,7 +164,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
164164
/// \(node.kind.protocolType). Otherwise return nil.
165165
///
166166
/// - Note: This will incur an existential conversion.
167-
func asProtocol(_: \(node.kind.protocolType).Protocol) -> \(node.kind.protocolType)? {
167+
public func asProtocol(_: \(node.kind.protocolType).Protocol) -> \(node.kind.protocolType)? {
168168
return self.asProtocol(SyntaxProtocol.self) as? \(node.kind.protocolType)
169169
}
170170
"""
@@ -337,15 +337,15 @@ private func leafProtocolDecl(type: TypeSyntax, inheritedType: TypeSyntax) -> De
337337
private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax) -> DeclSyntax {
338338
DeclSyntax(
339339
#"""
340-
public extension \#(type) {
340+
extension \#(type) {
341341
/// Checks if the current leaf syntax node can be cast to a different specified type.
342342
///
343343
/// - Returns: `false` since the leaf node cannot be cast to a different specified type.
344344
///
345345
/// - Note: This method overloads the general `is` method and is marked as deprecated to produce a warning,
346346
/// informing the user that the cast will always fail.
347347
@available(*, deprecated, message: "This cast will always fail")
348-
func `is`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> Bool {
348+
public func `is`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> Bool {
349349
return false
350350
}
351351
@@ -356,7 +356,7 @@ private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax)
356356
/// - Note: This method overloads the general `as` method and is marked as deprecated to produce a warning,
357357
/// informing the user that the cast will always fail.
358358
@available(*, deprecated, message: "This cast will always fail")
359-
func `as`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S? {
359+
public func `as`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S? {
360360
return nil
361361
}
362362
@@ -368,7 +368,7 @@ private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax)
368368
/// informing the user that the cast will always fail.
369369
/// - Warning: Invoking this method will lead to a fatal error.
370370
@available(*, deprecated, message: "This cast will always fail")
371-
func cast<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S {
371+
public func cast<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S {
372372
fatalError("\(Self.self) cannot be cast to \(S.self)")
373373
}
374374
}

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxEnumFile.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ let syntaxEnumFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3535

3636
try! ExtensionDeclSyntax(
3737
"""
38-
public extension Syntax
38+
extension Syntax
3939
"""
4040
) {
4141
try FunctionDeclSyntax(
4242
"""
4343
/// Get an enum that can be used to exhaustively switch over all syntax nodes.
44-
func `as`(_: SyntaxEnum.Type) -> SyntaxEnum
44+
public func `as`(_: SyntaxEnum.Type) -> SyntaxEnum
4545
"""
4646
) {
4747
try SwitchExprSyntax("switch raw.kind") {
@@ -81,13 +81,13 @@ let syntaxEnumFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
8181

8282
try! ExtensionDeclSyntax(
8383
"""
84-
public extension \(baseKind.syntaxType)
84+
extension \(baseKind.syntaxType)
8585
"""
8686
) {
8787
try FunctionDeclSyntax(
8888
"""
8989
/// Get an enum that can be used to exhaustively switch over all \(raw: baseName) syntax nodes.
90-
func `as`(_: \(enumType).Type) -> \(enumType)
90+
public func `as`(_: \(enumType).Type) -> \(enumType)
9191
"""
9292
) {
9393
try SwitchExprSyntax("switch raw.kind") {

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxTraitsFile.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3939
}
4040
}
4141

42-
try! ExtensionDeclSyntax("public extension \(trait.protocolName)") {
42+
try! ExtensionDeclSyntax("extension \(trait.protocolName)") {
4343
DeclSyntax(
4444
"""
4545
/// Without this function, the `with` function defined on `SyntaxProtocol`
4646
/// does not work on existentials of this protocol type.
4747
@_disfavoredOverload
48-
func with<T>(_ keyPath: WritableKeyPath<\(trait.protocolName), T>, _ newChild: T) -> \(trait.protocolName) {
48+
public func with<T>(_ keyPath: WritableKeyPath<\(trait.protocolName), T>, _ newChild: T) -> \(trait.protocolName) {
4949
var copy: \(trait.protocolName) = self
5050
copy[keyPath: keyPath] = newChild
5151
return copy
@@ -54,13 +54,13 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
5454
)
5555
}
5656

57-
try! ExtensionDeclSyntax("public extension SyntaxProtocol") {
57+
try! ExtensionDeclSyntax("extension SyntaxProtocol") {
5858
DeclSyntax(
5959
"""
6060
/// Check whether the non-type erased version of this syntax node conforms to
6161
/// `\(trait.protocolName)`.
6262
/// Note that this will incur an existential conversion.
63-
func isProtocol(_: \(trait.protocolName).Protocol) -> Bool {
63+
public func isProtocol(_: \(trait.protocolName).Protocol) -> Bool {
6464
return self.asProtocol(\(trait.protocolName).self) != nil
6565
}
6666
"""
@@ -71,7 +71,7 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
7171
/// Return the non-type erased version of this syntax node if it conforms to
7272
/// `\(trait.protocolName)`. Otherwise return `nil`.
7373
/// Note that this will incur an existential conversion.
74-
func asProtocol(_: \(trait.protocolName).Protocol) -> \(trait.protocolName)? {
74+
public func asProtocol(_: \(trait.protocolName).Protocol) -> \(trait.protocolName)? {
7575
return Syntax(self).asProtocol(SyntaxProtocol.self) as? \(trait.protocolName)
7676
}
7777
"""

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ let resultBuildersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6060

6161
DeclSyntax(
6262
"""
63-
public extension \(type.syntaxBaseName) {
64-
init(@\(type.resultBuilderType) itemsBuilder: () throws -> \(type.syntaxBaseName)) rethrows {
63+
extension \(type.syntaxBaseName) {
64+
public init(@\(type.resultBuilderType) itemsBuilder: () throws -> \(type.syntaxBaseName)) rethrows {
6565
self = try itemsBuilder()
6666
}
6767
}

0 commit comments

Comments
 (0)