From 6c58b9a552577b2253057764e9917248c49d4384 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Mon, 19 Feb 2024 14:41:12 -0800 Subject: [PATCH] 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 --- .../protobuf/compiler/java/doc_comment.cc | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/google/protobuf/compiler/java/doc_comment.cc b/src/google/protobuf/compiler/java/doc_comment.cc index 11e2b32bd7..2e194dd59d 100644 --- a/src/google/protobuf/compiler/java/doc_comment.cc +++ b/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(" *
\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");
       }
     }