Avoid all leading/trailing doc comments during codegen tests.

Prototiller has subtley different rules about attaching these to objects, and relatively harmless transformations can cause codegen diffs where these move around.

PiperOrigin-RevId: 608402666
pull/15874/head
Mike Kruskal 9 months ago committed by Copybara-Service
parent 6caac65375
commit 6c58b9a552
  1. 38
      src/google/protobuf/compiler/java/doc_comment.cc

@ -126,6 +126,12 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer,
const SourceLocation& location,
const Options options,
const bool kdoc) {
if (options.strip_nonfunctional_codegen) {
// TODO: Remove once prototiller can avoid making
// extraneous formatting changes to comments.
return;
}
std::string comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
@ -147,24 +153,20 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer,
printer->Print(" * <pre>\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");
}
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");
}
}

Loading…
Cancel
Save