Support builder class for an immutable parcelable
As-is: An immutable parcelable's constructor needs every field as
arguments. It can break build whenever a field is added
To-be: Builder class is provided, so it doesn't break build even though
a field is added. And also, it respects a default value if the field is
not set.
In addition, check the duplicate field name after capitalizing the first
letter because of setter name.
Test: atest aidl_integration_test aidl_unittests
Bug: 161506914
Change-Id: Icf45d67f2c1c66af89d8eb80ea0f71120ced5e0d
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index e6c857d..ea11044 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -2323,5 +2323,15 @@
EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_));
}
+TEST_P(AidlTest, ImmtuableParcelableFieldNameRestriction) {
+ io_delegate_.SetFileContents("Foo.aidl", "@Immutable parcelable Foo { int a; int A; }");
+ Options options = Options::From("aidl --lang=java Foo.aidl");
+ const string expected_stderr =
+ "ERROR: Foo.aidl:1.22-26: The parcelable 'Foo' has duplicate field name 'A' after "
+ "capitalizing the first letter\n";
+ CaptureStderr();
+ EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_));
+ EXPECT_EQ(expected_stderr, GetCapturedStderr());
+}
} // namespace aidl
} // namespace android