support multiple @JavaPassthrough

There can be @JavaPassthrough annotations for a single type.

Bug: n/a
Test: atest aidl_unittests
Change-Id: Ib4dcb00bf9148a5862cc04a2f18ab58d1f4ececd
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 87159e6..b9985e5 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -300,10 +300,6 @@
   return GetAnnotation(annotations_, AidlAnnotation::Type::UNSUPPORTED_APP_USAGE);
 }
 
-const AidlAnnotation* AidlAnnotatable::JavaPassthrough() const {
-  return GetAnnotation(annotations_, AidlAnnotation::Type::JAVA_PASSTHROUGH);
-}
-
 const AidlAnnotation* AidlAnnotatable::RustDerive() const {
   return GetAnnotation(annotations_, AidlAnnotation::Type::RUST_DERIVE);
 }
diff --git a/aidl_language.h b/aidl_language.h
index 64ced45..a648232 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -243,7 +243,6 @@
   void DumpAnnotations(CodeWriter* writer) const;
 
   const AidlAnnotation* UnsupportedAppUsage() const;
-  const AidlAnnotation* JavaPassthrough() const;
   const AidlAnnotation* RustDerive() const;
   const AidlTypeSpecifier* BackingType(const AidlTypenames& typenames) const;
   std::string ToString() const;
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 5b94a85..8b9cde7 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -2416,23 +2416,28 @@
 }
 
 TEST_F(AidlTest, ParseJavaPassthroughAnnotation) {
-  io_delegate_.SetFileContents("a/IFoo.aidl", R"(package a;
-    @JavaPassthrough(annotation="@com.android.Alice(arg=com.android.Alice.Value.A) ")
+  io_delegate_.SetFileContents("a/IFoo.aidl", R"--(package a;
+    @JavaPassthrough(annotation="@com.android.Alice(arg=com.android.Alice.Value.A)")
+    @JavaPassthrough(annotation="@com.android.AliceTwo")
     interface IFoo {
         @JavaPassthrough(annotation="@com.android.Bob")
         void foo(@JavaPassthrough(annotation="@com.android.Cat") int x);
         const @JavaPassthrough(annotation="@com.android.David") int A = 3;
-    })");
+    })--");
 
   Options java_options = Options::From("aidl --lang=java -o out a/IFoo.aidl");
   EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_));
 
   string java_out;
   EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/IFoo.java", &java_out));
-  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Alice(arg=com.android.Alice.Value.A)"));
-  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Bob"));
-  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Cat"));
-  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.David"));
+  // type-decl-level annotations with newline at the end
+  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Alice(arg=com.android.Alice.Value.A)\n"));
+  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.AliceTwo\n"));
+  // member-decl-level annotations with newline at the end
+  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Bob\n"));
+  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.David\n"));
+  // inline annotations with space at the end
+  EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Cat "));
 
   // Other backends shouldn't be bothered
   Options cpp_options = Options::From("aidl --lang=cpp -o out -h out a/IFoo.aidl");
diff --git a/generate_java.cpp b/generate_java.cpp
index 5b998df..223a258 100644
--- a/generate_java.cpp
+++ b/generate_java.cpp
@@ -464,12 +464,13 @@
     return raw_value.substr(1, raw_value.size() - 2);
   };
 
-  const AidlAnnotation* java_passthrough = a.JavaPassthrough();
-  if (java_passthrough != nullptr) {
-    for (const auto& name_and_param : java_passthrough->AnnotationParams(strip_double_quote)) {
-      if (name_and_param.first == "annotation") {
-        result.emplace_back(name_and_param.second);
-        break;
+  for (const auto& annotation : a.GetAnnotations()) {
+    if (annotation.GetType() == AidlAnnotation::Type::JAVA_PASSTHROUGH) {
+      for (const auto& name_and_param : annotation.AnnotationParams(strip_double_quote)) {
+        if (name_and_param.first == "annotation") {
+          result.emplace_back(name_and_param.second);
+          break;
+        }
       }
     }
   }