Generator-Names.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. if options.generateNIOImplementation {
  38. return nameForPackageService(file, service) + "Service_NIO"
  39. } else {
  40. return nameForPackageService(file, service) + "Service"
  41. }
  42. }
  43. internal var providerName: String {
  44. if options.generateNIOImplementation {
  45. return nameForPackageService(file, service) + "Provider_NIO"
  46. } else {
  47. return nameForPackageService(file, service) + "Provider"
  48. }
  49. }
  50. internal var callName: String {
  51. return nameForPackageServiceMethod(file, service, method) + "Call"
  52. }
  53. internal var methodFunctionName: String {
  54. let name = method.name
  55. return name.prefix(1).lowercased() + name.dropFirst()
  56. }
  57. internal var methodSessionName: String {
  58. return nameForPackageServiceMethod(file, service, method) + "Session"
  59. }
  60. internal var methodInputName: String {
  61. return protobufNamer.fullName(message: method.inputType)
  62. }
  63. internal var methodOutputName: String {
  64. return protobufNamer.fullName(message: method.outputType)
  65. }
  66. internal var servicePath: String {
  67. if !file.package.isEmpty {
  68. return file.package + "." + service.name
  69. } else {
  70. return service.name
  71. }
  72. }
  73. internal var methodPath: String {
  74. return "\"/" + servicePath + "/" + method.name + "\""
  75. }
  76. }