~ubuntu-branches/debian/stretch/protobuf/stretch

« back to all changes in this revision

Viewing changes to src/google/protobuf/compiler/java/java_service.cc

  • Committer: Package Import Robot
  • Author(s): Robert S. Edmonds
  • Date: 2014-09-11 22:50:10 UTC
  • mfrom: (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20140911225010-wt4yo9dpc1fzuq5g
Tags: 2.6.0-3
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
//  Sanjay Ghemawat, Jeff Dean, and others.
34
34
 
35
35
#include <google/protobuf/compiler/java/java_service.h>
 
36
 
 
37
#include <google/protobuf/compiler/java/java_context.h>
36
38
#include <google/protobuf/compiler/java/java_doc_comment.h>
37
39
#include <google/protobuf/compiler/java/java_helpers.h>
 
40
#include <google/protobuf/compiler/java/java_name_resolver.h>
38
41
#include <google/protobuf/io/printer.h>
39
42
#include <google/protobuf/descriptor.pb.h>
40
43
#include <google/protobuf/stubs/strutil.h>
49
52
 
50
53
ServiceGenerator::~ServiceGenerator() {}
51
54
 
52
 
void ServiceGenerator::Generate(io::Printer* printer) {
53
 
  bool is_own_file = descriptor_->file()->options().java_multiple_files();
 
55
// ===================================================================
 
56
ImmutableServiceGenerator::ImmutableServiceGenerator(
 
57
    const ServiceDescriptor* descriptor, Context* context)
 
58
    : ServiceGenerator(descriptor), context_(context),
 
59
    name_resolver_(context->GetNameResolver()) {}
 
60
 
 
61
ImmutableServiceGenerator::~ImmutableServiceGenerator() {}
 
62
 
 
63
void ImmutableServiceGenerator::Generate(io::Printer* printer) {
 
64
  bool is_own_file =
 
65
    MultipleJavaFiles(descriptor_->file(), /* immutable = */ true);
54
66
  WriteServiceDocComment(printer, descriptor_);
55
67
  printer->Print(
56
68
    "public $static$ abstract class $classname$\n"
77
89
    "    getDescriptor() {\n"
78
90
    "  return $file$.getDescriptor().getServices().get($index$);\n"
79
91
    "}\n",
80
 
    "file", ClassName(descriptor_->file()),
 
92
    "file", name_resolver_->GetImmutableClassName(descriptor_->file()),
81
93
    "index", SimpleItoa(descriptor_->index()));
82
94
  GenerateGetDescriptorForType(printer);
83
95
 
98
110
  printer->Print("}\n\n");
99
111
}
100
112
 
101
 
void ServiceGenerator::GenerateGetDescriptorForType(io::Printer* printer) {
 
113
void ImmutableServiceGenerator::GenerateGetDescriptorForType(
 
114
    io::Printer* printer) {
102
115
  printer->Print(
103
116
    "public final com.google.protobuf.Descriptors.ServiceDescriptor\n"
104
117
    "    getDescriptorForType() {\n"
106
119
    "}\n");
107
120
}
108
121
 
109
 
void ServiceGenerator::GenerateInterface(io::Printer* printer) {
 
122
void ImmutableServiceGenerator::GenerateInterface(io::Printer* printer) {
110
123
  printer->Print("public interface Interface {\n");
111
124
  printer->Indent();
112
125
  GenerateAbstractMethods(printer);
114
127
  printer->Print("}\n\n");
115
128
}
116
129
 
117
 
void ServiceGenerator::GenerateNewReflectiveServiceMethod(
 
130
void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod(
118
131
    io::Printer* printer) {
119
132
  printer->Print(
120
133
    "public static com.google.protobuf.Service newReflectiveService(\n"
141
154
  printer->Print("}\n\n");
142
155
}
143
156
 
144
 
void ServiceGenerator::GenerateNewReflectiveBlockingServiceMethod(
 
157
void ImmutableServiceGenerator::GenerateNewReflectiveBlockingServiceMethod(
145
158
    io::Printer* printer) {
146
159
  printer->Print(
147
160
    "public static com.google.protobuf.BlockingService\n"
162
175
  printer->Print("}\n\n");
163
176
}
164
177
 
165
 
void ServiceGenerator::GenerateAbstractMethods(io::Printer* printer) {
 
178
void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) {
166
179
  for (int i = 0; i < descriptor_->method_count(); i++) {
167
180
    const MethodDescriptor* method = descriptor_->method(i);
168
181
    WriteMethodDocComment(printer, method);
171
184
  }
172
185
}
173
186
 
174
 
void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
 
187
void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
175
188
  printer->Print(
176
189
    "\n"
177
190
    "public final void callMethod(\n"
194
207
    map<string, string> vars;
195
208
    vars["index"] = SimpleItoa(i);
196
209
    vars["method"] = UnderscoresToCamelCase(method);
197
 
    vars["input"] = ClassName(method->input_type());
198
 
    vars["output"] = ClassName(method->output_type());
 
210
    vars["input"] = name_resolver_->GetImmutableClassName(
 
211
        method->input_type());
 
212
    vars["output"] = name_resolver_->GetImmutableClassName(
 
213
        method->output_type());
199
214
    printer->Print(vars,
200
215
      "case $index$:\n"
201
216
      "  this.$method$(controller, ($input$)request,\n"
217
232
    "\n");
218
233
}
219
234
 
220
 
void ServiceGenerator::GenerateCallBlockingMethod(io::Printer* printer) {
 
235
void ImmutableServiceGenerator::GenerateCallBlockingMethod(
 
236
    io::Printer* printer) {
221
237
  printer->Print(
222
238
    "\n"
223
239
    "public final com.google.protobuf.Message callBlockingMethod(\n"
239
255
    map<string, string> vars;
240
256
    vars["index"] = SimpleItoa(i);
241
257
    vars["method"] = UnderscoresToCamelCase(method);
242
 
    vars["input"] = ClassName(method->input_type());
243
 
    vars["output"] = ClassName(method->output_type());
 
258
    vars["input"] = name_resolver_->GetImmutableClassName(
 
259
        method->input_type());
 
260
    vars["output"] = name_resolver_->GetImmutableClassName(
 
261
        method->output_type());
244
262
    printer->Print(vars,
245
263
      "case $index$:\n"
246
264
      "  return impl.$method$(controller, ($input$)request);\n");
259
277
    "\n");
260
278
}
261
279
 
262
 
void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
 
280
void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
263
281
                                            io::Printer* printer) {
264
282
  /*
265
283
   * TODO(cpovirk): The exception message says "Service.foo" when it may be
283
301
    const MethodDescriptor* method = descriptor_->method(i);
284
302
    map<string, string> vars;
285
303
    vars["index"] = SimpleItoa(i);
286
 
    vars["type"] = ClassName(
 
304
    vars["type"] = name_resolver_->GetImmutableClassName(
287
305
      (which == REQUEST) ? method->input_type() : method->output_type());
288
306
    printer->Print(vars,
289
307
      "case $index$:\n"
303
321
    "\n");
304
322
}
305
323
 
306
 
void ServiceGenerator::GenerateStub(io::Printer* printer) {
 
324
void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
307
325
  printer->Print(
308
326
    "public static Stub newStub(\n"
309
327
    "    com.google.protobuf.RpcChannel channel) {\n"
312
330
    "\n"
313
331
    "public static final class Stub extends $classname$ implements Interface {"
314
332
    "\n",
315
 
    "classname", ClassName(descriptor_));
 
333
    "classname", name_resolver_->GetImmutableClassName(descriptor_));
316
334
  printer->Indent();
317
335
 
318
336
  printer->Print(
335
353
 
336
354
    map<string, string> vars;
337
355
    vars["index"] = SimpleItoa(i);
338
 
    vars["output"] = ClassName(method->output_type());
 
356
    vars["output"] = name_resolver_->GetImmutableClassName(
 
357
        method->output_type());
339
358
    printer->Print(vars,
340
359
      "channel.callMethod(\n"
341
360
      "  getDescriptor().getMethods().get($index$),\n"
357
376
    "\n");
358
377
}
359
378
 
360
 
void ServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
 
379
void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
361
380
  printer->Print(
362
381
    "public static BlockingInterface newBlockingStub(\n"
363
382
    "    com.google.protobuf.BlockingRpcChannel channel) {\n"
399
418
 
400
419
    map<string, string> vars;
401
420
    vars["index"] = SimpleItoa(i);
402
 
    vars["output"] = ClassName(method->output_type());
 
421
    vars["output"] = name_resolver_->GetImmutableClassName(
 
422
        method->output_type());
403
423
    printer->Print(vars,
404
424
      "return ($output$) channel.callBlockingMethod(\n"
405
425
      "  getDescriptor().getMethods().get($index$),\n"
417
437
  printer->Print("}\n");
418
438
}
419
439
 
420
 
void ServiceGenerator::GenerateMethodSignature(io::Printer* printer,
 
440
void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer,
421
441
                                               const MethodDescriptor* method,
422
442
                                               IsAbstract is_abstract) {
423
443
  map<string, string> vars;
424
444
  vars["name"] = UnderscoresToCamelCase(method);
425
 
  vars["input"] = ClassName(method->input_type());
426
 
  vars["output"] = ClassName(method->output_type());
 
445
  vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
 
446
  vars["output"] = name_resolver_->GetImmutableClassName(method->output_type());
427
447
  vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : "";
428
448
  printer->Print(vars,
429
449
    "public $abstract$ void $name$(\n"
432
452
    "    com.google.protobuf.RpcCallback<$output$> done)");
433
453
}
434
454
 
435
 
void ServiceGenerator::GenerateBlockingMethodSignature(
 
455
void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
436
456
    io::Printer* printer,
437
457
    const MethodDescriptor* method) {
438
458
  map<string, string> vars;
439
459
  vars["method"] = UnderscoresToCamelCase(method);
440
 
  vars["input"] = ClassName(method->input_type());
441
 
  vars["output"] = ClassName(method->output_type());
 
460
  vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
 
461
  vars["output"] = name_resolver_->GetImmutableClassName(method->output_type());
442
462
  printer->Print(vars,
443
463
    "\n"
444
464
    "public $output$ $method$(\n"