1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 // Author: kenton@google.com (Kenton Varda) 9 // Based on original Protocol Buffers design by 10 // Sanjay Ghemawat, Jeff Dean, and others. 11 12 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ 13 #define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ 14 15 #include "google/protobuf/compiler/java/generator_factory.h" 16 #include "google/protobuf/descriptor.h" 17 18 namespace google { 19 namespace protobuf { 20 namespace compiler { 21 namespace java { 22 class Context; // context.h 23 class ClassNameResolver; // name_resolver.h 24 } // namespace java 25 } // namespace compiler 26 namespace io { 27 class Printer; // printer.h 28 } 29 } // namespace protobuf 30 } // namespace google 31 32 namespace google { 33 namespace protobuf { 34 namespace compiler { 35 namespace java { 36 37 class ImmutableServiceGenerator : public ServiceGenerator { 38 public: 39 ImmutableServiceGenerator(const ServiceDescriptor* descriptor, 40 Context* context); 41 ImmutableServiceGenerator(const ImmutableServiceGenerator&) = delete; 42 ImmutableServiceGenerator& operator=(const ImmutableServiceGenerator&) = 43 delete; 44 ~ImmutableServiceGenerator() override; 45 46 void Generate(io::Printer* printer) override; 47 48 private: 49 // Generate the getDescriptorForType() method. 50 void GenerateGetDescriptorForType(io::Printer* printer); 51 52 // Generate a Java interface for the service. 53 void GenerateInterface(io::Printer* printer); 54 55 // Generate newReflectiveService() method. 56 void GenerateNewReflectiveServiceMethod(io::Printer* printer); 57 58 // Generate newReflectiveBlockingService() method. 59 void GenerateNewReflectiveBlockingServiceMethod(io::Printer* printer); 60 61 // Generate abstract method declarations for all methods. 62 void GenerateAbstractMethods(io::Printer* printer); 63 64 // Generate the implementation of Service.callMethod(). 65 void GenerateCallMethod(io::Printer* printer); 66 67 // Generate the implementation of BlockingService.callBlockingMethod(). 68 void GenerateCallBlockingMethod(io::Printer* printer); 69 70 // Generate the implementations of Service.get{Request,Response}Prototype(). 71 void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); 72 73 // Generate a stub implementation of the service. 74 void GenerateStub(io::Printer* printer); 75 76 // Generate a method signature, possibly abstract, without body or trailing 77 // semicolon. 78 void GenerateMethodSignature(io::Printer* printer, 79 const MethodDescriptor* method, 80 IsAbstract is_abstract); 81 82 // Generate a blocking stub interface and implementation of the service. 83 void GenerateBlockingStub(io::Printer* printer); 84 85 // Generate the method signature for one method of a blocking stub. 86 void GenerateBlockingMethodSignature(io::Printer* printer, 87 const MethodDescriptor* method); 88 89 // Return the output type of the method. 90 std::string GetOutput(const MethodDescriptor* method); 91 92 Context* context_; 93 ClassNameResolver* name_resolver_; 94 }; 95 96 } // namespace java 97 } // namespace compiler 98 } // namespace protobuf 99 } // namespace google 100 101 #endif // NET_PROTO2_COMPILER_JAVA_SERVICE_H__ 102