This could be tidied up significantly, and at some point we will want to parse the markdown and generate more appropriate XML - but this is definitely better than nothing. Generated code changes coming in next commit.pull/845/head
parent
aa7ea3b698
commit
67dd42c50d
13 changed files with 178 additions and 1 deletions
@ -0,0 +1,98 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
#include <google/protobuf/compiler/csharp/csharp_doc_comment.h> |
||||
#include <google/protobuf/descriptor.h> |
||||
#include <google/protobuf/io/printer.h> |
||||
#include <google/protobuf/stubs/strutil.h> |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace csharp { |
||||
|
||||
// Functions to create C# XML documentation comments.
|
||||
// Currently this only includes documentation comments containing text specified as comments
|
||||
// in the .proto file; documentation comments generated just from field/message/enum/proto names
|
||||
// is inlined in the relevant code. If more control is required, that code can be moved here.
|
||||
|
||||
void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) { |
||||
string comments = location.leading_comments.empty() ? |
||||
location.trailing_comments : location.leading_comments; |
||||
if (comments.empty()) { |
||||
return; |
||||
} |
||||
// XML escaping... no need for apostrophes etc as the whole text is going to be a child
|
||||
// node of a summary element, not part of an attribute.
|
||||
comments = StringReplace(comments, "&", "&", true); |
||||
comments = StringReplace(comments, "<", "<", true); |
||||
vector<string> lines = Split(comments, "\n"); |
||||
printer->Print("/// <summary>\n"); |
||||
for (std::vector<string>::iterator it = lines.begin(); it != lines.end(); ++it) { |
||||
printer->Print("/// $line$\n", "line", *it); |
||||
} |
||||
printer->Print("/// </summary>\n"); |
||||
} |
||||
|
||||
template <typename DescriptorType> |
||||
static void WriteDocCommentBody( |
||||
io::Printer* printer, const DescriptorType* descriptor) { |
||||
SourceLocation location; |
||||
if (descriptor->GetSourceLocation(&location)) { |
||||
WriteDocCommentBodyImpl(printer, location); |
||||
} |
||||
} |
||||
|
||||
void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) { |
||||
WriteDocCommentBody(printer, message); |
||||
} |
||||
|
||||
void WritePropertyDocComment(io::Printer* printer, const FieldDescriptor* field) { |
||||
WriteDocCommentBody(printer, field); |
||||
} |
||||
|
||||
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enumDescriptor) { |
||||
WriteDocCommentBody(printer, enumDescriptor); |
||||
} |
||||
void WriteEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value) { |
||||
WriteDocCommentBody(printer, value); |
||||
} |
||||
|
||||
void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method) { |
||||
WriteDocCommentBody(printer, method); |
||||
} |
||||
|
||||
} // namespace csharp
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
@ -0,0 +1,51 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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.
|
||||
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__ |
||||
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__ |
||||
|
||||
#include <google/protobuf/io/printer.h> |
||||
#include <google/protobuf/descriptor.h> |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace csharp { |
||||
void WriteMessageDocComment(io::Printer* printer, const Descriptor* message); |
||||
void WritePropertyDocComment(io::Printer* printer, const FieldDescriptor* field); |
||||
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enumDescriptor); |
||||
void WriteEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value); |
||||
void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method); |
||||
} // namespace csharp
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__
|
Loading…
Reference in new issue