2
0

Generator-Names.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2018, 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. import Foundation
  17. import SwiftProtobuf
  18. import SwiftProtobufPluginLibrary
  19. internal func nameForPackageService(_ file: FileDescriptor,
  20. _ service: ServiceDescriptor) -> String {
  21. if !file.package.isEmpty {
  22. return SwiftProtobufNamer().typePrefix(forFile: file) + service.name
  23. } else {
  24. return service.name
  25. }
  26. }
  27. internal func nameForPackageServiceMethod(_ file: FileDescriptor,
  28. _ service: ServiceDescriptor,
  29. _ method: MethodDescriptor) -> String {
  30. return nameForPackageService(file, service) + method.name
  31. }
  32. extension Generator {
  33. internal var access: String {
  34. return options.visibility.sourceSnippet
  35. }
  36. internal var serviceClassName: String {
  37. return nameForPackageService(file, service) + "Service"
  38. }
  39. internal var providerName: String {
  40. return nameForPackageService(file, service) + "Provider"
  41. }
  42. internal var clientClassName: String {
  43. return nameForPackageService(file, service) + "Client"
  44. }
  45. internal var testClientClassName: String {
  46. return nameForPackageService(self.file, self.service) + "TestClient"
  47. }
  48. internal var clientProtocolName: String {
  49. return nameForPackageService(file, service) + "ClientProtocol"
  50. }
  51. internal var clientInterceptorProtocolName: String {
  52. return nameForPackageService(file, service) + "ClientInterceptorFactoryProtocol"
  53. }
  54. internal var serverInterceptorProtocolName: String {
  55. return nameForPackageService(file, service) + "ServerInterceptorFactoryProtocol"
  56. }
  57. internal var callName: String {
  58. return nameForPackageServiceMethod(file, service, method) + "Call"
  59. }
  60. internal var methodFunctionName: String {
  61. let name = method.name
  62. return name.prefix(1).lowercased() + name.dropFirst()
  63. }
  64. internal var methodInputName: String {
  65. return protobufNamer.fullName(message: method.inputType)
  66. }
  67. internal var methodOutputName: String {
  68. return protobufNamer.fullName(message: method.outputType)
  69. }
  70. internal var methodInterceptorFactoryName: String {
  71. return "make\(self.method.name)Interceptors"
  72. }
  73. internal var servicePath: String {
  74. if !file.package.isEmpty {
  75. return file.package + "." + service.name
  76. } else {
  77. return service.name
  78. }
  79. }
  80. internal var methodPath: String {
  81. return "\"/" + self.servicePath + "/" + method.name + "\""
  82. }
  83. }