Skip to content

Commit

Permalink
305: Apply deprecation annotations for generated mocks
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 4ee7dcb commit 24ae23d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ final class ConnectMockGenerator: Generator {

private func printCallbackMethodMockImplementation(for method: MethodDescriptor) {
self.printLine()
if let availabilityAnnotation = method.callbackAvailabilityAnnotation() {
self.printLine(availabilityAnnotation)
}
if !method.serverStreaming && !method.clientStreaming {
self.printLine("@discardableResult")
}
Expand Down Expand Up @@ -150,7 +153,9 @@ final class ConnectMockGenerator: Generator {

private func printAsyncAwaitMethodMockImplementation(for method: MethodDescriptor) {
self.printLine()

if let availabilityAnnotation = method.asyncAwaitAvailabilityAnnotation() {
self.printLine(availabilityAnnotation)
}
self.printLine(
"\(self.typeVisibility) "
+ method.asyncAwaitSignature(
Expand Down Expand Up @@ -219,4 +224,28 @@ 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 nil
}
}
}

0 comments on commit 24ae23d

Please sign in to comment.