The hidl-gen Java backend now supports structures (NOT unions) and types.hal

files.

Bug: 30575790
Change-Id: I6461235a1c469ce1bdb279bfa3d531113c5788f9
diff --git a/ScalarType.cpp b/ScalarType.cpp
index 7cfacd5..04cb1c3 100644
--- a/ScalarType.cpp
+++ b/ScalarType.cpp
@@ -57,6 +57,25 @@
     return kName[mKind];
 }
 
+std::string ScalarType::getJavaWrapperType() const {
+    static const char *const kName[] = {
+        "Boolean",
+        "Long",
+        "Byte",
+        "Byte",
+        "Short",
+        "Short",
+        "Int",
+        "Int",
+        "Long",
+        "Long",
+        "Float",
+        "Double"
+    };
+
+    return kName[mKind];
+}
+
 std::string ScalarType::getJavaSuffix() const {
     static const char *const kSuffix[] = {
         "Bool",
@@ -143,6 +162,35 @@
     handleError(out, mode);
 }
 
+void ScalarType::emitJavaFieldReaderWriter(
+        Formatter &out,
+        const std::string &blobName,
+        const std::string &fieldName,
+        const std::string &offset,
+        bool isReader) const {
+    if (isReader) {
+        out << fieldName
+            << " = "
+            << blobName
+            << ".get"
+            << getJavaSuffix()
+            << "("
+            << offset
+            << ");\n";
+
+        return;
+    }
+
+    out << blobName
+        << ".put"
+        << getJavaSuffix()
+        << "("
+        << offset
+        << ", "
+        << fieldName
+        << ");\n";
+}
+
 status_t ScalarType::emitVtsTypeDeclarations(Formatter &out) const {
     std::string extra;
     out << "type: TYPE_SCALAR\n"
@@ -152,5 +200,24 @@
     return OK;
 }
 
+void ScalarType::getAlignmentAndSize(size_t *align, size_t *size) const {
+    static const size_t kAlign[] = {
+        1,  // bool, this is NOT standardized!
+        8,  // void *, 64-bit mode
+        1,  // int8_t
+        1,  // uint8_t
+        2,  // int16_t
+        2,  // uint16_t
+        4,  // int32_t
+        4,  // uint32_t
+        8,  // int64_t
+        8,  // uint64_t
+        4,  // float
+        8   // double
+    };
+
+    *align = *size = kAlign[mKind];
+}
+
 }  // namespace android