csharp_doc_comment.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
38 
39 namespace google {
40 namespace protobuf {
41 namespace compiler {
42 namespace csharp {
43 
44 // Functions to create C# XML documentation comments.
45 // Currently this only includes documentation comments containing text specified as comments
46 // in the .proto file; documentation comments generated just from field/message/enum/proto names
47 // is inlined in the relevant code. If more control is required, that code can be moved here.
48 
50  string comments = location.leading_comments.empty() ?
51  location.trailing_comments : location.leading_comments;
52  if (comments.empty()) {
53  return;
54  }
55  // XML escaping... no need for apostrophes etc as the whole text is going to be a child
56  // node of a summary element, not part of an attribute.
57  comments = StringReplace(comments, "&", "&", true);
58  comments = StringReplace(comments, "<", "&lt;", true);
59  std::vector<string> lines;
60  SplitStringAllowEmpty(comments, "\n", &lines);
61  // TODO: We really should work out which part to put in the summary and which to put in the remarks...
62  // but that needs to be part of a bigger effort to understand the markdown better anyway.
63  printer->Print("/// <summary>\n");
64  bool last_was_empty = false;
65  // We squash multiple blank lines down to one, and remove any trailing blank lines. We need
66  // to preserve the blank lines themselves, as this is relevant in the markdown.
67  // Note that we can't remove leading or trailing whitespace as *that's* relevant in markdown too.
68  // (We don't skip "just whitespace" lines, either.)
69  for (std::vector<string>::iterator it = lines.begin(); it != lines.end(); ++it) {
70  string line = *it;
71  if (line.empty()) {
72  last_was_empty = true;
73  } else {
74  if (last_was_empty) {
75  printer->Print("///\n");
76  }
77  last_was_empty = false;
78  printer->Print("///$line$\n", "line", *it);
79  }
80  }
81  printer->Print("/// </summary>\n");
82 }
83 
84 template <typename DescriptorType>
85 static void WriteDocCommentBody(
86  io::Printer* printer, const DescriptorType* descriptor) {
88  if (descriptor->GetSourceLocation(&location)) {
90  }
91 }
92 
94  WriteDocCommentBody(printer, message);
95 }
96 
98  WriteDocCommentBody(printer, field);
99 }
100 
101 void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enumDescriptor) {
102  WriteDocCommentBody(printer, enumDescriptor);
103 }
105  WriteDocCommentBody(printer, value);
106 }
107 
109  WriteDocCommentBody(printer, method);
110 }
111 
112 } // namespace csharp
113 } // namespace compiler
114 } // namespace protobuf
115 } // namespace google
google::protobuf::io::Printer::Print
void Print(const std::map< std::string, std::string > &variables, const char *text)
Definition: printer.cc:112
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf::compiler::csharp::WriteEnumDocComment
void WriteEnumDocComment(io::Printer *printer, const EnumDescriptor *enumDescriptor)
Definition: csharp_doc_comment.cc:101
google::protobuf::compiler::csharp::WriteDocCommentBodyImpl
void WriteDocCommentBodyImpl(io::Printer *printer, SourceLocation location)
Definition: csharp_doc_comment.cc:49
google::protobuf::SourceLocation
Definition: src/google/protobuf/descriptor.h:145
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
strutil.h
csharp_doc_comment.h
printer.h
google::protobuf::MethodDescriptor
Definition: src/google/protobuf/descriptor.h:1234
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
location
GLint location
Definition: glcorearb.h:3074
google::protobuf::io::Printer
Definition: printer.h:181
google::protobuf::compiler::csharp::WriteMessageDocComment
void WriteMessageDocComment(io::Printer *printer, const Descriptor *message)
Definition: csharp_doc_comment.cc:93
google::protobuf::compiler::csharp::WriteEnumValueDocComment
void WriteEnumValueDocComment(io::Printer *printer, const EnumValueDescriptor *value)
Definition: csharp_doc_comment.cc:104
google::protobuf::StringReplace
void StringReplace(const string &s, const string &oldsub, const string &newsub, bool replace_all, string *res)
Definition: strutil.cc:148
google::protobuf::EnumValueDescriptor
Definition: src/google/protobuf/descriptor.h:1075
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
descriptor.h
google::protobuf::compiler::csharp::WritePropertyDocComment
void WritePropertyDocComment(io::Printer *printer, const FieldDescriptor *field)
Definition: csharp_doc_comment.cc:97
google::protobuf::compiler::csharp::WriteDocCommentBody
static void WriteDocCommentBody(io::Printer *printer, const DescriptorType *descriptor)
Definition: csharp_doc_comment.cc:85
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google::protobuf::EnumDescriptor
Definition: src/google/protobuf/descriptor.h:918
google::protobuf::compiler::csharp::WriteMethodDocComment
void WriteMethodDocComment(io::Printer *printer, const MethodDescriptor *method)
Definition: csharp_doc_comment.cc:108
it
MapIter it
Definition: php/ext/google/protobuf/map.c:205
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695
google::protobuf::SplitStringAllowEmpty
void SplitStringAllowEmpty(const string &full, const char *delim, std::vector< string > *result)
Definition: strutil.cc:268
google::protobuf::method
const Descriptor::ReservedRange const EnumValueDescriptor method
Definition: src/google/protobuf/descriptor.h:1973


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:49