syntax: annotations before [] and type args

This is a re-write of the grammar to support "T @annotation []" or
"List<@annotation T>". (To be specific, TYPE_USE annotations in Java).

However, the compiler doesn't support those annotations yet and rejects
input with TYPE_USE annotations.

This will make it easy to support them when we want(or are ready) to.

Bug: 174862286
Test: aidl_unittests
Change-Id: Idf0a0aeda6fd33cbdd225276cb9a5ea36f29f59b
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 0baf5ba..7ffe5f7 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -3294,11 +3294,30 @@
   io_delegate_.SetFileContents("a/Bar.aidl", "package a; parcelable Bar { List[]<String> a; }");
 
   Options options = Options::From("aidl a/Bar.aidl -I . -o out --lang=java");
-  const string expected_stderr =
-      "ERROR: a/Bar.aidl:1.28-33: Must specify type parameters (<>) before array ([]).\n";
   CaptureStderr();
   EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_));
-  EXPECT_EQ(expected_stderr, GetCapturedStderr());
+  EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr("syntax error, unexpected '<'"));
+}
+
+TEST_F(AidlTest, NullableArraysAreNotSupported) {
+  io_delegate_.SetFileContents("a/Bar.aidl",
+                               "package a; parcelable Bar { String @nullable [] a; }");
+
+  Options options = Options::From("aidl a/Bar.aidl -I . -o out --lang=java");
+  CaptureStderr();
+  EXPECT_EQ(1, ::android::aidl::compile_aidl(options, io_delegate_));
+  EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr("Annotations for arrays are not supported."));
+}
+
+TEST_F(AidlTest, ListOfNullablesAreNotSupported) {
+  io_delegate_.SetFileContents("a/Bar.aidl",
+                               "package a; parcelable Bar { List<@nullable String> a; }");
+
+  Options options = Options::From("aidl a/Bar.aidl -I . -o out --lang=java");
+  CaptureStderr();
+  EXPECT_EQ(1, ::android::aidl::compile_aidl(options, io_delegate_));
+  EXPECT_THAT(GetCapturedStderr(),
+              testing::HasSubstr("Annotations for type arguments are not supported."));
 }
 
 struct GenericAidlTest : ::testing::Test {