AAPT2: inferred style parent processing
Change-Id: I8fbc4feef16b6039cf4c526fcfb767dc75a9c131
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index e7e824c..59915a2 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -1163,7 +1163,7 @@
bool ResourceParser::parseStyle(XmlPullParser* parser, const ResourceNameRef& resourceName) {
const SourceLine source = mSource.line(parser->getLineNumber());
- std::unique_ptr<Style> style = util::make_unique<Style>(false);
+ std::unique_ptr<Style> style = util::make_unique<Style>();
const auto endAttrIter = parser->endAttributes();
const auto parentAttrIter = parser->findAttribute(u"", u"parent");
@@ -1181,6 +1181,16 @@
// If no package is specified, this can not be an alias and is the local package.
style->parent.name.package = mTable->getPackage();
}
+ } else {
+ // No parent was specified, so try inferring it from the style name.
+ std::u16string styleName = resourceName.entry.toString();
+ size_t pos = styleName.find_last_of(u'.');
+ if (pos != std::string::npos) {
+ style->parentInferred = true;
+ style->parent.name.package = mTable->getPackage();
+ style->parent.name.type = ResourceType::kStyle;
+ style->parent.name.entry = styleName.substr(0, pos);
+ }
}
bool success = true;