dumpapi: add a newline before preamble
Bug: n/a
Test: m test-root-package-update-api (no changes)
Change-Id: I1ca1ebbbeeeb2b6669a8a5e6238295d35cdead17
diff --git a/aidl_dumpapi.cpp b/aidl_dumpapi.cpp
index ae970ea..6364929 100644
--- a/aidl_dumpapi.cpp
+++ b/aidl_dumpapi.cpp
@@ -22,6 +22,7 @@
#include "logging.h"
#include "os.h"
+using android::base::EndsWith;
using android::base::Join;
using android::base::Split;
using std::string;
@@ -148,6 +149,17 @@
".aidl";
}
+static void DumpComments(CodeWriter& out, const Comments& comments) {
+ bool needs_newline = false;
+ for (const auto& c : comments) {
+ out << c.body;
+ needs_newline = !EndsWith(c.body, "\n");
+ }
+ if (needs_newline) {
+ out << "\n";
+ }
+}
+
bool dump_api(const Options& options, const IoDelegate& io_delegate) {
for (const auto& file : options.InputFiles()) {
AidlTypenames typenames;
@@ -159,9 +171,7 @@
unique_ptr<CodeWriter> writer =
io_delegate.GetCodeWriter(GetApiDumpPathFor(*type, options));
// dump doc comments (license) as well for each type
- for (const auto& c : doc.GetComments()) {
- (*writer) << c.body;
- }
+ DumpComments(*writer, doc.GetComments());
(*writer) << kPreamble;
if (!type->GetPackage().empty()) {
(*writer) << "package " << type->GetPackage() << ";\n";