Skip to content

[6.0] Move public from extension decl to each decl in the extension in generated files #2613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ let renamedSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
}
}

try! ExtensionDeclSyntax("public extension SyntaxKind") {
try! ExtensionDeclSyntax("extension SyntaxKind") {
let syntaxKinds = SyntaxNodeKind.allCases.sorted(by: { $0.deprecatedRawValue ?? "" < $1.deprecatedRawValue ?? "" })
for syntaxKind in syntaxKinds {
if let deprecatedName = syntaxKind.deprecatedRawValue {
DeclSyntax(
"""
\(deprecationAttribute(for: syntaxKind))
static var \(raw: deprecatedName): Self {
public static var \(raw: deprecatedName): Self {
return .\(syntaxKind.varOrCaseName)
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
"""#
)

try! ExtensionDeclSyntax("public extension Syntax") {
try! ExtensionDeclSyntax("extension Syntax") {
DeclSyntax(
"""
/// Check whether the non-type erased version of this syntax node conforms to
/// \(node.kind.protocolType).
///
/// - Note: This will incur an existential conversion.
func isProtocol(_: \(node.kind.protocolType).Protocol) -> Bool {
public func isProtocol(_: \(node.kind.protocolType).Protocol) -> Bool {
return self.asProtocol(\(node.kind.protocolType).self) != nil
}
"""
Expand All @@ -164,7 +164,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
/// \(node.kind.protocolType). Otherwise return nil.
///
/// - Note: This will incur an existential conversion.
func asProtocol(_: \(node.kind.protocolType).Protocol) -> \(node.kind.protocolType)? {
public func asProtocol(_: \(node.kind.protocolType).Protocol) -> \(node.kind.protocolType)? {
return self.asProtocol(SyntaxProtocol.self) as? \(node.kind.protocolType)
}
"""
Expand Down Expand Up @@ -337,15 +337,15 @@ private func leafProtocolDecl(type: TypeSyntax, inheritedType: TypeSyntax) -> De
private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax) -> DeclSyntax {
DeclSyntax(
#"""
public extension \#(type) {
extension \#(type) {
/// Checks if the current leaf syntax node can be cast to a different specified type.
///
/// - Returns: `false` since the leaf node cannot be cast to a different specified type.
///
/// - Note: This method overloads the general `is` method and is marked as deprecated to produce a warning,
/// informing the user that the cast will always fail.
@available(*, deprecated, message: "This cast will always fail")
func `is`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> Bool {
public func `is`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> Bool {
return false
}

Expand All @@ -356,7 +356,7 @@ private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax)
/// - Note: This method overloads the general `as` method and is marked as deprecated to produce a warning,
/// informing the user that the cast will always fail.
@available(*, deprecated, message: "This cast will always fail")
func `as`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S? {
public func `as`<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S? {
return nil
}

Expand All @@ -368,7 +368,7 @@ private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax)
/// informing the user that the cast will always fail.
/// - Warning: Invoking this method will lead to a fatal error.
@available(*, deprecated, message: "This cast will always fail")
func cast<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S {
public func cast<S: \#(inheritedType)>(_ syntaxType: S.Type) -> S {
fatalError("\(Self.self) cannot be cast to \(S.self)")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ let syntaxEnumFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

try! ExtensionDeclSyntax(
"""
public extension Syntax
extension Syntax
"""
) {
try FunctionDeclSyntax(
"""
/// Get an enum that can be used to exhaustively switch over all syntax nodes.
func `as`(_: SyntaxEnum.Type) -> SyntaxEnum
public func `as`(_: SyntaxEnum.Type) -> SyntaxEnum
"""
) {
try SwitchExprSyntax("switch raw.kind") {
Expand Down Expand Up @@ -81,13 +81,13 @@ let syntaxEnumFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

try! ExtensionDeclSyntax(
"""
public extension \(baseKind.syntaxType)
extension \(baseKind.syntaxType)
"""
) {
try FunctionDeclSyntax(
"""
/// Get an enum that can be used to exhaustively switch over all \(raw: baseName) syntax nodes.
func `as`(_: \(enumType).Type) -> \(enumType)
public func `as`(_: \(enumType).Type) -> \(enumType)
"""
) {
try SwitchExprSyntax("switch raw.kind") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
}
}

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

try! ExtensionDeclSyntax("public extension SyntaxProtocol") {
try! ExtensionDeclSyntax("extension SyntaxProtocol") {
DeclSyntax(
"""
/// Check whether the non-type erased version of this syntax node conforms to
/// `\(trait.protocolName)`.
/// Note that this will incur an existential conversion.
func isProtocol(_: \(trait.protocolName).Protocol) -> Bool {
public func isProtocol(_: \(trait.protocolName).Protocol) -> Bool {
return self.asProtocol(\(trait.protocolName).self) != nil
}
"""
Expand All @@ -71,7 +71,7 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
/// Return the non-type erased version of this syntax node if it conforms to
/// `\(trait.protocolName)`. Otherwise return `nil`.
/// Note that this will incur an existential conversion.
func asProtocol(_: \(trait.protocolName).Protocol) -> \(trait.protocolName)? {
public func asProtocol(_: \(trait.protocolName).Protocol) -> \(trait.protocolName)? {
return Syntax(self).asProtocol(SyntaxProtocol.self) as? \(trait.protocolName)
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ let resultBuildersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

DeclSyntax(
"""
public extension \(type.syntaxBaseName) {
init(@\(type.resultBuilderType) itemsBuilder: () throws -> \(type.syntaxBaseName)) rethrows {
extension \(type.syntaxBaseName) {
public init(@\(type.resultBuilderType) itemsBuilder: () throws -> \(type.syntaxBaseName)) rethrows {
self = try itemsBuilder()
}
}
Expand Down
Loading