SpecializedTranslator.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2023, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /// Represents one responsibility of the ``Translator``: either the type aliases translation,
  17. /// the server code translation or the client code translation.
  18. protocol SpecializedTranslator {
  19. /// The ``SourceGenerator.Configuration.AccessLevel`` object used to represent the visibility level used in the generated code.
  20. var accessLevel: SourceGenerator.Configuration.AccessLevel { get }
  21. /// Generates an array of ``CodeBlock`` elements that will be part of the ``StructuredSwiftRepresentation`` object
  22. /// created by the ``Translator``.
  23. ///
  24. /// - Parameters:
  25. /// - codeGenerationRequest: The ``CodeGenerationRequest`` object used to represent a Source IDL description of RPCs.
  26. /// - Returns: An array of ``CodeBlock`` elements.
  27. ///
  28. /// - SeeAlso: ``CodeGenerationRequest``, ``Translator``, ``CodeBlock``.
  29. func translate(from codeGenerationRequest: CodeGenerationRequest) throws -> [CodeBlock]
  30. }
  31. extension SpecializedTranslator {
  32. /// The access modifier that corresponds with the access level from ``SourceGenerator.Configuration``.
  33. internal var accessModifier: AccessModifier {
  34. get {
  35. switch accessLevel.level {
  36. case .internal:
  37. return AccessModifier.internal
  38. case .package:
  39. return AccessModifier.package
  40. case .public:
  41. return AccessModifier.public
  42. }
  43. }
  44. }
  45. internal var availabilityGuard: AvailabilityDescription {
  46. AvailabilityDescription(osVersions: [
  47. .init(os: .macOS, version: "13.0"),
  48. .init(os: .iOS, version: "16.0"),
  49. .init(os: .watchOS, version: "9.0"),
  50. .init(os: .tvOS, version: "16.0"),
  51. ])
  52. }
  53. }