Limit comment tags placement

Documentation comments are recognized only when placed immediately
before entities.

--dumpapi now generates a single block comment when an entity is
hidden/deprecated to comply with the change.

  /* @hide
     @deprecated */
  AIDL entity;

Bug: 177276893
Bug: 177616426
Test: aidl_unittests
Change-Id: I2c00d8e234d1a1ec3fbbcf34f290e0b163d508c0
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 408bee8..7d8b1c8 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -31,6 +31,7 @@
 #include "aidl_language.h"
 #include "aidl_to_cpp.h"
 #include "aidl_to_java.h"
+#include "comments.h"
 #include "logging.h"
 #include "options.h"
 #include "tests/fake_io_delegate.h"
@@ -636,14 +637,12 @@
   EXPECT_NE(nullptr, parse_result);
   EXPECT_EQ("", GetCapturedStderr());
 
-  EXPECT_EQ((Comments{{Comment::Type::BLOCK, "/* foo */"}}), parse_result->GetComments());
+  EXPECT_EQ((Comments{{"/* foo */"}}), parse_result->GetComments());
 
   const AidlInterface* interface = parse_result->AsInterface();
-  EXPECT_EQ((Comments{{Comment::Type::BLOCK, "/* i */"}}),
-            interface->GetMethods()[0]->GetComments());
-  EXPECT_EQ((Comments{{Comment::Type::LINE, "// j\n"}}), interface->GetMethods()[1]->GetComments());
-  EXPECT_EQ((Comments{{Comment::Type::LINE, "// k1\n"}, {Comment::Type::BLOCK, "/* k2 */"}}),
-            interface->GetMethods()[2]->GetComments());
+  EXPECT_EQ((Comments{{"/* i */"}}), interface->GetMethods()[0]->GetComments());
+  EXPECT_EQ((Comments{{"// j\n"}}), interface->GetMethods()[1]->GetComments());
+  EXPECT_EQ((Comments{{"// k1\n"}, {"/* k2 */"}}), interface->GetMethods()[2]->GetComments());
 }
 
 TEST_P(AidlTest, CppHeaderCanBeIdentifierAsWell) {
@@ -662,8 +661,7 @@
   auto parse_result = Parse(input_path, input, typenames_, GetLanguage());
   EXPECT_NE(nullptr, parse_result);
   const AidlInterface* interface = parse_result->AsInterface();
-  EXPECT_EQ((Comments{{Comment::Type::LINE, "// get bar\n"}}),
-            interface->GetMethods()[0]->GetComments());
+  EXPECT_EQ((Comments{{"// get bar\n"}}), interface->GetMethods()[0]->GetComments());
 }
 
 TEST_F(AidlTest, ParsesPreprocessedFile) {
@@ -1439,12 +1437,13 @@
       "import foo.bar.Data;\n"
       "// commented /* @hide */\n"
       "interface IFoo {\n"
-      "    /* @hide */\n"
-      "    int foo(out int[] a, String b, boolean c, inout List<String>  d);\n"
-      "    int foo2(@utf8InCpp String x, inout List<String>  y);\n"
+      "    /* @hide applied \n"
+      "       @deprecated use foo2 */\n"
+      "    int foo(out int[] a, String b, boolean c, inout List<String> d);\n"
+      "    int foo2(@utf8InCpp String x, inout List<String> y);\n"
       "    IFoo foo3(IFoo foo);\n"
       "    Data getData();\n"
-      "    // @hide\n"
+      "    // @hide not applied\n"
       "    /** blahblah\n"
       "        @deprecated\n"
       "          reason why... */\n"
@@ -1474,29 +1473,38 @@
   ASSERT_TRUE(result);
   string actual;
   EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual));
-  EXPECT_EQ(actual, string(kPreamble).append(R"(package foo.bar;
+  EXPECT_EQ(string(kPreamble).append(R"(package foo.bar;
 interface IFoo {
-  /* @hide */
+  /**
+   * @hide
+   * @deprecated use foo2
+   */
   int foo(out int[] a, String b, boolean c, inout List<String> d);
   int foo2(@utf8InCpp String x, inout List<String> y);
   foo.bar.IFoo foo3(foo.bar.IFoo foo);
   foo.bar.Data getData();
-  /* @deprecated reason why... */
+  /**
+   * @deprecated reason why...
+   */
   const int A = 1;
   const String STR = "Hello";
 }
-)"));
+)"),
+            actual);
 
   EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/Data.aidl", &actual));
-  EXPECT_EQ(actual, string(kPreamble).append(R"(package foo.bar;
-/* @hide */
+  EXPECT_EQ(string(kPreamble).append(R"(package foo.bar;
+/**
+ * @hide
+ */
 parcelable Data {
   int x = 10;
   int y;
   foo.bar.IFoo foo;
   @nullable String[] c;
 }
-)"));
+)"),
+            actual);
 }
 
 TEST_F(AidlTest, ApiDumpWithManualIds) {