| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /*
- * Copyright 2018, gRPC Authors All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import Foundation
- import SwiftProtobuf
- import SwiftProtobufPluginLibrary
- internal func nameForPackageService(_ file: FileDescriptor,
- _ service: ServiceDescriptor) -> String {
- if !file.package.isEmpty {
- return SwiftProtobufNamer().typePrefix(forFile: file) + service.name
- } else {
- return service.name
- }
- }
- internal func nameForPackageServiceMethod(_ file: FileDescriptor,
- _ service: ServiceDescriptor,
- _ method: MethodDescriptor) -> String {
- return nameForPackageService(file, service) + method.name
- }
- extension Generator {
- internal var access: String {
- return options.visibility.sourceSnippet
- }
- internal var serviceClassName: String {
- return nameForPackageService(file, service) + "Service"
- }
- internal var providerName: String {
- return nameForPackageService(file, service) + "Provider"
- }
- internal var clientClassName: String {
- return nameForPackageService(file, service) + "Client"
- }
- internal var testClientClassName: String {
- return nameForPackageService(self.file, self.service) + "TestClient"
- }
- internal var clientProtocolName: String {
- return nameForPackageService(file, service) + "ClientProtocol"
- }
- internal var clientInterceptorProtocolName: String {
- return nameForPackageService(file, service) + "ClientInterceptorFactoryProtocol"
- }
- internal var callName: String {
- return nameForPackageServiceMethod(file, service, method) + "Call"
- }
- internal var methodFunctionName: String {
- let name = method.name
- return name.prefix(1).lowercased() + name.dropFirst()
- }
- internal var methodInputName: String {
- return protobufNamer.fullName(message: method.inputType)
- }
- internal var methodOutputName: String {
- return protobufNamer.fullName(message: method.outputType)
- }
- internal var methodInterceptorFactoryName: String {
- return "make\(self.method.name)Interceptors"
- }
- internal var servicePath: String {
- if !file.package.isEmpty {
- return file.package + "." + service.name
- } else {
- return service.name
- }
- }
- internal var methodPath: String {
- return "\"/" + self.servicePath + "/" + method.name + "\""
- }
- }
|