|
|
|
@ -124,6 +124,7 @@ static std::string EscapeKdoc(const std::string& input) { |
|
|
|
|
|
|
|
|
|
static void WriteDocCommentBodyForLocation(io::Printer* printer, |
|
|
|
|
const SourceLocation& location, |
|
|
|
|
const Options options, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
std::string comments = location.leading_comments.empty() |
|
|
|
|
? location.trailing_comments |
|
|
|
@ -146,20 +147,24 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer, |
|
|
|
|
printer->Print(" * <pre>\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < lines.size(); i++) { |
|
|
|
|
// Lines should start with a single space and any extraneous leading
|
|
|
|
|
// spaces should be stripped. For lines starting with a /, the leading
|
|
|
|
|
// space will prevent putting it right after the leading asterick from
|
|
|
|
|
// closing the comment.
|
|
|
|
|
std::string line = lines[i]; |
|
|
|
|
line.erase(line.begin(), |
|
|
|
|
std::find_if(line.begin(), line.end(), [](unsigned char ch) { |
|
|
|
|
return !std::isspace(ch); |
|
|
|
|
})); |
|
|
|
|
if (!line.empty()) { |
|
|
|
|
printer->Print(" * $line$\n", "line", line); |
|
|
|
|
} else { |
|
|
|
|
printer->Print(" *\n"); |
|
|
|
|
// TODO: Remove once prototiller can avoid making
|
|
|
|
|
// extraneous formatting changes to comments.
|
|
|
|
|
if (!options.strip_nonfunctional_codegen) { |
|
|
|
|
for (size_t i = 0; i < lines.size(); i++) { |
|
|
|
|
// Lines should start with a single space and any extraneous leading
|
|
|
|
|
// spaces should be stripped. For lines starting with a /, the leading
|
|
|
|
|
// space will prevent putting it right after the leading asterick from
|
|
|
|
|
// closing the comment.
|
|
|
|
|
std::string line = lines[i]; |
|
|
|
|
line.erase(line.begin(), |
|
|
|
|
std::find_if(line.begin(), line.end(), [](unsigned char ch) { |
|
|
|
|
return !std::isspace(ch); |
|
|
|
|
})); |
|
|
|
|
if (!line.empty()) { |
|
|
|
|
printer->Print(" * $line$\n", "line", line); |
|
|
|
|
} else { |
|
|
|
|
printer->Print(" *\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -175,10 +180,10 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer, |
|
|
|
|
template <typename DescriptorType> |
|
|
|
|
static void WriteDocCommentBody(io::Printer* printer, |
|
|
|
|
const DescriptorType* descriptor, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
const Options options, const bool kdoc) { |
|
|
|
|
SourceLocation location; |
|
|
|
|
if (descriptor->GetSourceLocation(&location)) { |
|
|
|
|
WriteDocCommentBodyForLocation(printer, location, kdoc); |
|
|
|
|
WriteDocCommentBodyForLocation(printer, location, options, kdoc); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -213,9 +218,9 @@ static void WriteDebugString(io::Printer* printer, const FieldDescriptor* field, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteMessageDocComment(io::Printer* printer, const Descriptor* message, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
const Options options, const bool kdoc) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, message, kdoc); |
|
|
|
|
WriteDocCommentBody(printer, message, options, kdoc); |
|
|
|
|
if (kdoc) { |
|
|
|
|
printer->Print( |
|
|
|
|
" * Protobuf type `$fullname$`\n" |
|
|
|
@ -238,7 +243,7 @@ void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field, |
|
|
|
|
// And then we end with the javadoc tags if applicable.
|
|
|
|
|
// If the field is a group, the debug string might end with {.
|
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, field, kdoc); |
|
|
|
|
WriteDocCommentBody(printer, field, options, kdoc); |
|
|
|
|
WriteDebugString(printer, field, options, kdoc); |
|
|
|
|
printer->Print(" */\n"); |
|
|
|
|
} |
|
|
|
@ -276,7 +281,7 @@ void WriteFieldAccessorDocComment(io::Printer* printer, |
|
|
|
|
const Options options, const bool builder, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, field, kdoc); |
|
|
|
|
WriteDocCommentBody(printer, field, options, kdoc); |
|
|
|
|
WriteDebugString(printer, field, options, kdoc); |
|
|
|
|
if (!kdoc) WriteDeprecatedJavadoc(printer, field, type, options); |
|
|
|
|
switch (type) { |
|
|
|
@ -336,7 +341,7 @@ void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, |
|
|
|
|
const bool builder, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, field, kdoc); |
|
|
|
|
WriteDocCommentBody(printer, field, options, kdoc); |
|
|
|
|
WriteDebugString(printer, field, options, kdoc); |
|
|
|
|
if (!kdoc) WriteDeprecatedJavadoc(printer, field, type, options); |
|
|
|
|
switch (type) { |
|
|
|
@ -407,7 +412,7 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, |
|
|
|
|
const bool builder, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, field, kdoc); |
|
|
|
|
WriteDocCommentBody(printer, field, options, kdoc); |
|
|
|
|
WriteDebugString(printer, field, options, kdoc); |
|
|
|
|
if (!kdoc) WriteDeprecatedJavadoc(printer, field, type, options); |
|
|
|
|
switch (type) { |
|
|
|
@ -461,9 +466,9 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, |
|
|
|
|
// Enum
|
|
|
|
|
|
|
|
|
|
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, |
|
|
|
|
const bool kdoc) { |
|
|
|
|
const Options options, const bool kdoc) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, enum_, kdoc); |
|
|
|
|
WriteDocCommentBody(printer, enum_, options, kdoc); |
|
|
|
|
if (kdoc) { |
|
|
|
|
printer->Print( |
|
|
|
|
" * Protobuf enum `$fullname$`\n" |
|
|
|
@ -478,9 +483,10 @@ void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteEnumValueDocComment(io::Printer* printer, |
|
|
|
|
const EnumValueDescriptor* value) { |
|
|
|
|
const EnumValueDescriptor* value, |
|
|
|
|
const Options options) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, value, /* kdoc */ false); |
|
|
|
|
WriteDocCommentBody(printer, value, options, /* kdoc */ false); |
|
|
|
|
|
|
|
|
|
printer->Print( |
|
|
|
|
" * <code>$def$</code>\n" |
|
|
|
@ -489,19 +495,20 @@ void WriteEnumValueDocComment(io::Printer* printer, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteServiceDocComment(io::Printer* printer, |
|
|
|
|
const ServiceDescriptor* service) { |
|
|
|
|
const ServiceDescriptor* service, |
|
|
|
|
const Options options) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, service, /* kdoc */ false); |
|
|
|
|
WriteDocCommentBody(printer, service, options, /* kdoc */ false); |
|
|
|
|
printer->Print( |
|
|
|
|
" * Protobuf service {@code $fullname$}\n" |
|
|
|
|
" */\n", |
|
|
|
|
"fullname", EscapeJavadoc(service->full_name())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteMethodDocComment(io::Printer* printer, |
|
|
|
|
const MethodDescriptor* method) { |
|
|
|
|
void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method, |
|
|
|
|
const Options options) { |
|
|
|
|
printer->Print("/**\n"); |
|
|
|
|
WriteDocCommentBody(printer, method, /* kdoc */ false); |
|
|
|
|
WriteDocCommentBody(printer, method, options, /* kdoc */ false); |
|
|
|
|
printer->Print( |
|
|
|
|
" * <code>$def$</code>\n" |
|
|
|
|
" */\n", |
|
|
|
|