From 24ae23d0d1bb183175e53806a5b1f1573e28400b Mon Sep 17 00:00:00 2001 From: Eddie Seay Date: Thu, 24 Oct 2024 13:58:09 -0400 Subject: [PATCH] 305: Apply deprecation annotations for generated mocks Signed-off-by: Eddie Seay --- .../ConnectMockGenerator.swift | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift b/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift index d9246784..787e2ccb 100644 --- a/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift +++ b/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift @@ -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") } @@ -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( @@ -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 + } + } }