aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2017-02-22 10:49:07 -0800
committerYifan Hong <elsk@google.com>2017-02-24 10:16:12 -0800
commite45b5303e072043679483a70606f6c00dde17382 (patch)
tree8f3b2e7e30df64c78ca2c2657716c9908787aad1 /utils
parent870d1a7ccd70bd710128993de401278614d1975e (diff)
downloadhidl-e45b5303e072043679483a70606f6c00dde17382.tar.gz
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
Diffstat (limited to 'utils')
-rw-r--r--utils/Formatter.cpp10
-rw-r--r--utils/include/hidl-util/Formatter.h9
2 files changed, 19 insertions, 0 deletions
diff --git a/utils/Formatter.cpp b/utils/Formatter.cpp
index df3a5a43..4d3771bf 100644
--- a/utils/Formatter.cpp
+++ b/utils/Formatter.cpp
@@ -86,6 +86,16 @@ Formatter &Formatter::sElse(std::function<void(void)> block) {
return this->block(block);
}
+Formatter &Formatter::sTry(std::function<void(void)> block) {
+ (*this) << "try ";
+ return this->block(block);
+}
+
+Formatter &Formatter::sCatch(const std::string &exception, std::function<void(void)> block) {
+ (*this) << " catch (" << exception << ") ";
+ return this->block(block);
+}
+
Formatter &Formatter::operator<<(const std::string &out) {
const size_t len = out.length();
size_t start = 0;
diff --git a/utils/include/hidl-util/Formatter.h b/utils/include/hidl-util/Formatter.h
index 7a272873..d1f76fb1 100644
--- a/utils/include/hidl-util/Formatter.h
+++ b/utils/include/hidl-util/Formatter.h
@@ -79,6 +79,15 @@ struct Formatter {
Formatter &sElseIf(const std::string &cond, std::function<void(void)> block);
Formatter &sElse(std::function<void(void)> block);
+ // out.sTry([&] {
+ // out << "throw RemoteException();\n"
+ // }).sCatch("RemoteException ex", [&] {
+ // out << "ex.printStackTrace();\n"
+ // }).endl();
+ // note that there will be a space before the "catch"-s.
+ Formatter &sTry(std::function<void(void)> block);
+ Formatter &sCatch(const std::string &exception, std::function<void(void)> block);
+
Formatter &operator<<(const std::string &out);
Formatter &operator<<(size_t n);