diff options
author | Ningyuan Wang <nywang@google.com> | 2016-09-30 19:10:29 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-30 19:10:29 +0000 |
commit | 6f7e926b5daaafacbca2fa6e65c95304b29f115a (patch) | |
tree | ed235388e3c083b28f1f95715524acc549321f9d | |
parent | 84d0919ccf79d4747dce9af684407bb8603d8220 (diff) | |
parent | 7bc7be846b6ed785350096405ad8210b264f74e8 (diff) | |
download | aidl-6f7e926b5daaafacbca2fa6e65c95304b29f115a.tar.gz |
Fix nested parcelable class name am: d17c58babb am: e667674402
am: 7bc7be846b
Change-Id: I562f2f768ac4bda00ddf1d363b2dc5e7463fa0de
-rw-r--r-- | aidl_language.h | 3 | ||||
-rw-r--r-- | aidl_unittest.cpp | 17 | ||||
-rw-r--r-- | type_cpp.cpp | 4 | ||||
-rw-r--r-- | type_cpp_unittest.cpp | 19 |
4 files changed, 41 insertions, 2 deletions
diff --git a/aidl_language.h b/aidl_language.h index e27cd107..7982e761 100644 --- a/aidl_language.h +++ b/aidl_language.h @@ -278,6 +278,7 @@ class AidlQualifiedName : public AidlNode { const std::vector<std::string>& GetTerms() const { return terms_; } const std::string& GetComments() const { return comments_; } std::string GetDotName() const { return android::base::Join(terms_, '.'); } + std::string GetColonName() const { return android::base::Join(terms_, "::"); } void AddTerm(const std::string& term); @@ -296,6 +297,8 @@ class AidlParcelable : public AidlNode { virtual ~AidlParcelable() = default; std::string GetName() const { return name_->GetDotName(); } + // C++ uses "::" instead of "." to refer to a inner class. + std::string GetCppName() const { return name_->GetColonName(); } unsigned GetLine() const { return line_; } std::string GetPackage() const; const std::vector<std::string>& GetSplitPackage() const { return package_; } diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp index 0d2ba536..22ad1bd8 100644 --- a/aidl_unittest.cpp +++ b/aidl_unittest.cpp @@ -332,6 +332,23 @@ TEST_F(AidlTest, ParseNegativeConstHexValue) { EXPECT_EQ(-1, cpp_int_constants[0]->GetValue()); } +TEST_F(AidlTest, UnderstandsNestedParcelables) { + io_delegate_.SetFileContents( + "p/Outer.aidl", + "package p; parcelable Outer.Inner cpp_header \"baz/header\";"); + import_paths_.push_back(""); + const string input_path = "p/IFoo.aidl"; + const string input = "package p; import p.Outer; interface IFoo" + " { Outer.Inner get(); }"; + + auto cpp_parse_result = Parse(input_path, input, &cpp_types_); + EXPECT_NE(nullptr, cpp_parse_result); + auto cpp_type = cpp_types_.FindTypeByCanonicalName("p.Outer.Inner"); + ASSERT_NE(nullptr, cpp_type); + // C++ uses "::" instead of "." to refer to a inner class. + EXPECT_EQ("::p::Outer::Inner", cpp_type->CppType()); +} + TEST_F(AidlTest, UnderstandsNativeParcelables) { io_delegate_.SetFileContents( "p/Bar.aidl", diff --git a/type_cpp.cpp b/type_cpp.cpp index 2c0552d2..e20f6034 100644 --- a/type_cpp.cpp +++ b/type_cpp.cpp @@ -235,7 +235,7 @@ class NullableParcelableType : public Type { private: static string GetCppName(const AidlParcelable& parcelable) { return "::std::unique_ptr<::" + Join(parcelable.GetSplitPackage(), "::") + - "::" + parcelable.GetName() + ">"; + "::" + parcelable.GetCppName() + ">"; } }; @@ -261,7 +261,7 @@ class ParcelableType : public Type { private: static string GetCppName(const AidlParcelable& parcelable) { return "::" + Join(parcelable.GetSplitPackage(), "::") + - "::" + parcelable.GetName(); + "::" + parcelable.GetCppName(); } }; diff --git a/type_cpp_unittest.cpp b/type_cpp_unittest.cpp index 35fc3d5a..46b5db84 100644 --- a/type_cpp_unittest.cpp +++ b/type_cpp_unittest.cpp @@ -15,15 +15,26 @@ */ #include <memory> +#include <string> #include <gtest/gtest.h> #include "type_cpp.h" +using std::string; +using std::unique_ptr; + namespace android { namespace aidl { namespace cpp { +namespace { + +string kParcelableDotName = "Outer.Inner"; +string kParcelableColonName = "Outer::Inner"; + +} // namespace + class CppTypeNamespaceTest : public ::testing::Test { protected: void SetUp() override { @@ -48,6 +59,14 @@ TEST_F(CppTypeNamespaceTest, SupportsListString) { types_.HasTypeByCanonicalName("java.util.List<java.lang.String>")); } +TEST_F(CppTypeNamespaceTest, SupportsNestedParcelableClass) { + unique_ptr<AidlParcelable> parcelable( + new AidlParcelable(new AidlQualifiedName(kParcelableDotName, ""), + 0, + {"a", "goog"})); + EXPECT_EQ(parcelable->GetCppName(), kParcelableColonName); +} + } // namespace cpp } // namespace android } // namespace aidl |