Skip to content

Commit

Permalink
Merge pull request grpc#6674 from murgatroid99/node_ruby_codegen_comm…
Browse files Browse the repository at this point in the history
…ents

Add comments to generated code for Node and Ruby
  • Loading branch information
jtattermusch committed Jun 3, 2016
2 parents addf007 + b39ad70 commit 11ca9d8
Show file tree
Hide file tree
Showing 28 changed files with 753 additions and 124 deletions.
32 changes: 32 additions & 0 deletions examples/node/static_codegen/helloworld_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
// GENERATED CODE -- DO NOT EDIT!

// Original file comments:
// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
'use strict';
var grpc = require('grpc');
var helloworld_pb = require('./helloworld_pb.js');
Expand Down Expand Up @@ -27,7 +57,9 @@ function deserialize_HelloRequest(buffer_arg) {
}


// The greeting service definition.
var GreeterService = exports.GreeterService = {
// Sends a greeting
sayHello: {
path: '/helloworld.Greeter/SayHello',
requestStream: false,
Expand Down
4 changes: 2 additions & 2 deletions examples/node/static_codegen/helloworld_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions examples/node/static_codegen/route_guide/route_guide_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
// GENERATED CODE -- DO NOT EDIT!

// Original file comments:
// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
'use strict';
var grpc = require('grpc');
var route_guide_pb = require('./route_guide_pb.js');
Expand Down Expand Up @@ -60,7 +90,14 @@ function deserialize_RouteSummary(buffer_arg) {
}


// Interface exported by the server.
var RouteGuideService = exports.RouteGuideService = {
// A simple RPC.
//
// Obtains the feature at a given position.
//
// A feature with an empty name is returned if there's no feature at the given
// position.
getFeature: {
path: '/routeguide.RouteGuide/GetFeature',
requestStream: false,
Expand All @@ -72,6 +109,12 @@ var RouteGuideService = exports.RouteGuideService = {
responseSerialize: serialize_Feature,
responseDeserialize: deserialize_Feature,
},
// A server-to-client streaming RPC.
//
// Obtains the Features available within the given Rectangle. Results are
// streamed rather than returned at once (e.g. in a response message with a
// repeated field), as the rectangle may cover a large area and contain a
// huge number of features.
listFeatures: {
path: '/routeguide.RouteGuide/ListFeatures',
requestStream: false,
Expand All @@ -83,6 +126,10 @@ var RouteGuideService = exports.RouteGuideService = {
responseSerialize: serialize_Feature,
responseDeserialize: deserialize_Feature,
},
// A client-to-server streaming RPC.
//
// Accepts a stream of Points on a route being traversed, returning a
// RouteSummary when traversal is completed.
recordRoute: {
path: '/routeguide.RouteGuide/RecordRoute',
requestStream: true,
Expand All @@ -94,6 +141,10 @@ var RouteGuideService = exports.RouteGuideService = {
responseSerialize: serialize_RouteSummary,
responseDeserialize: deserialize_RouteSummary,
},
// A Bidirectional streaming RPC.
//
// Accepts a stream of RouteNotes sent while a route is being traversed,
// while receiving other RouteNotes (e.g. from other users).
routeChat: {
path: '/routeguide.RouteGuide/RouteChat',
requestStream: true,
Expand Down
10 changes: 5 additions & 5 deletions examples/node/static_codegen/route_guide/route_guide_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions examples/ruby/lib/helloworld_services.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 51 additions & 2 deletions examples/ruby/lib/route_guide_services.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/compiler/cpp_generator_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ inline grpc::string ClassName(const grpc::protobuf::Descriptor *descriptor,
}
}

// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetCppComments(const DescriptorType *desc, bool leading) {
return grpc_generator::GetPrefixedComments(desc, leading, "//");
}

} // namespace grpc_cpp_generator

#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
2 changes: 1 addition & 1 deletion src/compiler/cpp_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "src/compiler/cpp_generator_helpers.h"
#include "src/compiler/generator_helpers.h"

using grpc_generator::GetCppComments;
using grpc_cpp_generator::GetCppComments;

class ProtoBufMethod : public grpc_cpp_generator::Method {
public:
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/csharp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ using grpc::protobuf::MethodDescriptor;
using grpc::protobuf::io::Printer;
using grpc::protobuf::io::StringOutputStream;
using grpc_generator::MethodType;
using grpc_generator::GetCppComments;
using grpc_generator::GetMethodType;
using grpc_generator::METHODTYPE_NO_STREAMING;
using grpc_generator::METHODTYPE_CLIENT_STREAMING;
Expand Down Expand Up @@ -659,7 +658,7 @@ grpc::string GetServices(const FileDescriptor *file, bool generate_client,
out.Print("// source: $filename$\n", "filename", file->name());

// use C++ style as there are no file-level XML comments in .NET
grpc::string leading_comments = GetCppComments(file, true);
grpc::string leading_comments = GetCsharpComments(file, true);
if (!leading_comments.empty()) {
out.Print("// Original file comments:\n");
out.Print(leading_comments.c_str());
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/csharp_generator_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ inline bool ServicesFilename(const grpc::protobuf::FileDescriptor *file,
return true;
}

// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetCsharpComments(const DescriptorType *desc, bool leading) {
return grpc_generator::GetPrefixedComments(desc, leading, "//");
}

} // namespace grpc_csharp_generator

#endif // GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
8 changes: 4 additions & 4 deletions src/compiler/generator_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ inline grpc::string GenerateCommentsWithPrefix(
return oss.str();
}

// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetCppComments(const DescriptorType *desc, bool leading) {
inline grpc::string GetPrefixedComments(const DescriptorType *desc,
bool leading,
const grpc::string &prefix) {
std::vector<grpc::string> out;
if (leading) {
grpc_generator::GetComment(
Expand All @@ -281,7 +281,7 @@ inline grpc::string GetCppComments(const DescriptorType *desc, bool leading) {
grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING,
&out);
}
return GenerateCommentsWithPrefix(out, "//");
return GenerateCommentsWithPrefix(out, prefix);
}

} // namespace grpc_generator
Expand Down
Loading

0 comments on commit 11ca9d8

Please sign in to comment.