Go to the documentation of this file.
35 #include <google/protobuf/compiler/java/java_service.h>
37 #include <google/protobuf/compiler/java/java_context.h>
38 #include <google/protobuf/compiler/java/java_doc_comment.h>
39 #include <google/protobuf/compiler/java/java_helpers.h>
40 #include <google/protobuf/compiler/java/java_name_resolver.h>
41 #include <google/protobuf/io/printer.h>
42 #include <google/protobuf/stubs/strutil.h>
59 name_resolver_(
context->GetNameResolver()) {}
69 "public $static$ abstract class $classname$\n"
70 " implements com.google.protobuf.Service {\n",
71 "static", is_own_file ?
"" :
"static",
"classname",
descriptor_->
name());
74 printer->Print(
"protected $classname$() {}\n\n",
"classname",
86 "public static final\n"
87 " com.google.protobuf.Descriptors.ServiceDescriptor\n"
88 " getDescriptor() {\n"
89 " return $file$.getDescriptor().getServices().get($index$);\n"
105 "// @@protoc_insertion_point(class_scope:$full_name$)\n",
109 printer->Print(
"}\n\n");
115 "public final com.google.protobuf.Descriptors.ServiceDescriptor\n"
116 " getDescriptorForType() {\n"
117 " return getDescriptor();\n"
122 printer->Print(
"public interface Interface {\n");
126 printer->Print(
"}\n\n");
132 "public static com.google.protobuf.Service newReflectiveService(\n"
133 " final Interface impl) {\n"
134 " return new $classname$() {\n",
141 printer->Print(
"@java.lang.Override\n");
145 " impl.$method$(controller, request, done);\n"
151 printer->Print(
"};\n");
153 printer->Print(
"}\n\n");
159 "public static com.google.protobuf.BlockingService\n"
160 " newReflectiveBlockingService(final BlockingInterface impl) {\n"
161 " return new com.google.protobuf.BlockingService() {\n");
172 printer->Print(
"};\n");
174 printer->Print(
"}\n\n");
182 printer->Print(
";\n\n");
194 "public final void callMethod(\n"
195 " com.google.protobuf.Descriptors.MethodDescriptor method,\n"
196 " com.google.protobuf.RpcController controller,\n"
197 " com.google.protobuf.Message request,\n"
198 " com.google.protobuf.RpcCallback<\n"
199 " com.google.protobuf.Message> done) {\n"
200 " if (method.getService() != getDescriptor()) {\n"
201 " throw new java.lang.IllegalArgumentException(\n"
202 " \"Service.callMethod() given method descriptor for wrong \" +\n"
203 " \"service type.\");\n"
205 " switch(method.getIndex()) {\n");
211 std::map<std::string, std::string> vars;
212 vars[
"index"] =
StrCat(i);
219 " this.$method$(controller, ($input$)request,\n"
220 " com.google.protobuf.RpcUtil.<$output$>specializeCallback(\n"
227 " throw new java.lang.AssertionError(\"Can't get here.\");\n");
242 "public final com.google.protobuf.Message callBlockingMethod(\n"
243 " com.google.protobuf.Descriptors.MethodDescriptor method,\n"
244 " com.google.protobuf.RpcController controller,\n"
245 " com.google.protobuf.Message request)\n"
246 " throws com.google.protobuf.ServiceException {\n"
247 " if (method.getService() != getDescriptor()) {\n"
248 " throw new java.lang.IllegalArgumentException(\n"
249 " \"Service.callBlockingMethod() given method descriptor for \" +\n"
250 " \"wrong service type.\");\n"
252 " switch(method.getIndex()) {\n");
258 std::map<std::string, std::string> vars;
259 vars[
"index"] =
StrCat(i);
265 " return impl.$method$(controller, ($input$)request);\n");
270 " throw new java.lang.AssertionError(\"Can't get here.\");\n");
288 "public final com.google.protobuf.Message\n"
289 " get$request_or_response$Prototype(\n"
290 " com.google.protobuf.Descriptors.MethodDescriptor method) {\n"
291 " if (method.getService() != getDescriptor()) {\n"
292 " throw new java.lang.IllegalArgumentException(\n"
293 " \"Service.get$request_or_response$Prototype() given method \" +\n"
294 " \"descriptor for wrong service type.\");\n"
296 " switch(method.getIndex()) {\n",
297 "request_or_response", (
which ==
REQUEST) ?
"Request" :
"Response");
303 std::map<std::string, std::string> vars;
304 vars[
"index"] =
StrCat(i);
311 " return $type$.getDefaultInstance();\n");
316 " throw new java.lang.AssertionError(\"Can't get here.\");\n");
329 "public static Stub newStub(\n"
330 " com.google.protobuf.RpcChannel channel) {\n"
331 " return new Stub(channel);\n"
334 "public static final class Stub extends $classname$ implements Interface "
341 "private Stub(com.google.protobuf.RpcChannel channel) {\n"
342 " this.channel = channel;\n"
345 "private final com.google.protobuf.RpcChannel channel;\n"
347 "public com.google.protobuf.RpcChannel getChannel() {\n"
353 printer->Print(
"\n");
355 printer->Print(
" {\n");
358 std::map<std::string, std::string> vars;
359 vars[
"index"] =
StrCat(i);
362 "channel.callMethod(\n"
363 " getDescriptor().getMethods().get($index$),\n"
366 " $output$.getDefaultInstance(),\n"
367 " com.google.protobuf.RpcUtil.generalizeCallback(\n"
370 " $output$.getDefaultInstance()));\n");
373 printer->Print(
"}\n");
384 "public static BlockingInterface newBlockingStub(\n"
385 " com.google.protobuf.BlockingRpcChannel channel) {\n"
386 " return new BlockingStub(channel);\n"
390 printer->Print(
"public interface BlockingInterface {");
396 printer->Print(
";\n");
405 "private static final class BlockingStub implements BlockingInterface "
410 "private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {\n"
411 " this.channel = channel;\n"
414 "private final com.google.protobuf.BlockingRpcChannel channel;\n");
419 printer->Print(
" {\n");
422 std::map<std::string, std::string> vars;
423 vars[
"index"] =
StrCat(i);
426 "return ($output$) channel.callBlockingMethod(\n"
427 " getDescriptor().getMethods().get($index$),\n"
430 " $output$.getDefaultInstance());\n");
439 printer->Print(
"}\n");
444 IsAbstract is_abstract) {
445 std::map<std::string, std::string> vars;
449 vars[
"abstract"] = (is_abstract ==
IS_ABSTRACT) ?
"abstract" :
"";
451 "public $abstract$ void $name$(\n"
452 " com.google.protobuf.RpcController controller,\n"
453 " $input$ request,\n"
454 " com.google.protobuf.RpcCallback<$output$> done)");
459 std::map<std::string, std::string> vars;
465 "public $output$ $method$(\n"
466 " com.google.protobuf.RpcController controller,\n"
467 " $input$ request)\n"
468 " throws com.google.protobuf.ServiceException");
std::string UnderscoresToCamelCase(const std::string &input, bool cap_next_letter)
void GenerateMethodSignature(io::Printer *printer, const MethodDescriptor *method, IsAbstract is_abstract)
void MaybePrintGeneratedAnnotation(Context *context, io::Printer *printer, Descriptor *descriptor, bool immutable, const std::string &suffix="")
std::string GetOutput(const MethodDescriptor *method)
const std::string & full_name() const
GRPC_CUSTOM_PRINTER Printer
ServiceGenerator(const ServiceDescriptor *descriptor)
std::string GetImmutableClassName(const DescriptorType *descriptor)
const std::string & name() const
virtual ~ServiceGenerator()
void GenerateNewReflectiveBlockingServiceMethod(io::Printer *printer)
string StrCat(const AlphaNum &a, const AlphaNum &b)
const ServiceDescriptor * descriptor_
GRPC_CUSTOM_METHODDESCRIPTOR MethodDescriptor
void GenerateGetPrototype(RequestOrResponse which, io::Printer *printer)
void GenerateCallBlockingMethod(io::Printer *printer)
void GenerateInterface(io::Printer *printer)
void GenerateNewReflectiveServiceMethod(io::Printer *printer)
void GenerateBlockingMethodSignature(io::Printer *printer, const MethodDescriptor *method)
void GenerateBlockingStub(io::Printer *printer)
const FileDescriptor * file() const
void WriteServiceDocComment(io::Printer *printer, const ServiceDescriptor *service)
virtual void Generate(io::Printer *printer)
void GenerateCallMethod(io::Printer *printer)
ImmutableServiceGenerator(const ServiceDescriptor *descriptor, Context *context)
void WriteMethodDocComment(io::Printer *printer, const MethodDescriptor *method)
grpc::ClientContext context
void GenerateGetDescriptorForType(io::Printer *printer)
const MethodDescriptor * method(int index) const
void GenerateAbstractMethods(io::Printer *printer)
ClassNameResolver * name_resolver_
bool IsOwnFile(const Descriptor *descriptor, bool immutable)
static const char descriptor[1336]
GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor
virtual ~ImmutableServiceGenerator()
const Descriptor::ReservedRange const EnumValueDescriptor method
void GenerateStub(io::Printer *printer)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:10