Fix Java comment format.

TrimmedLines was copied from hidl-gen to do this, but we weren't using
it in the output.

For simplicity, this converts a single-line block comment to a
multi-line block comment.

Fixes: 202563750
Test: goldens
Change-Id: I2130a32702fb0bc87156363d9dc0e7e7edb57621
diff --git a/comments.cpp b/comments.cpp
index afbdc8f..8feee28 100644
--- a/comments.cpp
+++ b/comments.cpp
@@ -40,6 +40,7 @@
 
 static const std::string_view kLineCommentBegin = "//";
 static const std::string_view kBlockCommentBegin = "/*";
+static const std::string_view kBlockCommentMid = " *";
 static const std::string_view kBlockCommentEnd = "*/";
 static const std::string_view kDocCommentBegin = "/**";
 static const std::string kTagDeprecated = "@deprecated";
@@ -222,15 +223,31 @@
   std::stringstream out;
   for (auto it = begin(comments); it != end(comments); it++) {
     const bool last = next(it) == end(comments);
-    // We only re-format the last/block comment which is not already a doc-style comment.
-    if (last && it->type == Comment::Type::BLOCK && !StartsWith(it->body, kDocCommentBegin)) {
-      out << kDocCommentBegin << ConsumePrefix(it->body, kBlockCommentBegin);
+    auto lines = TrimmedLines(*it);
+
+    if (it->type == Comment::Type::LINE) {
+      for (const auto& line : lines) {
+        out << kLineCommentBegin << line;
+      }
     } else {
-      out << it->body;
+      if (last || StartsWith(it->body, kDocCommentBegin)) {
+        out << kDocCommentBegin;
+      } else {
+        out << kBlockCommentBegin;
+      }
+      bool multiline = lines.size() > 1;
+
+      if (multiline) out << "\n";
+      for (const auto& line : lines) {
+        if (multiline) out << kBlockCommentMid;
+        out << " " << line;
+        if (multiline) out << "\n";
+      }
+      out << " " << kBlockCommentEnd << "\n";
     }
   }
   return out.str();
 }
 
 }  // namespace aidl
-}  // namespace android
\ No newline at end of file
+}  // namespace android