remove dependency with ast_java and JavaTypeNamespace: Method

ast_java doesn't need to know about Type in JavaTypeNamespace.

This commit removes Type in Method

remove dependency with generate_java_parcel and JavaTypeNamespace

Bug: 110967839
Test: ./runtests.sh
Test: m -j
Change-Id: I8b6c6a76df5789cac9d8b5fc84d5c11cdf27b2b8
diff --git a/ast_java.cpp b/ast_java.cpp
index c695d83..0be172c 100644
--- a/ast_java.cpp
+++ b/ast_java.cpp
@@ -371,12 +371,12 @@
   WriteModifiers(to, this->modifiers,
                  SCOPE_MASK | STATIC | ABSTRACT | FINAL | OVERRIDE);
 
-  if (this->returnType != nullptr) {
+  if (this->returnType) {
     string dim;
     for (i = 0; i < this->returnTypeDimension; i++) {
       dim += "[]";
     }
-    to->Write("%s%s ", this->returnType->JavaType().c_str(), dim.c_str());
+    to->Write("%s%s ", this->returnType->c_str(), dim.c_str());
   }
 
   to->Write("%s(", this->name.c_str());
@@ -398,7 +398,7 @@
     } else {
       to->Write(", ");
     }
-    to->Write("%s", this->exceptions[i]->JavaType().c_str());
+    to->Write("%s", this->exceptions[i].c_str());
   }
 
   if (this->statements == nullptr) {
diff --git a/ast_java.h b/ast_java.h
index 8bb55f9..1a65d85 100644
--- a/ast_java.h
+++ b/ast_java.h
@@ -302,11 +302,11 @@
   std::string comment;
   std::vector<std::string> annotations;
   int modifiers = 0;
-  const Type* returnType = nullptr;  // nullptr means constructor
+  std::optional<std::string> returnType = std::nullopt;  // nullopt means constructor
   size_t returnTypeDimension = 0;
   std::string name;
   std::vector<Variable*> parameters;
-  std::vector<const Type*> exceptions;
+  std::vector<std::string> exceptions;
   StatementBlock* statements = nullptr;
 
   Method() = default;
diff --git a/generate_java.cpp b/generate_java.cpp
index 0204f03..a663d3a 100644
--- a/generate_java.cpp
+++ b/generate_java.cpp
@@ -51,9 +51,9 @@
 }
 
 bool generate_java_parcel(const std::string& filename, const std::string& original_src,
-                          const AidlStructuredParcelable* parcel, JavaTypeNamespace* types,
-                          const IoDelegate& io_delegate, const Options& options) {
-  Class* cl = generate_parcel_class(parcel, types, options);
+                          const AidlStructuredParcelable* parcel, AidlTypenames& typenames,
+                          const IoDelegate& io_delegate) {
+  Class* cl = generate_parcel_class(parcel, typenames);
 
   Document* document =
       new Document("" /* no comment */, parcel->GetPackage(), original_src, unique_ptr<Class>(cl));
@@ -77,7 +77,7 @@
                    const IoDelegate& io_delegate, const Options& options) {
   const AidlStructuredParcelable* parcelable = defined_type->AsStructuredParcelable();
   if (parcelable != nullptr) {
-    return generate_java_parcel(filename, original_src, parcelable, types, io_delegate, options);
+    return generate_java_parcel(filename, original_src, parcelable, types->typenames_, io_delegate);
   }
 
   const AidlParcelable* parcelable_decl = defined_type->AsParcelable();
@@ -95,8 +95,7 @@
 }
 
 android::aidl::java::Class* generate_parcel_class(const AidlStructuredParcelable* parcel,
-                                                  java::JavaTypeNamespace* types,
-                                                  const Options& /*options*/) {
+                                                  AidlTypenames& typenames) {
   Class* parcel_class = new Class;
   parcel_class->comment = parcel->GetComments();
   parcel_class->modifiers = PUBLIC;
@@ -144,7 +143,7 @@
 
   Method* write_method = new Method;
   write_method->modifiers = PUBLIC | OVERRIDE | FINAL;
-  write_method->returnType = new Type(types, "void", 0, false);
+  write_method->returnType = "void";
   write_method->name = "writeToParcel";
   write_method->parameters.push_back(parcel_variable);
   write_method->parameters.push_back(flag_variable);
@@ -160,7 +159,7 @@
     CodeWriterPtr writer = CodeWriter::ForString(&code);
     CodeGeneratorContext context{
         .writer = *(writer.get()),
-        .typenames = types->typenames_,
+        .typenames = typenames,
         .type = field->GetType(),
         .var = field->GetName(),
         .parcel = parcel_variable->name,
@@ -183,7 +182,7 @@
 
   Method* read_method = new Method;
   read_method->modifiers = PUBLIC | FINAL;
-  read_method->returnType = new Type(types, "void", 0, false);
+  read_method->returnType = "void";
   read_method->name = "readFromParcel";
   read_method->parameters.push_back(parcel_variable);
   read_method->statements = new StatementBlock();
@@ -208,7 +207,7 @@
     CodeWriterPtr writer = CodeWriter::ForString(&code);
     CodeGeneratorContext context{
         .writer = *(writer.get()),
-        .typenames = types->typenames_,
+        .typenames = typenames,
         .type = field->GetType(),
         .var = field->GetName(),
         .parcel = parcel_variable->name,
@@ -233,7 +232,7 @@
 
   Method* describe_contents_method = new Method;
   describe_contents_method->modifiers = PUBLIC | OVERRIDE;
-  describe_contents_method->returnType = types->IntType();
+  describe_contents_method->returnType = "int";
   describe_contents_method->name = "describeContents";
   describe_contents_method->statements = new StatementBlock();
   describe_contents_method->statements->Add(new LiteralStatement("return 0;\n"));
diff --git a/generate_java.h b/generate_java.h
index 7408ee7..4f0b590 100644
--- a/generate_java.h
+++ b/generate_java.h
@@ -37,8 +37,7 @@
                                                             const Options& options);
 
 android::aidl::java::Class* generate_parcel_class(const AidlStructuredParcelable* parcel,
-                                                  java::JavaTypeNamespace* types,
-                                                  const Options& options);
+                                                  AidlTypenames& typenames);
 
 std::vector<std::string> generate_java_annotations(const AidlAnnotatable& a);
 
diff --git a/generate_java_binder.cpp b/generate_java_binder.cpp
index 4f06c6f..c3b41e8 100644
--- a/generate_java_binder.cpp
+++ b/generate_java_binder.cpp
@@ -145,7 +145,7 @@
   // asBinder
   Method* asBinder = new Method;
   asBinder->modifiers = PUBLIC | OVERRIDE;
-  asBinder->returnType = types->IBinderType();
+  asBinder->returnType = types->IBinderType()->JavaType();
   asBinder->name = "asBinder";
   asBinder->statements = new StatementBlock;
   asBinder->statements->Add(new ReturnStatement(THIS_VALUE));
@@ -155,7 +155,7 @@
     // getDefaultTransactionName
     Method* getDefaultTransactionName = new Method;
     getDefaultTransactionName->modifiers = PUBLIC | STATIC;
-    getDefaultTransactionName->returnType = types->StringType();
+    getDefaultTransactionName->returnType = types->StringType()->JavaType();
     getDefaultTransactionName->name = "getDefaultTransactionName";
     Variable* code = new Variable(types->IntType()->JavaType(), "transactionCode");
     getDefaultTransactionName->parameters.push_back(code);
@@ -167,7 +167,7 @@
     // getTransactionName
     Method* getTransactionName = new Method;
     getTransactionName->modifiers = PUBLIC;
-    getTransactionName->returnType = types->StringType();
+    getTransactionName->returnType = types->StringType()->JavaType();
     getTransactionName->name = "getTransactionName";
     Variable* code2 = new Variable(types->IntType()->JavaType(), "transactionCode");
     getTransactionName->parameters.push_back(code2);
@@ -184,7 +184,7 @@
   this->transact_flags = new Variable(types->IntType()->JavaType(), "flags");
   Method* onTransact = new Method;
   onTransact->modifiers = PUBLIC | OVERRIDE;
-  onTransact->returnType = types->BoolType();
+  onTransact->returnType = types->BoolType()->JavaType();
   onTransact->name = "onTransact";
   onTransact->parameters.push_back(this->transact_code);
   onTransact->parameters.push_back(this->transact_data);
@@ -192,7 +192,7 @@
   onTransact->parameters.push_back(this->transact_flags);
   onTransact->statements = new StatementBlock;
   transact_statements = onTransact->statements;
-  onTransact->exceptions.push_back(types->RemoteExceptionType());
+  onTransact->exceptions.push_back(types->RemoteExceptionType()->JavaType());
   this->elements.push_back(onTransact);
   this->transact_switch = new SwitchStatement(this->transact_code);
 }
@@ -260,7 +260,7 @@
   m->comment += " interface,\n";
   m->comment += " * generating a proxy if needed.\n */";
   m->modifiers = PUBLIC | STATIC;
-  m->returnType = interfaceType;
+  m->returnType = interfaceType->JavaType();
   m->name = "asInterface";
   m->parameters.push_back(obj);
   m->statements = new StatementBlock;
@@ -344,7 +344,7 @@
   // IBinder asBinder()
   Method* asBinder = new Method;
   asBinder->modifiers = PUBLIC | OVERRIDE;
-  asBinder->returnType = types->IBinderType();
+  asBinder->returnType = types->IBinderType()->JavaType();
   asBinder->name = "asBinder";
   asBinder->statements = new StatementBlock;
   asBinder->statements->Add(new ReturnStatement(mRemote));
@@ -403,7 +403,7 @@
   std::unique_ptr<Method> decl(new Method);
   decl->comment = method.GetComments();
   decl->modifiers = PUBLIC;
-  decl->returnType = method.GetType().GetLanguageType<Type>();
+  decl->returnType = method.GetType().GetLanguageType<Type>()->JavaType();
   decl->returnTypeDimension = method.GetType().IsArray() ? 1 : 0;
   decl->name = method.GetName();
   decl->annotations = generate_java_annotations(method.GetType());
@@ -413,7 +413,7 @@
                                             arg->GetName(), arg->GetType().IsArray() ? 1 : 0));
   }
 
-  decl->exceptions.push_back(types->RemoteExceptionType());
+  decl->exceptions.push_back(types->RemoteExceptionType()->JavaType());
 
   return decl;
 }
@@ -563,12 +563,12 @@
     Variable* transact_reply = new Variable(types->ParcelType()->JavaType(), "reply");
     Method* onTransact_case = new Method;
     onTransact_case->modifiers = PRIVATE;
-    onTransact_case->returnType = types->BoolType();
+    onTransact_case->returnType = types->BoolType()->JavaType();
     onTransact_case->name = outline_name;
     onTransact_case->parameters.push_back(transact_data);
     onTransact_case->parameters.push_back(transact_reply);
     onTransact_case->statements = new StatementBlock;
-    onTransact_case->exceptions.push_back(types->RemoteExceptionType());
+    onTransact_case->exceptions.push_back(types->RemoteExceptionType()->JavaType());
     stubClass->elements.push_back(onTransact_case);
 
     generate_stub_code(iface, method, oneway, transact_data, transact_reply, types,
@@ -596,7 +596,7 @@
   std::unique_ptr<Method> proxy(new Method);
   proxy->comment = method.GetComments();
   proxy->modifiers = PUBLIC | OVERRIDE;
-  proxy->returnType = method.GetType().GetLanguageType<Type>();
+  proxy->returnType = method.GetType().GetLanguageType<Type>()->JavaType();
   proxy->returnTypeDimension = method.GetType().IsArray() ? 1 : 0;
   proxy->name = method.GetName();
   proxy->statements = new StatementBlock;
@@ -604,7 +604,7 @@
     proxy->parameters.push_back(new Variable(arg->GetType().GetLanguageType<Type>()->JavaType(),
                                              arg->GetName(), arg->GetType().IsArray() ? 1 : 0));
   }
-  proxy->exceptions.push_back(types->RemoteExceptionType());
+  proxy->exceptions.push_back(types->RemoteExceptionType()->JavaType());
 
   // the parcels
   Variable* _data = new Variable(types->ParcelType()->JavaType(), "_data");
@@ -620,8 +620,7 @@
   // the return value
   Variable* _result = nullptr;
   if (method.GetType().GetName() != "void") {
-    _result =
-        new Variable(proxy->returnType->JavaType(), "_result", method.GetType().IsArray() ? 1 : 0);
+    _result = new Variable(*proxy->returnType, "_result", method.GetType().IsArray() ? 1 : 0);
     proxy->statements->Add(new VariableDeclaration(_result));
   }
 
@@ -859,7 +858,7 @@
   // and the proxy-side method returning the descriptor directly
   Method* getDesc = new Method;
   getDesc->modifiers = PUBLIC;
-  getDesc->returnType = types->StringType();
+  getDesc->returnType = types->StringType()->JavaType();
   getDesc->returnTypeDimension = 0;
   getDesc->name = "getInterfaceDescriptor";
   getDesc->statements = new StatementBlock;
@@ -910,7 +909,7 @@
   unique_ptr<Method> default_method(new Method);
   default_method->comment = method.GetComments();
   default_method->modifiers = PUBLIC | OVERRIDE;
-  default_method->returnType = method.GetType().GetLanguageType<Type>();
+  default_method->returnType = method.GetType().GetLanguageType<Type>()->JavaType();
   default_method->returnTypeDimension = method.GetType().IsArray() ? 1 : 0;
   default_method->name = method.GetName();
   default_method->statements = new StatementBlock;
@@ -919,8 +918,11 @@
         new Variable(arg->GetType().GetLanguageType<Type>()->JavaType(), arg->GetName(),
                      arg->GetType().IsArray() ? 1 : 0));
   }
-  default_method->exceptions.push_back(
-      method.GetType().GetLanguageType<Type>()->GetTypeNamespace()->RemoteExceptionType());
+  default_method->exceptions.push_back(method.GetType()
+                                           .GetLanguageType<Type>()
+                                           ->GetTypeNamespace()
+                                           ->RemoteExceptionType()
+                                           ->JavaType());
 
   if (method.GetType().GetName() != "void") {
     const string& defaultValue = DefaultJavaValueOf(method.GetType());