Preprocessed uses the same syntax of AIDL
Preprocessed file has been using a similar but different syntax. Now,
it is using the same syntax with AIDL files with a couple of small
changes.
- Type decl can have qualified name.
(interestinly, I only changed this for interface/enum)
- Interface can omit body(members) blocks.
interface IFoo; // is simply an empty interface
Bug: 25479378
Test: aidl_unittests
Test: m
Change-Id: Icf5e4c321c469af00506c5ff14782251018d9d57
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 5bff95e..8f0c255 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -900,11 +900,20 @@
AidlDefinedType::AidlDefinedType(const AidlLocation& location, const std::string& name,
const Comments& comments, const std::string& package,
std::vector<std::unique_ptr<AidlMember>>* members)
- : AidlAnnotatable(location, comments),
- name_(name),
- package_(package),
- split_package_(package.empty() ? std::vector<std::string>()
- : android::base::Split(package, ".")) {
+ : AidlAnnotatable(location, comments), name_(name), package_(package) {
+ // adjust name/package when name is fully qualified (for preprocessed files)
+ if (package_.empty() && name_.find('.') != std::string::npos) {
+ // Note that this logic is absolutely wrong. Given a parcelable
+ // org.some.Foo.Bar, the class name is Foo.Bar, but this code will claim that
+ // the class is just Bar. However, this was the way it was done in the past.
+ //
+ // See b/17415692
+ auto pos = name.rfind('.');
+ // name is the last part.
+ name_ = name.substr(pos + 1);
+ // package is the initial parts (except the last).
+ package_ = name.substr(0, pos);
+ }
if (members) {
for (auto& m : *members) {
if (auto constant = m->AsConstantDeclaration(); constant) {