Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 // =================================================================== 54 // ===================================================================
55 ImmutableServiceGenerator::ImmutableServiceGenerator( 55 ImmutableServiceGenerator::ImmutableServiceGenerator(
56 const ServiceDescriptor* descriptor, Context* context) 56 const ServiceDescriptor* descriptor, Context* context)
57 : ServiceGenerator(descriptor), context_(context), 57 : ServiceGenerator(descriptor), context_(context),
58 name_resolver_(context->GetNameResolver()) {} 58 name_resolver_(context->GetNameResolver()) {}
59 59
60 ImmutableServiceGenerator::~ImmutableServiceGenerator() {} 60 ImmutableServiceGenerator::~ImmutableServiceGenerator() {}
61 61
62 void ImmutableServiceGenerator::Generate(io::Printer* printer) { 62 void ImmutableServiceGenerator::Generate(io::Printer* printer) {
63 bool is_own_file = 63 bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
64 MultipleJavaFiles(descriptor_->file(), /* immutable = */ true);
65 WriteServiceDocComment(printer, descriptor_); 64 WriteServiceDocComment(printer, descriptor_);
65 MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
66 /* immutable = */ true);
66 printer->Print( 67 printer->Print(
67 "public $static$ abstract class $classname$\n" 68 "public $static$ abstract class $classname$\n"
68 " implements com.google.protobuf.Service {\n", 69 " implements com.google.protobuf.Service {\n",
69 "static", is_own_file ? "" : "static", 70 "static", is_own_file ? "" : "static",
70 "classname", descriptor_->name()); 71 "classname", descriptor_->name());
71 printer->Indent(); 72 printer->Indent();
72 73
73 printer->Print( 74 printer->Print(
74 "protected $classname$() {}\n\n", 75 "protected $classname$() {}\n\n",
75 "classname", descriptor_->name()); 76 "classname", descriptor_->name());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { 178 void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) {
178 for (int i = 0; i < descriptor_->method_count(); i++) { 179 for (int i = 0; i < descriptor_->method_count(); i++) {
179 const MethodDescriptor* method = descriptor_->method(i); 180 const MethodDescriptor* method = descriptor_->method(i);
180 WriteMethodDocComment(printer, method); 181 WriteMethodDocComment(printer, method);
181 GenerateMethodSignature(printer, method, IS_ABSTRACT); 182 GenerateMethodSignature(printer, method, IS_ABSTRACT);
182 printer->Print(";\n\n"); 183 printer->Print(";\n\n");
183 } 184 }
184 } 185 }
185 186
187 string ImmutableServiceGenerator::GetOutput(const MethodDescriptor* method) {
188 return name_resolver_->GetImmutableClassName(method->output_type());
189 }
190
186 void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { 191 void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
187 printer->Print( 192 printer->Print(
188 "\n" 193 "\n"
189 "public final void callMethod(\n" 194 "public final void callMethod(\n"
190 " com.google.protobuf.Descriptors.MethodDescriptor method,\n" 195 " com.google.protobuf.Descriptors.MethodDescriptor method,\n"
191 " com.google.protobuf.RpcController controller,\n" 196 " com.google.protobuf.RpcController controller,\n"
192 " com.google.protobuf.Message request,\n" 197 " com.google.protobuf.Message request,\n"
193 " com.google.protobuf.RpcCallback<\n" 198 " com.google.protobuf.RpcCallback<\n"
194 " com.google.protobuf.Message> done) {\n" 199 " com.google.protobuf.Message> done) {\n"
195 " if (method.getService() != getDescriptor()) {\n" 200 " if (method.getService() != getDescriptor()) {\n"
196 " throw new java.lang.IllegalArgumentException(\n" 201 " throw new java.lang.IllegalArgumentException(\n"
197 " \"Service.callMethod() given method descriptor for wrong \" +\n" 202 " \"Service.callMethod() given method descriptor for wrong \" +\n"
198 " \"service type.\");\n" 203 " \"service type.\");\n"
199 " }\n" 204 " }\n"
200 " switch(method.getIndex()) {\n"); 205 " switch(method.getIndex()) {\n");
201 printer->Indent(); 206 printer->Indent();
202 printer->Indent(); 207 printer->Indent();
203 208
204 for (int i = 0; i < descriptor_->method_count(); i++) { 209 for (int i = 0; i < descriptor_->method_count(); i++) {
205 const MethodDescriptor* method = descriptor_->method(i); 210 const MethodDescriptor* method = descriptor_->method(i);
206 map<string, string> vars; 211 std::map<string, string> vars;
207 vars["index"] = SimpleItoa(i); 212 vars["index"] = SimpleItoa(i);
208 vars["method"] = UnderscoresToCamelCase(method); 213 vars["method"] = UnderscoresToCamelCase(method);
209 vars["input"] = name_resolver_->GetImmutableClassName( 214 vars["input"] = name_resolver_->GetImmutableClassName(
210 method->input_type()); 215 method->input_type());
211 vars["output"] = name_resolver_->GetImmutableClassName( 216 vars["output"] = GetOutput(method);
212 method->output_type());
213 printer->Print(vars, 217 printer->Print(vars,
214 "case $index$:\n" 218 "case $index$:\n"
215 " this.$method$(controller, ($input$)request,\n" 219 " this.$method$(controller, ($input$)request,\n"
216 " com.google.protobuf.RpcUtil.<$output$>specializeCallback(\n" 220 " com.google.protobuf.RpcUtil.<$output$>specializeCallback(\n"
217 " done));\n" 221 " done));\n"
218 " return;\n"); 222 " return;\n");
219 } 223 }
220 224
221 printer->Print( 225 printer->Print(
222 "default:\n" 226 "default:\n"
(...skipping 21 matching lines...) Expand all
244 " throw new java.lang.IllegalArgumentException(\n" 248 " throw new java.lang.IllegalArgumentException(\n"
245 " \"Service.callBlockingMethod() given method descriptor for \" +\n" 249 " \"Service.callBlockingMethod() given method descriptor for \" +\n"
246 " \"wrong service type.\");\n" 250 " \"wrong service type.\");\n"
247 " }\n" 251 " }\n"
248 " switch(method.getIndex()) {\n"); 252 " switch(method.getIndex()) {\n");
249 printer->Indent(); 253 printer->Indent();
250 printer->Indent(); 254 printer->Indent();
251 255
252 for (int i = 0; i < descriptor_->method_count(); i++) { 256 for (int i = 0; i < descriptor_->method_count(); i++) {
253 const MethodDescriptor* method = descriptor_->method(i); 257 const MethodDescriptor* method = descriptor_->method(i);
254 map<string, string> vars; 258 std::map<string, string> vars;
255 vars["index"] = SimpleItoa(i); 259 vars["index"] = SimpleItoa(i);
256 vars["method"] = UnderscoresToCamelCase(method); 260 vars["method"] = UnderscoresToCamelCase(method);
257 vars["input"] = name_resolver_->GetImmutableClassName( 261 vars["input"] = name_resolver_->GetImmutableClassName(
258 method->input_type()); 262 method->input_type());
259 vars["output"] = name_resolver_->GetImmutableClassName( 263 vars["output"] = GetOutput(method);
260 method->output_type());
261 printer->Print(vars, 264 printer->Print(vars,
262 "case $index$:\n" 265 "case $index$:\n"
263 " return impl.$method$(controller, ($input$)request);\n"); 266 " return impl.$method$(controller, ($input$)request);\n");
264 } 267 }
265 268
266 printer->Print( 269 printer->Print(
267 "default:\n" 270 "default:\n"
268 " throw new java.lang.AssertionError(\"Can't get here.\");\n"); 271 " throw new java.lang.AssertionError(\"Can't get here.\");\n");
269 272
270 printer->Outdent(); 273 printer->Outdent();
(...skipping 20 matching lines...) Expand all
291 " \"Service.get$request_or_response$Prototype() given method \" +\n" 294 " \"Service.get$request_or_response$Prototype() given method \" +\n"
292 " \"descriptor for wrong service type.\");\n" 295 " \"descriptor for wrong service type.\");\n"
293 " }\n" 296 " }\n"
294 " switch(method.getIndex()) {\n", 297 " switch(method.getIndex()) {\n",
295 "request_or_response", (which == REQUEST) ? "Request" : "Response"); 298 "request_or_response", (which == REQUEST) ? "Request" : "Response");
296 printer->Indent(); 299 printer->Indent();
297 printer->Indent(); 300 printer->Indent();
298 301
299 for (int i = 0; i < descriptor_->method_count(); i++) { 302 for (int i = 0; i < descriptor_->method_count(); i++) {
300 const MethodDescriptor* method = descriptor_->method(i); 303 const MethodDescriptor* method = descriptor_->method(i);
301 map<string, string> vars; 304 std::map<string, string> vars;
302 vars["index"] = SimpleItoa(i); 305 vars["index"] = SimpleItoa(i);
303 vars["type"] = name_resolver_->GetImmutableClassName( 306 vars["type"] = name_resolver_->GetImmutableClassName(
304 (which == REQUEST) ? method->input_type() : method->output_type()); 307 (which == REQUEST) ? method->input_type() : method->output_type());
305 printer->Print(vars, 308 printer->Print(vars,
306 "case $index$:\n" 309 "case $index$:\n"
307 " return $type$.getDefaultInstance();\n"); 310 " return $type$.getDefaultInstance();\n");
308 } 311 }
309 312
310 printer->Print( 313 printer->Print(
311 "default:\n" 314 "default:\n"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 " return channel;\n" 346 " return channel;\n"
344 "}\n"); 347 "}\n");
345 348
346 for (int i = 0; i < descriptor_->method_count(); i++) { 349 for (int i = 0; i < descriptor_->method_count(); i++) {
347 const MethodDescriptor* method = descriptor_->method(i); 350 const MethodDescriptor* method = descriptor_->method(i);
348 printer->Print("\n"); 351 printer->Print("\n");
349 GenerateMethodSignature(printer, method, IS_CONCRETE); 352 GenerateMethodSignature(printer, method, IS_CONCRETE);
350 printer->Print(" {\n"); 353 printer->Print(" {\n");
351 printer->Indent(); 354 printer->Indent();
352 355
353 map<string, string> vars; 356 std::map<string, string> vars;
354 vars["index"] = SimpleItoa(i); 357 vars["index"] = SimpleItoa(i);
355 vars["output"] = name_resolver_->GetImmutableClassName( 358 vars["output"] = GetOutput(method);
356 method->output_type());
357 printer->Print(vars, 359 printer->Print(vars,
358 "channel.callMethod(\n" 360 "channel.callMethod(\n"
359 " getDescriptor().getMethods().get($index$),\n" 361 " getDescriptor().getMethods().get($index$),\n"
360 " controller,\n" 362 " controller,\n"
361 " request,\n" 363 " request,\n"
362 " $output$.getDefaultInstance(),\n" 364 " $output$.getDefaultInstance(),\n"
363 " com.google.protobuf.RpcUtil.generalizeCallback(\n" 365 " com.google.protobuf.RpcUtil.generalizeCallback(\n"
364 " done,\n" 366 " done,\n"
365 " $output$.class,\n" 367 " $output$.class,\n"
366 " $output$.getDefaultInstance()));\n"); 368 " $output$.getDefaultInstance()));\n");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 "}\n" 410 "}\n"
409 "\n" 411 "\n"
410 "private final com.google.protobuf.BlockingRpcChannel channel;\n"); 412 "private final com.google.protobuf.BlockingRpcChannel channel;\n");
411 413
412 for (int i = 0; i < descriptor_->method_count(); i++) { 414 for (int i = 0; i < descriptor_->method_count(); i++) {
413 const MethodDescriptor* method = descriptor_->method(i); 415 const MethodDescriptor* method = descriptor_->method(i);
414 GenerateBlockingMethodSignature(printer, method); 416 GenerateBlockingMethodSignature(printer, method);
415 printer->Print(" {\n"); 417 printer->Print(" {\n");
416 printer->Indent(); 418 printer->Indent();
417 419
418 map<string, string> vars; 420 std::map<string, string> vars;
419 vars["index"] = SimpleItoa(i); 421 vars["index"] = SimpleItoa(i);
420 vars["output"] = name_resolver_->GetImmutableClassName( 422 vars["output"] = GetOutput(method);
421 method->output_type());
422 printer->Print(vars, 423 printer->Print(vars,
423 "return ($output$) channel.callBlockingMethod(\n" 424 "return ($output$) channel.callBlockingMethod(\n"
424 " getDescriptor().getMethods().get($index$),\n" 425 " getDescriptor().getMethods().get($index$),\n"
425 " controller,\n" 426 " controller,\n"
426 " request,\n" 427 " request,\n"
427 " $output$.getDefaultInstance());\n"); 428 " $output$.getDefaultInstance());\n");
428 429
429 printer->Outdent(); 430 printer->Outdent();
430 printer->Print( 431 printer->Print(
431 "}\n" 432 "}\n"
432 "\n"); 433 "\n");
433 } 434 }
434 435
435 printer->Outdent(); 436 printer->Outdent();
436 printer->Print("}\n"); 437 printer->Print("}\n");
437 } 438 }
438 439
439 void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer, 440 void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer,
440 const MethodDescriptor* method, 441 const MethodDescriptor* method,
441 IsAbstract is_abstract) { 442 IsAbstract is_abstract) {
442 map<string, string> vars; 443 std::map<string, string> vars;
443 vars["name"] = UnderscoresToCamelCase(method); 444 vars["name"] = UnderscoresToCamelCase(method);
444 vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); 445 vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
445 vars["output"] = name_resolver_->GetImmutableClassName(method->output_type()); 446 vars["output"] = GetOutput(method);
446 vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : ""; 447 vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : "";
447 printer->Print(vars, 448 printer->Print(vars,
448 "public $abstract$ void $name$(\n" 449 "public $abstract$ void $name$(\n"
449 " com.google.protobuf.RpcController controller,\n" 450 " com.google.protobuf.RpcController controller,\n"
450 " $input$ request,\n" 451 " $input$ request,\n"
451 " com.google.protobuf.RpcCallback<$output$> done)"); 452 " com.google.protobuf.RpcCallback<$output$> done)");
452 } 453 }
453 454
454 void ImmutableServiceGenerator::GenerateBlockingMethodSignature( 455 void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
455 io::Printer* printer, 456 io::Printer* printer,
456 const MethodDescriptor* method) { 457 const MethodDescriptor* method) {
457 map<string, string> vars; 458 std::map<string, string> vars;
458 vars["method"] = UnderscoresToCamelCase(method); 459 vars["method"] = UnderscoresToCamelCase(method);
459 vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); 460 vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
460 vars["output"] = name_resolver_->GetImmutableClassName(method->output_type()); 461 vars["output"] = GetOutput(method);
461 printer->Print(vars, 462 printer->Print(vars,
462 "\n" 463 "\n"
463 "public $output$ $method$(\n" 464 "public $output$ $method$(\n"
464 " com.google.protobuf.RpcController controller,\n" 465 " com.google.protobuf.RpcController controller,\n"
465 " $input$ request)\n" 466 " $input$ request)\n"
466 " throws com.google.protobuf.ServiceException"); 467 " throws com.google.protobuf.ServiceException");
467 } 468 }
468 469
469 } // namespace java 470 } // namespace java
470 } // namespace compiler 471 } // namespace compiler
471 } // namespace protobuf 472 } // namespace protobuf
472 } // namespace google 473 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698