write annotations when dumping structured parcelable

1. Compare annotations after sorting when checkapi
2. Add some testcases
3. Write annotations in the parcelable when aidl --dumpapi

Bug: 120454218
Test: ./runtests.sh
Change-Id: I02e3f3ae3e8ee626f4823128b22d0d4eba6167af
diff --git a/aidl_apicheck.cpp b/aidl_apicheck.cpp
index 853c349..069a434 100644
--- a/aidl_apicheck.cpp
+++ b/aidl_apicheck.cpp
@@ -33,7 +33,11 @@
 
 static bool have_compatible_annotations(const AidlAnnotatable& older,
                                         const AidlAnnotatable& newer) {
-  if (older.GetAnnotations() != newer.GetAnnotations()) {
+  set<AidlAnnotation> olderAnnotations(older.GetAnnotations().begin(),
+                                       older.GetAnnotations().end());
+  set<AidlAnnotation> newerAnnotations(newer.GetAnnotations().begin(),
+                                       newer.GetAnnotations().end());
+  if (olderAnnotations != newerAnnotations) {
     const string from = older.ToString().empty() ? "(empty)" : older.ToString();
     const string to = newer.ToString().empty() ? "(empty)" : newer.ToString();
     AIDL_ERROR(newer) << "Changed annotations: " << from << " to " << to;
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 0cc11ac..578a3e0 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -245,7 +245,7 @@
 }
 
 string AidlVariableDeclaration::ToString() const {
-  string ret = type_->ToString() + " " + name_;
+  string ret = type_->Signature() + " " + name_;
   if (default_value_ != nullptr) {
     ret += " = " + ValueString(AidlConstantValueDecorator);
   }
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index c1851bf..b396bdb 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -546,6 +546,7 @@
                                "   IFoo foo;\n"
                                "   List<IFoo> a;\n"
                                "   List<foo.bar.IFoo> b;\n"
+                               "   @nullable String[] c;\n"
                                "}\n");
   io_delegate_.SetFileContents("api.aidl", "");
   vector<string> args = {"aidl", "--dumpapi", "--out=dump", "foo/bar/IFoo.aidl",
@@ -574,6 +575,7 @@
   foo.bar.IFoo foo;
   List<foo.bar.IFoo> a;
   List<foo.bar.IFoo> b;
+  @nullable String[] c;
 }
 )");
 }
@@ -764,6 +766,16 @@
   EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_));
 }
 
+TEST_F(AidlTest, DiffrentOrderAnnotationsInCheckAPI) {
+  Options options = Options::From("aidl --checkapi old new");
+  io_delegate_.SetFileContents("old/p/IFoo.aidl",
+                               "package p; interface IFoo{ @utf8InCpp @nullable String foo();}");
+  io_delegate_.SetFileContents("new/p/IFoo.aidl",
+                               "package p; interface IFoo{ @nullable @utf8InCpp String foo();}");
+
+  EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_));
+}
+
 TEST_F(AidlTest, SuccessOnIdenticalApiDumps) {
   Options options = Options::From("aidl --checkapi old new");
   io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo();}");