Skip to content

Commit

Permalink
305: Acknowledge deprecated option
Browse files Browse the repository at this point in the history
  • Loading branch information
eseay committed Oct 24, 2024
1 parent 9bed141 commit 6be74d8
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 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,27 @@ private extension MethodDescriptor {
}
}

func callbackAvailabilityAnnotation() -> String? {
if self.options.deprecated {
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.")
"""
} else {
return nil
}
}

func asyncAwaitAvailabilityAnnotation() -> String {
if self.options.deprecated {
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 6be74d8

Please sign in to comment.