Rename @Immutable to @JavaOnlyImmutable
Test: atest aidl_integration_test aidl_unittests
Bug: 161506914
Change-Id: I0258d6af9b7378416435eb6b47098521ca7e8beb
diff --git a/Android.bp b/Android.bp
index 580e5a1..62ecb6c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -338,7 +338,7 @@
"tests/java_app/src/android/aidl/tests/ExtensionTests.java",
"tests/java_app/src/android/aidl/tests/GenericTests.java",
"tests/java_app/src/android/aidl/tests/MapTests.java",
- "tests/java_app/src/android/aidl/tests/ImmutableAnnotationTests.java",
+ "tests/java_app/src/android/aidl/tests/JavaOnlyImmutableAnnotationTests.java",
"tests/java_app/src/android/aidl/tests/NullableTests.java",
"tests/java_app/src/android/aidl/tests/SimpleParcelable.java",
"tests/java_app/src/android/aidl/tests/TestFailException.java",
diff --git a/aidl_checkapi.cpp b/aidl_checkapi.cpp
index 9e73f31..2e41c63 100644
--- a/aidl_checkapi.cpp
+++ b/aidl_checkapi.cpp
@@ -52,7 +52,7 @@
static const set<AidlAnnotation::Type> kIgnoreAnnotations{
AidlAnnotation::Type::NULLABLE,
AidlAnnotation::Type::JAVA_DEBUG,
- AidlAnnotation::Type::IMMUTABLE,
+ AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE,
};
set<AidlAnnotation> annotations;
for (const AidlAnnotation& annotation : node.GetAnnotations()) {
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 777e0f8..f356f32 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -132,7 +132,7 @@
{AidlAnnotation::Type::BACKING, "Backing", {{"type", "String"}}},
{AidlAnnotation::Type::JAVA_PASSTHROUGH, "JavaPassthrough", {{"annotation", "String"}}},
{AidlAnnotation::Type::JAVA_DEBUG, "JavaDebug", {}},
- {AidlAnnotation::Type::IMMUTABLE, "Immutable", {}},
+ {AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE, "JavaOnlyImmutable", {}},
};
return kSchemas;
}
@@ -277,8 +277,8 @@
return GetAnnotation(annotations_, AidlAnnotation::Type::VINTF_STABILITY);
}
-bool AidlAnnotatable::IsImmutable() const {
- return GetAnnotation(annotations_, AidlAnnotation::Type::IMMUTABLE);
+bool AidlAnnotatable::IsJavaOnlyImmutable() const {
+ return GetAnnotation(annotations_, AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE);
}
const AidlAnnotation* AidlAnnotatable::UnsupportedAppUsage() const {
@@ -789,7 +789,7 @@
std::set<AidlAnnotation::Type> AidlParcelable::GetSupportedAnnotations() const {
return {AidlAnnotation::Type::VINTF_STABILITY, AidlAnnotation::Type::UNSUPPORTED_APP_USAGE,
AidlAnnotation::Type::JAVA_STABLE_PARCELABLE, AidlAnnotation::Type::HIDE,
- AidlAnnotation::Type::JAVA_PASSTHROUGH, AidlAnnotation::Type::IMMUTABLE};
+ AidlAnnotation::Type::JAVA_PASSTHROUGH, AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE};
}
bool AidlParcelable::CheckValid(const AidlTypenames& typenames) const {
@@ -834,7 +834,7 @@
AidlAnnotation::Type::HIDE,
AidlAnnotation::Type::JAVA_PASSTHROUGH,
AidlAnnotation::Type::JAVA_DEBUG,
- AidlAnnotation::Type::IMMUTABLE};
+ AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE};
}
bool AidlStructuredParcelable::CheckValid(const AidlTypenames& typenames) const {
@@ -846,8 +846,8 @@
for (const auto& v : GetFields()) {
success = success && v->CheckValid(typenames);
bool duplicated;
- if (IsImmutable()) {
- success = success && typenames.CanBeImmutable(v->GetType());
+ if (IsJavaOnlyImmutable()) {
+ success = success && typenames.CanBeJavaOnlyImmutable(v->GetType());
duplicated = !fieldnames.emplace(CapitalizeFirstLetter(v->GetName())).second;
} else {
duplicated = !fieldnames.emplace(v->GetName()).second;
@@ -856,7 +856,7 @@
if (duplicated) {
AIDL_ERROR(this) << "The parcelable '" << this->GetName() << "' has duplicate field name '"
<< v->GetName() << "'"
- << (IsImmutable() ? " after capitalizing the first letter" : "");
+ << (IsJavaOnlyImmutable() ? " after capitalizing the first letter" : "");
return false;
}
}
diff --git a/aidl_language.h b/aidl_language.h
index 512636d..7a53332 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -166,7 +166,7 @@
UTF8_IN_CPP,
JAVA_PASSTHROUGH,
JAVA_DEBUG,
- IMMUTABLE,
+ JAVA_ONLY_IMMUTABLE,
};
static std::string TypeToString(Type type);
@@ -230,7 +230,7 @@
bool IsNullable() const;
bool IsUtf8InCpp() const;
bool IsVintfStability() const;
- bool IsImmutable() const;
+ bool IsJavaOnlyImmutable() const;
bool IsStableApiParcelable(Options::Language lang) const;
bool IsHide() const;
bool IsJavaDebug() const;
diff --git a/aidl_typenames.cpp b/aidl_typenames.cpp
index 4697782..4b44ffd 100644
--- a/aidl_typenames.cpp
+++ b/aidl_typenames.cpp
@@ -219,13 +219,13 @@
// Only immutable Parcelable, primitive type, and String, and List, Map, array of the types can be
// immutable.
-bool AidlTypenames::CanBeImmutable(const AidlTypeSpecifier& type) const {
+bool AidlTypenames::CanBeJavaOnlyImmutable(const AidlTypeSpecifier& type) const {
const string& name = type.GetName();
if (type.IsGeneric()) {
if (type.GetName() == "List" || type.GetName() == "Map") {
const auto& types = type.GetTypeParameters();
return std::all_of(types.begin(), types.end(),
- [this](const auto& t) { return CanBeImmutable(*t); });
+ [this](const auto& t) { return CanBeJavaOnlyImmutable(*t); });
}
AIDL_ERROR(type) << "For a generic type, an immutable parcelable can contain only List or Map.";
return false;
@@ -239,7 +239,7 @@
"type, and String.";
return false;
}
- return t->IsImmutable();
+ return t->IsJavaOnlyImmutable();
}
// Only T[], List, Map, ParcelFileDescriptor and mutable Parcelable can be an out parameter.
@@ -252,7 +252,7 @@
const AidlDefinedType* t = TryGetDefinedType(type.GetName());
CHECK(t != nullptr) << "Unrecognized type: '" << type.GetName() << "'";
// An 'out' field is passed as an argument, so it doesn't make sense if it is immutable.
- return t->AsParcelable() != nullptr && !t->IsImmutable();
+ return t->AsParcelable() != nullptr && !t->IsJavaOnlyImmutable();
}
const AidlEnumDeclaration* AidlTypenames::GetEnumDeclaration(const AidlTypeSpecifier& type) const {
diff --git a/aidl_typenames.h b/aidl_typenames.h
index 2bcc409..aaee4e2 100644
--- a/aidl_typenames.h
+++ b/aidl_typenames.h
@@ -68,7 +68,7 @@
};
ResolvedTypename ResolveTypename(const string& type_name) const;
bool CanBeOutParameter(const AidlTypeSpecifier& type) const;
- bool CanBeImmutable(const AidlTypeSpecifier& type) const;
+ bool CanBeJavaOnlyImmutable(const AidlTypeSpecifier& type) const;
bool IsIgnorableImport(const string& import) const;
// Returns the AidlEnumDeclaration of the given type, or nullptr if the type
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index ea11044..40a0d9e 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -335,7 +335,7 @@
const string expected_stderr =
"ERROR: a/Foo.aidl:1.32-37: 'nullable' is not a supported annotation for this node. "
"It must be one of: Hide, JavaOnlyStableParcelable, UnsupportedAppUsage, VintfStability, "
- "JavaPassthrough, Immutable\n";
+ "JavaPassthrough, JavaOnlyImmutable\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", method, typenames_, GetLanguage(), &error));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
@@ -348,7 +348,7 @@
const string expected_stderr =
"ERROR: a/Foo.aidl:1.32-36: 'nullable' is not a supported annotation for this node. "
"It must be one of: Hide, UnsupportedAppUsage, VintfStability, JavaPassthrough, JavaDebug, "
- "Immutable\n";
+ "JavaOnlyImmutable\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", method, typenames_, GetLanguage(), &error));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
@@ -2292,42 +2292,43 @@
EXPECT_EQ(AidlError::BAD_TYPE, error);
}
-TEST_P(AidlTest, SupportImmutableAnnotation) {
- io_delegate_.SetFileContents(
- "Foo.aidl",
- "@Immutable parcelable Foo { int a; Bar b; List<Bar> c; Map<String, Baz> d; Bar[] e; }");
- io_delegate_.SetFileContents("Bar.aidl", "@Immutable parcelable Bar { String a; }");
- io_delegate_.SetFileContents("Baz.aidl", "@Immutable @JavaOnlyStableParcelable parcelable Baz;");
+TEST_P(AidlTest, SupportJavaOnlyImmutableAnnotation) {
+ io_delegate_.SetFileContents("Foo.aidl",
+ "@JavaOnlyImmutable parcelable Foo { int a; Bar b; List<Bar> c; "
+ "Map<String, Baz> d; Bar[] e; }");
+ io_delegate_.SetFileContents("Bar.aidl", "@JavaOnlyImmutable parcelable Bar { String a; }");
+ io_delegate_.SetFileContents("Baz.aidl",
+ "@JavaOnlyImmutable @JavaOnlyStableParcelable parcelable Baz;");
Options options = Options::From("aidl --lang=java -I . Foo.aidl");
EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_));
}
-TEST_P(AidlTest, RejectMutableParcelableFromImmutableParcelable) {
- io_delegate_.SetFileContents("Foo.aidl", "@Immutable parcelable Foo { Bar bar; }");
+TEST_P(AidlTest, RejectMutableParcelableFromJavaOnlyImmutableParcelable) {
+ io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { Bar bar; }");
io_delegate_.SetFileContents("Bar.aidl", "parcelable Bar { String a; }");
Options options = Options::From("aidl --lang=java Foo.aidl -I .");
EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_));
}
TEST_P(AidlTest, ImmtuableParcelableCannotBeInOut) {
- io_delegate_.SetFileContents("Foo.aidl", "@Immutable parcelable Foo { int a; }");
+ io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { int a; }");
io_delegate_.SetFileContents("IBar.aidl", "interface IBar { void my(inout Foo); }");
Options options = Options::From("aidl --lang=java IBar.aidl -I .");
EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_));
}
TEST_P(AidlTest, ImmtuableParcelableCannotBeOut) {
- io_delegate_.SetFileContents("Foo.aidl", "@Immutable parcelable Foo { int a; }");
+ io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { int a; }");
io_delegate_.SetFileContents("IBar.aidl", "interface IBar { void my(out Foo); }");
Options options = Options::From("aidl --lang=java IBar.aidl -I .");
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; }");
+ io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable 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 "
+ "ERROR: Foo.aidl:1.30-34: 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_));
diff --git a/generate_java.cpp b/generate_java.cpp
index 3d5259c..dda913b 100644
--- a/generate_java.cpp
+++ b/generate_java.cpp
@@ -122,11 +122,11 @@
}
out << "public ";
- if (variable->GetType().GetName() == "ParcelableHolder" || parcel->IsImmutable()) {
+ if (variable->GetType().GetName() == "ParcelableHolder" || parcel->IsJavaOnlyImmutable()) {
out << "final ";
}
out << JavaSignatureOf(variable->GetType(), typenames) << " " << variable->GetName();
- if (!parcel->IsImmutable() && variable->GetDefaultValue()) {
+ if (!parcel->IsJavaOnlyImmutable() && variable->GetDefaultValue()) {
out << " = " << variable->ValueString(ConstantValueDecorator);
} else if (variable->GetType().GetName() == "ParcelableHolder") {
out << std::boolalpha;
@@ -144,7 +144,7 @@
}
std::ostringstream out;
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
auto builder_class = std::make_shared<Class>();
builder_class->modifiers = PUBLIC | FINAL | STATIC;
builder_class->what = Class::CLASS;
@@ -189,7 +189,7 @@
out << " @Override\n";
out << " public " << parcel->GetName()
<< " createFromParcel(android.os.Parcel _aidl_source) {\n";
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
out << " return internalCreateFromParcel(_aidl_source);\n";
} else {
out << " " << parcel->GetName() << " _aidl_out = new " << parcel->GetName() << "();\n";
@@ -246,7 +246,7 @@
parcel_class->elements.push_back(write_method);
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
auto constructor = std::make_shared<Method>();
constructor->modifiers = PUBLIC;
constructor->name = parcel->GetName();
@@ -274,7 +274,7 @@
// For an immutable parcelable, generate internalCreateFromParcel method.
// Otherwise, generate readFromParcel method.
auto read_or_create_method = std::make_shared<Method>();
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
auto constructor = std::make_shared<Method>();
read_or_create_method->modifiers = PRIVATE | STATIC;
read_or_create_method->returnType = parcel->GetName();
@@ -290,14 +290,14 @@
}
out.str("");
const string builder_variable = "_aidl_parcelable_builder";
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
out << "Builder " << builder_variable << " = new Builder();\n";
}
out << "int _aidl_start_pos = _aidl_parcel.dataPosition();\n"
<< "int _aidl_parcelable_size = _aidl_parcel.readInt();\n"
<< "try {\n"
<< " if (_aidl_parcelable_size < 0) return";
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
out << " " << builder_variable << ".build()";
}
out << ";\n";
@@ -306,7 +306,7 @@
out.str("");
out << " if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return";
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
out << " " << builder_variable << ".build()";
}
out << ";\n";
@@ -317,7 +317,7 @@
bool is_classloader_created = false;
for (const auto& field : parcel->GetFields()) {
const auto field_variable_name =
- (parcel->IsImmutable() ? "_aidl_temp_" : "") + field->GetName();
+ (parcel->IsJavaOnlyImmutable() ? "_aidl_temp_" : "") + field->GetName();
string code;
CodeWriterPtr writer = CodeWriter::ForString(&code);
CodeGeneratorContext context{
@@ -329,12 +329,12 @@
.is_classloader_created = &is_classloader_created,
};
context.writer.Indent();
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
context.writer.Write("%s %s;\n", JavaSignatureOf(field->GetType(), typenames).c_str(),
field_variable_name.c_str());
}
CreateFromParcelFor(context);
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
context.writer.Write("%s.%s(%s);\n", builder_variable.c_str(),
get_setter_name(field->GetName()).c_str(), field_variable_name.c_str());
}
@@ -347,7 +347,7 @@
out.str("");
out << "} finally {\n"
<< " _aidl_parcel.setDataPosition(_aidl_start_pos + _aidl_parcelable_size);\n";
- if (parcel->IsImmutable()) {
+ if (parcel->IsJavaOnlyImmutable()) {
out << " return " << builder_variable << ".build();\n";
}
out << "}\n";
diff --git a/tests/android/aidl/tests/immutable/Bar.aidl b/tests/android/aidl/tests/immutable/Bar.aidl
index 1d509bd..f29af9d 100644
--- a/tests/android/aidl/tests/immutable/Bar.aidl
+++ b/tests/android/aidl/tests/immutable/Bar.aidl
@@ -16,7 +16,7 @@
package android.aidl.tests.immutable;
-@Immutable
+@JavaOnlyImmutable
parcelable Bar {
String s = "bar";
}
\ No newline at end of file
diff --git a/tests/android/aidl/tests/immutable/Foo.aidl b/tests/android/aidl/tests/immutable/Foo.aidl
index a79dd94..c923d8a 100644
--- a/tests/android/aidl/tests/immutable/Foo.aidl
+++ b/tests/android/aidl/tests/immutable/Foo.aidl
@@ -18,7 +18,7 @@
import android.aidl.tests.immutable.Bar;
-@Immutable
+@JavaOnlyImmutable
parcelable Foo {
int a = 10;
Bar b;
diff --git a/tests/java_app/src/android/aidl/tests/ImmutableAnnotationTests.java b/tests/java_app/src/android/aidl/tests/JavaOnlyImmutableAnnotationTests.java
similarity index 97%
rename from tests/java_app/src/android/aidl/tests/ImmutableAnnotationTests.java
rename to tests/java_app/src/android/aidl/tests/JavaOnlyImmutableAnnotationTests.java
index 54784b0..4fd4b90 100644
--- a/tests/java_app/src/android/aidl/tests/ImmutableAnnotationTests.java
+++ b/tests/java_app/src/android/aidl/tests/JavaOnlyImmutableAnnotationTests.java
@@ -36,9 +36,9 @@
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
-public class ImmutableAnnotationTests {
+public class JavaOnlyImmutableAnnotationTests {
@Test
- public void testReadWriteImmutableParcelable() {
+ public void testReadWriteJavaOnlyImmutableParcelable() {
Parcel parcel = Parcel.obtain();
List<Bar> list = new ArrayList<Bar>();
list.add(new Bar("aa"));