diff options
author | nechda <nechda@yandex-team.com> | 2024-08-29 23:50:27 +0300 |
---|---|---|
committer | nechda <nechda@yandex-team.com> | 2024-08-30 00:05:25 +0300 |
commit | e10d6638f07a82edae3ea8197b9f5c0affcc07ea (patch) | |
tree | 571c38cec05813766a1ad290c9d51ce7ace52919 /contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc | |
parent | e79b38f2bbbf78d295d1901d2a79f898022d5224 (diff) | |
download | ydb-e10d6638f07a82edae3ea8197b9f5c0affcc07ea.tar.gz |
Update cpp-protobuf to 22.5
Привет!\
Этот PR переключат cpp & python библиотеки protobuf на версию 22.5
Если у вас возникли проблемы после влития этого PR:
1. Если начали падать канон тесты, то проведите их переканонизацию
2. Прочитайте <https://wiki.yandex-team.ru/users/nechda/obnovlenie-cpp-protobuf-22.5/> страничку с основными изменениями
3. Если страничка в вики не помогла, то пишите в [DEVTOOLSSUPPORT](https://st.yandex-team.ru/DEVTOOLSSUPPORT)
7fecade616c20a841b9e9af7b7998bdfc8d2807d
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc')
-rw-r--r-- | contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc | 184 |
1 files changed, 131 insertions, 53 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc b/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc index ec7dce7d34..74fb087ccf 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/java/doc_comment.cc @@ -32,13 +32,14 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include <google/protobuf/compiler/java/doc_comment.h> +#include "google/protobuf/compiler/java/doc_comment.h" #include <vector> -#include <google/protobuf/io/printer.h> -#include <google/protobuf/stubs/strutil.h> -#include <google/protobuf/descriptor.pb.h> +#include "y_absl/strings/str_split.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { @@ -103,26 +104,65 @@ TProtoStringType EscapeJavadoc(const TProtoStringType& input) { return result; } +static TProtoStringType EscapeKdoc(const TProtoStringType& input) { + TProtoStringType result; + result.reserve(input.size() * 2); + + char prev = 'a'; + + for (char c : input) { + switch (c) { + case '*': + // Avoid "/*". + if (prev == '/') { + result.append("*"); + } else { + result.push_back(c); + } + break; + case '/': + // Avoid "*/". + if (prev == '*') { + result.append("/"); + } else { + result.push_back(c); + } + break; + default: + result.push_back(c); + break; + } + + prev = c; + } + + return result; +} + static void WriteDocCommentBodyForLocation(io::Printer* printer, - const SourceLocation& location) { + const SourceLocation& location, + const bool kdoc) { TProtoStringType comments = location.leading_comments.empty() ? location.trailing_comments : location.leading_comments; if (!comments.empty()) { - // TODO(kenton): Ideally we should parse the comment text as Markdown and - // write it back as HTML, but this requires a Markdown parser. For now - // we just use <pre> to get fixed-width text formatting. - - // If the comment itself contains block comment start or end markers, - // HTML-escape them so that they don't accidentally close the doc comment. - comments = EscapeJavadoc(comments); + if (kdoc) { + comments = EscapeKdoc(comments); + } else { + comments = EscapeJavadoc(comments); + } - std::vector<TProtoStringType> lines = Split(comments, "\n"); + std::vector<TProtoStringType> lines = y_absl::StrSplit(comments, "\n"); while (!lines.empty() && lines.back().empty()) { lines.pop_back(); } - printer->Print(" * <pre>\n"); + if (kdoc) { + printer->Print(" * ```\n"); + } else { + printer->Print(" * <pre>\n"); + } + for (int i = 0; i < lines.size(); i++) { // Most lines should start with a space. Watch out for lines that start // with a /, since putting that right after the leading asterisk will @@ -133,18 +173,23 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer, printer->Print(" *$line$\n", "line", lines[i]); } } - printer->Print( - " * </pre>\n" - " *\n"); + + if (kdoc) { + printer->Print(" * ```\n"); + } else { + printer->Print(" * </pre>\n"); + } + printer->Print(" *\n"); } } template <typename DescriptorType> static void WriteDocCommentBody(io::Printer* printer, - const DescriptorType* descriptor) { + const DescriptorType* descriptor, + const bool kdoc) { SourceLocation location; if (descriptor->GetSourceLocation(&location)) { - WriteDocCommentBodyForLocation(printer, location); + WriteDocCommentBodyForLocation(printer, location, kdoc); } } @@ -164,16 +209,36 @@ static TProtoStringType FirstLineOf(const TProtoStringType& value) { return result; } -void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) { +static void WriteDebugString(io::Printer* printer, const FieldDescriptor* field, + const bool kdoc) { + if (kdoc) { + printer->Print(" * `$def$`\n", "def", + EscapeKdoc(FirstLineOf(field->DebugString()))); + } else { + printer->Print(" * <code>$def$</code>\n", "def", + EscapeJavadoc(FirstLineOf(field->DebugString()))); + } +} + +void WriteMessageDocComment(io::Printer* printer, const Descriptor* message, + const bool kdoc) { printer->Print("/**\n"); - WriteDocCommentBody(printer, message); - printer->Print( - " * Protobuf type {@code $fullname$}\n" - " */\n", - "fullname", EscapeJavadoc(message->full_name())); + WriteDocCommentBody(printer, message, kdoc); + if (kdoc) { + printer->Print( + " * Protobuf type `$fullname$`\n" + " */\n", + "fullname", EscapeKdoc(message->full_name())); + } else { + printer->Print( + " * Protobuf type {@code $fullname$}\n" + " */\n", + "fullname", EscapeJavadoc(message->full_name())); + } } -void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) { +void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field, + const bool kdoc) { // We start the comment with the main body based on the comments from the // .proto file (if present). We then continue with the field declaration, // e.g.: @@ -181,9 +246,14 @@ 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); - printer->Print(" * <code>$def$</code>\n", "def", - EscapeJavadoc(FirstLineOf(field->DebugString()))); + WriteDocCommentBody(printer, field, kdoc); + if (kdoc) { + printer->Print(" * `$def$`\n", "def", + EscapeKdoc(FirstLineOf(field->DebugString()))); + } else { + printer->Print(" * <code>$def$</code>\n", "def", + EscapeJavadoc(FirstLineOf(field->DebugString()))); + } printer->Print(" */\n"); } @@ -214,12 +284,11 @@ void WriteDeprecatedJavadoc(io::Printer* printer, const FieldDescriptor* field, void WriteFieldAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder) { + const bool builder, const bool kdoc) { printer->Print("/**\n"); - WriteDocCommentBody(printer, field); - printer->Print(" * <code>$def$</code>\n", "def", - EscapeJavadoc(FirstLineOf(field->DebugString()))); - WriteDeprecatedJavadoc(printer, field, type); + WriteDocCommentBody(printer, field, kdoc); + WriteDebugString(printer, field, kdoc); + if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); switch (type) { case HAZZER: printer->Print(" * @return Whether the $name$ field is set.\n", "name", @@ -273,12 +342,12 @@ void WriteFieldAccessorDocComment(io::Printer* printer, void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder) { + const bool builder, + const bool kdoc) { printer->Print("/**\n"); - WriteDocCommentBody(printer, field); - printer->Print(" * <code>$def$</code>\n", "def", - EscapeJavadoc(FirstLineOf(field->DebugString()))); - WriteDeprecatedJavadoc(printer, field, type); + WriteDocCommentBody(printer, field, kdoc); + WriteDebugString(printer, field, kdoc); + if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); switch (type) { case HAZZER: // Should never happen @@ -343,12 +412,12 @@ void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder) { + const bool builder, + const bool kdoc) { printer->Print("/**\n"); - WriteDocCommentBody(printer, field); - printer->Print(" * <code>$def$</code>\n", "def", - EscapeJavadoc(FirstLineOf(field->DebugString()))); - WriteDeprecatedJavadoc(printer, field, type); + WriteDocCommentBody(printer, field, kdoc); + WriteDebugString(printer, field, kdoc); + if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); switch (type) { case HAZZER: // Should never happen @@ -399,19 +468,28 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, // Enum -void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) { +void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, + const bool kdoc) { printer->Print("/**\n"); - WriteDocCommentBody(printer, enum_); - printer->Print( - " * Protobuf enum {@code $fullname$}\n" - " */\n", - "fullname", EscapeJavadoc(enum_->full_name())); + WriteDocCommentBody(printer, enum_, kdoc); + if (kdoc) { + printer->Print( + " * Protobuf enum `$fullname$`\n" + " */\n", + "fullname", EscapeKdoc(enum_->full_name())); + } else { + printer->Print( + " * Protobuf enum {@code $fullname$}\n" + " */\n", + "fullname", EscapeJavadoc(enum_->full_name())); + } } void WriteEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value) { printer->Print("/**\n"); - WriteDocCommentBody(printer, value); + WriteDocCommentBody(printer, value, /* kdoc */ false); + printer->Print( " * <code>$def$</code>\n" " */\n", @@ -421,7 +499,7 @@ void WriteEnumValueDocComment(io::Printer* printer, void WriteServiceDocComment(io::Printer* printer, const ServiceDescriptor* service) { printer->Print("/**\n"); - WriteDocCommentBody(printer, service); + WriteDocCommentBody(printer, service, /* kdoc */ false); printer->Print( " * Protobuf service {@code $fullname$}\n" " */\n", @@ -431,7 +509,7 @@ void WriteServiceDocComment(io::Printer* printer, void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method) { printer->Print("/**\n"); - WriteDocCommentBody(printer, method); + WriteDocCommentBody(printer, method, /* kdoc */ false); printer->Print( " * <code>$def$</code>\n" " */\n", |