Skip to content

Commit

Permalink
305: Acknowledge deprecated option
Browse files Browse the repository at this point in the history
Signed-off-by: Eddie Seay <[email protected]>
  • Loading branch information
eseay committed Oct 24, 2024
1 parent 9bed141 commit 4ee7dcb
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ final class ConnectClientGenerator: Generator {
private func printCallbackMethodInterface(for method: MethodDescriptor) {
self.printLine()
self.printCommentsIfNeeded(for: method)
if let availabilityAnnotation = method.callbackAvailabilityAnnotation() {
self.printLine(availabilityAnnotation)
}
if !method.serverStreaming && !method.clientStreaming {
self.printLine("@discardableResult")
}
Expand All @@ -133,7 +136,7 @@ final class ConnectClientGenerator: Generator {
private func printAsyncAwaitMethodInterface(for method: MethodDescriptor) {
self.printLine()
self.printCommentsIfNeeded(for: method)
self.printLine("@available(iOS 13, *)")
self.printLine(method.asyncAwaitAvailabilityAnnotation())
self.printLine(
method.asyncAwaitSignature(
using: self.namer, includeDefaults: false, options: self.options
Expand All @@ -143,6 +146,9 @@ final class ConnectClientGenerator: Generator {

private func printCallbackMethodImplementation(for method: MethodDescriptor) {
self.printLine()
if let availabilityAnnotation = method.callbackAvailabilityAnnotation() {
self.printLine(availabilityAnnotation)
}
if !method.serverStreaming && !method.clientStreaming {
self.printLine("@discardableResult")
}
Expand All @@ -162,7 +168,7 @@ final class ConnectClientGenerator: Generator {

private func printAsyncAwaitMethodImplementation(for method: MethodDescriptor) {
self.printLine()
self.printLine("@available(iOS 13, *)")
self.printLine(method.asyncAwaitAvailabilityAnnotation())
self.printLine(
"\(self.visibility) "
+ method.asyncAwaitSignature(
Expand Down Expand Up @@ -201,6 +207,30 @@ private extension MethodDescriptor {
}
}

func callbackAvailabilityAnnotation() -> String? {
if self.options.deprecated {
// swiftlint:disable line_length
return """
@available(iOS, introduced: 12, deprecated: 12, message: "This function has been marked deprecated.")
@available(macOS, introduced: 10.15, deprecated: 10.15, message: "This function has been marked deprecated.")
@available(tvOS, introduced: 13, deprecated: 13, message: "This function has been marked deprecated.")
@available(watchOS, introduced: 6, deprecated: 6, message: "This function has been marked deprecated.")
"""
// swiftlint:enable line_length
} else {
return nil
}
}

func asyncAwaitAvailabilityAnnotation() -> String {
if self.options.deprecated {
// swiftlint:disable:next line_length
return "@available(iOS, introduced: 13, deprecated: 13, message: \"This function has been marked deprecated.\")"
} else {
return "@available(iOS 13, *)"
}
}

func callbackReturnValue() -> String {
if self.clientStreaming && self.serverStreaming {
return """
Expand Down

0 comments on commit 4ee7dcb

Please sign in to comment.