diff --git a/Sources/StringGenerator/Extensions/AttributeSyntax+Availability.swift b/Sources/StringGenerator/Extensions/AttributeSyntax+Availability.swift index e685030..69e7dfb 100644 --- a/Sources/StringGenerator/Extensions/AttributeSyntax+Availability.swift +++ b/Sources/StringGenerator/Extensions/AttributeSyntax+Availability.swift @@ -74,6 +74,24 @@ extension AvailabilityArgumentListSyntax { ] } + static var wwdc2020: AvailabilityArgumentListSyntax { + [ + AvailabilityArgumentSyntax(argument: .platformVersionRestriction("macOS", versionMajor: 11)) + .with(\.trailingComma, .commaToken()), + + AvailabilityArgumentSyntax(argument: .platformVersionRestriction("iOS", versionMajor: 14)) + .with(\.trailingComma, .commaToken()), + + AvailabilityArgumentSyntax(argument: .platformVersionRestriction("tvOS", versionMajor: 14)) + .with(\.trailingComma, .commaToken()), + + AvailabilityArgumentSyntax(argument: .platformVersionRestriction("watchOS", versionMajor: 7)) + .with(\.trailingComma, .commaToken()), + + AvailabilityArgumentSyntax(argument: .token(.binaryOperator("*"))) + ] + } + static var wwdc2019: AvailabilityArgumentListSyntax { [ AvailabilityArgumentSyntax(argument: .platformVersionRestriction("macOS", versionMajor: 10, versionMinor: 5)) diff --git a/Sources/StringGenerator/Snippets/SourceFileSnippet.swift b/Sources/StringGenerator/Snippets/SourceFileSnippet.swift index fe61851..6b4f472 100644 --- a/Sources/StringGenerator/Snippets/SourceFileSnippet.swift +++ b/Sources/StringGenerator/Snippets/SourceFileSnippet.swift @@ -76,7 +76,8 @@ struct SourceFileSnippet: Snippet { StringsTableConversionStaticMethodSnippet( stringsTable: sourceFile.stringExtension.stringsTableStruct, - returnType: .type(.LocalizedStringKey) + returnType: .type(.LocalizedStringKey), + availability: .wwdc2020 ) LocalizedStringKeyOverrideKeySnippet() diff --git a/Sources/StringGenerator/Snippets/StringsTableConversionStaticMethodSnippet.swift b/Sources/StringGenerator/Snippets/StringsTableConversionStaticMethodSnippet.swift index bfe876d..ebe113a 100644 --- a/Sources/StringGenerator/Snippets/StringsTableConversionStaticMethodSnippet.swift +++ b/Sources/StringGenerator/Snippets/StringsTableConversionStaticMethodSnippet.swift @@ -4,12 +4,14 @@ import SwiftSyntaxBuilder struct StringsTableConversionStaticMethodSnippet { let stringsTable: SourceFile.StringExtension.StringsTableStruct let returnType: TokenSyntax + var availability: AvailabilityArgumentListSyntax? } extension StringsTableConversionStaticMethodSnippet: Snippet { var syntax: some DeclSyntaxProtocol { FunctionDeclSyntax( leadingTrivia: leadingTrivia, + attributes: attributes.map({ $0.with(\.trailingTrivia, .newline) }), modifiers: modifiers, name: name, signature: signature, @@ -23,6 +25,13 @@ extension StringsTableConversionStaticMethodSnippet: Snippet { """) } + @AttributeListBuilder + var attributes: AttributeListSyntax { + if let availability { + AttributeSyntax(availability: availability) + } + } + @DeclModifierListBuilder var modifiers: DeclModifierListSyntax { DeclModifierSyntax(name: stringsTable.accessLevel.token) diff --git a/Sources/StringGenerator/Snippets/SwiftUI/LocalizedStringKeyInitializerSnippet.swift b/Sources/StringGenerator/Snippets/SwiftUI/LocalizedStringKeyInitializerSnippet.swift index 39f925c..eebab88 100644 --- a/Sources/StringGenerator/Snippets/SwiftUI/LocalizedStringKeyInitializerSnippet.swift +++ b/Sources/StringGenerator/Snippets/SwiftUI/LocalizedStringKeyInitializerSnippet.swift @@ -13,6 +13,7 @@ extension LocalizedStringKeyInitializerSnippet: Snippet { var syntax: some DeclSyntaxProtocol { InitializerDeclSyntax( leadingTrivia: leadingTrivia, + attributes: attributes.map({ $0.with(\.trailingTrivia, .newline) }), modifiers: modifiers, signature: signature, body: body @@ -25,6 +26,11 @@ extension LocalizedStringKeyInitializerSnippet: Snippet { """) } + @AttributeListBuilder + var attributes: AttributeListSyntax { + AttributeSyntax(availability: .wwdc2020) + } + @DeclModifierListBuilder var modifiers: DeclModifierListSyntax { DeclModifierSyntax(name: stringsTable.accessLevel.token) diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.FormatSpecifiers.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.FormatSpecifiers.swift index bc6beb7..b4aa2bf 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.FormatSpecifiers.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.FormatSpecifiers.swift @@ -677,6 +677,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘FormatSpecifiers‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(formatSpecifiers: String.FormatSpecifiers) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -691,6 +692,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘FormatSpecifiers‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func formatSpecifiers(_ formatSpecifiers: String.FormatSpecifiers) -> LocalizedStringKey { LocalizedStringKey(formatSpecifiers: formatSpecifiers) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Localizable.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Localizable.swift index e49b5a8..91251d6 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Localizable.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Localizable.swift @@ -364,6 +364,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Localizable‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(localizable: String.Localizable) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -378,6 +379,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Localizable‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func localizable(_ localizable: String.Localizable) -> LocalizedStringKey { LocalizedStringKey(localizable: localizable) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Multiline.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Multiline.swift index e3d2bc3..d3e4287 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Multiline.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Multiline.swift @@ -285,6 +285,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Multiline‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(multiline: String.Multiline) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -299,6 +300,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Multiline‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func multiline(_ multiline: String.Multiline) -> LocalizedStringKey { LocalizedStringKey(multiline: multiline) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Positional.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Positional.swift index 67a8dc6..8288ad0 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Positional.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Positional.swift @@ -346,6 +346,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Positional‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(positional: String.Positional) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -360,6 +361,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Positional‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func positional(_ positional: String.Positional) -> LocalizedStringKey { LocalizedStringKey(positional: positional) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Simple.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Simple.swift index 43a61dc..42d1b46 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Simple.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Simple.swift @@ -275,6 +275,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Simple‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(simple: String.Simple) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -289,6 +290,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Simple‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func simple(_ simple: String.Simple) -> LocalizedStringKey { LocalizedStringKey(simple: simple) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Substitution.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Substitution.swift index 0414884..918840d 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Substitution.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Substitution.swift @@ -279,6 +279,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Substitution‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(substitution: String.Substitution) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -293,6 +294,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Substitution‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func substitution(_ substitution: String.Substitution) -> LocalizedStringKey { LocalizedStringKey(substitution: substitution) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Variations.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Variations.swift index 62a7e17..b60b44d 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Variations.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerate.Variations.swift @@ -305,6 +305,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Variations‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal init(variations: String.Variations) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -319,6 +320,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Variations‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) internal static func variations(_ variations: String.Variations) -> LocalizedStringKey { LocalizedStringKey(variations: variations) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPackageAccessLevel.Localizable.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPackageAccessLevel.Localizable.swift index 26d70d1..a197dde 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPackageAccessLevel.Localizable.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPackageAccessLevel.Localizable.swift @@ -364,6 +364,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Localizable‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) package init(localizable: String.Localizable) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -378,6 +379,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Localizable‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) package static func localizable(_ localizable: String.Localizable) -> LocalizedStringKey { LocalizedStringKey(localizable: localizable) } diff --git a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPublicAccessLevel.Localizable.swift b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPublicAccessLevel.Localizable.swift index 0c4d9af..29a1705 100644 --- a/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPublicAccessLevel.Localizable.swift +++ b/Tests/XCStringsToolTests/__Snapshots__/GenerateTests/testGenerateWithPublicAccessLevel.Localizable.swift @@ -364,6 +364,7 @@ extension Text { @available(macOS 10.5, iOS 13, tvOS 13, watchOS 6, *) extension LocalizedStringKey { /// Creates a localized string key that represents a localized value in the ‘Localizable‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) public init(localizable: String.Localizable) { var stringInterpolation = LocalizedStringKey.StringInterpolation(literalCapacity: 0, interpolationCount: 1) @@ -378,6 +379,7 @@ extension LocalizedStringKey { } /// Creates a `LocalizedStringKey` that represents a localized value in the ‘Localizable‘ strings table. + @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) public static func localizable(_ localizable: String.Localizable) -> LocalizedStringKey { LocalizedStringKey(localizable: localizable) }