Add toString to Java code
* toString is mainly for debugging purposes.
* For structs and interfaces, add Object.toString.
* For enums, add MyEnum.toString(int) and MyEnum.dumpBitfield(int).
Use them as follows:
* For enums, use the static method E.toString(int).
* For bitfields, use the static method E.dumpBitfield(int).
* For all arrays, use java.utils.Arrays.deepToString(o)
* For everything else, use one of the following:
* o.toString(), if o is not null
* Object.toString(o)
* String.valueOf(o)
* Note that for array / vec of enums / bitfields, the raw integer
value is dumped.
Bug: 33459772
Test: hidl_test_java
Change-Id: Ifb1ed519770b907e0a4e345b2c3109dc322a23b2
diff --git a/generateJava.cpp b/generateJava.cpp
index 56ac2d6..3e8d493 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -303,6 +303,18 @@
out.unindent();
out << "}\n\n";
+
+ out << "@Override\npublic String toString() ";
+ out.block([&] {
+ out.sTry([&] {
+ out << "return this.interfaceDescriptor() + \"@Proxy\";\n";
+ }).sCatch("RemoteException ex", [&] {
+ out << "/* ignored; handled below. */\n";
+ }).endl();
+ out << "return \"[class or subclass of \" + "
+ << ifaceName << ".kInterfaceName + \"]@Proxy\";\n";
+ }).endl().endl();
+
const Interface *prevInterface = nullptr;
for (const auto &tuple : iface->allMethodsFromRoot()) {
const Method *method = tuple.method();
@@ -488,6 +500,11 @@
out.unindent();
out << "}\n\n";
+ out << "@Override\npublic String toString() ";
+ out.block([&] {
+ out << "return this.interfaceDescriptor() + \"@Stub\";\n";
+ }).endl().endl();
+
out << "@Override\n"
<< "public void onTransact("
<< "int _hidl_code, "