Support nested types in the Java backend

Bug: 201730046
Test: aidl_integration_test
Change-Id: I694049bda461a072933d15cc784ea3b16f1bf5bc
diff --git a/generate_java_binder.cpp b/generate_java_binder.cpp
index 48dd10e..9b0fad1 100644
--- a/generate_java_binder.cpp
+++ b/generate_java_binder.cpp
@@ -1250,6 +1250,15 @@
     GenerateMethods(*iface, *item, interface.get(), stub, proxy, item->GetId(), typenames, options);
   }
 
+  // all the nested types
+  for (const auto& nested : iface->GetNestedTypes()) {
+    string code;
+    auto writer = CodeWriter::ForString(&code);
+    GenerateClass(*writer, *nested, typenames, options);
+    writer->Close();
+    interface->elements.push_back(std::make_shared<LiteralClassElement>(code));
+  }
+
   // additional static methods for the default impl set/get to the
   // stub class. Can't add them to the interface as the generated java files
   // may be compiled with Java < 1.7 where static interface method isn't