union: java backend
union is a parcelable which can hold only a single field with a tag.
Example:
union Union {
int n;
String s;
}
In Java, you can instantiate it with
- default constructor: init with first field
- value constructor: Union.n(42) or Union.s("abc")
You can query "tag" before getting the contents from it.
It also supports getter/setter.
Example:
void foo(Union u) {
if (u.getTag() == Union.n) { // query
int n = u.getN(); // getter
...
}
u.setS("abc"); // setter
}
Bug: 150948558
Test: atest aidl_integration_test
Change-Id: I5c2d87e09462c0d3c6617d73fdf0e49c281d551e
diff --git a/generate_java.h b/generate_java.h
index d2c8a6d..3ed2546 100644
--- a/generate_java.h
+++ b/generate_java.h
@@ -40,6 +40,8 @@
void generate_enum(const CodeWriterPtr& code_writer, const AidlEnumDeclaration* enum_decl,
const AidlTypenames& typenames);
+void generate_union(CodeWriter& out, const AidlUnionDecl* decl, const AidlTypenames& typenames);
+
std::vector<std::string> generate_java_annotations(const AidlAnnotatable& a);
} // namespace java