2
0

Generator-Names.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // Transform .some.package_name.FooBarRequest -> Some_PackageName_FooBarRequest
  20. internal func protoMessageName(_ descriptor: SwiftProtobufPluginLibrary.Descriptor) -> String {
  21. return SwiftProtobufNamer().fullName(message: descriptor)
  22. }
  23. internal func nameForPackageService(_ file: FileDescriptor,
  24. _ service: ServiceDescriptor) -> String {
  25. if !file.package.isEmpty {
  26. return SwiftProtobufNamer().typePrefix(forFile:file) + service.name
  27. } else {
  28. return service.name
  29. }
  30. }
  31. internal func nameForPackageServiceMethod(_ file: FileDescriptor,
  32. _ service: ServiceDescriptor,
  33. _ method: MethodDescriptor) -> String {
  34. return nameForPackageService(file, service) + method.name
  35. }
  36. extension Generator {
  37. internal var access : String {
  38. return options.visibility.sourceSnippet
  39. }
  40. internal var serviceClassName: String {
  41. if options.generateNIOImplementation {
  42. return nameForPackageService(file, service) + "Service_NIO"
  43. } else {
  44. return nameForPackageService(file, service) + "Service"
  45. }
  46. }
  47. internal var providerName: String {
  48. if options.generateNIOImplementation {
  49. return nameForPackageService(file, service) + "Provider_NIO"
  50. } else {
  51. return nameForPackageService(file, service) + "Provider"
  52. }
  53. }
  54. internal var callName: String {
  55. return nameForPackageServiceMethod(file, service, method) + "Call"
  56. }
  57. internal var methodFunctionName: String {
  58. let name = method.name
  59. return name.prefix(1).lowercased() + name.dropFirst()
  60. }
  61. internal var methodSessionName: String {
  62. return nameForPackageServiceMethod(file, service, method) + "Session"
  63. }
  64. internal var methodInputName: String {
  65. return protoMessageName(method.inputType)
  66. }
  67. internal var methodOutputName: String {
  68. return protoMessageName(method.outputType)
  69. }
  70. internal var servicePath: String {
  71. if !file.package.isEmpty {
  72. return file.package + "." + service.name
  73. } else {
  74. return service.name
  75. }
  76. }
  77. internal var methodPath: String {
  78. return "\"/" + servicePath + "/" + method.name + "\""
  79. }
  80. }