Loading tools/aapt2/BinaryResourceParser.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -735,8 +735,7 @@ std::unique_ptr<Value> BinaryResourceParser::parseMapEntry(const ResourceNameRef std::unique_ptr<Style> BinaryResourceParser::parseStyle(const ResourceNameRef& name, const ConfigDescription& config, const ResTable_map_entry* map) { const bool isWeak = (map->flags & ResTable_entry::FLAG_WEAK) != 0; std::unique_ptr<Style> style = util::make_unique<Style>(isWeak); std::unique_ptr<Style> style = util::make_unique<Style>(); if (map->parent.ident == 0) { // The parent is either not set or it is an unresolved symbol. // Check to see if it is a symbol. Loading tools/aapt2/Linker_test.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ TEST_F(LinkerTest, DoNotInterpretEscapedStringAsReference) { } TEST_F(LinkerTest, EscapeAndConvertRawString) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"integer" }, util::make_unique<RawString>(mTable->getValueStringPool().makeRef(u" 123")) Loading @@ -93,7 +93,7 @@ TEST_F(LinkerTest, EscapeAndConvertRawString) { } TEST_F(LinkerTest, FailToConvertRawString) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"integer" }, util::make_unique<RawString>(mTable->getValueStringPool().makeRef(u"yo what is up?")) Loading @@ -105,7 +105,7 @@ TEST_F(LinkerTest, FailToConvertRawString) { } TEST_F(LinkerTest, ConvertRawStringToString) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"string" }, util::make_unique<RawString>( Loading @@ -124,7 +124,7 @@ TEST_F(LinkerTest, ConvertRawStringToString) { } TEST_F(LinkerTest, ConvertRawStringToFlags) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"flags" }, util::make_unique<RawString>(mTable->getValueStringPool().makeRef(u"banana | apple")) Loading tools/aapt2/Main.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -158,7 +158,6 @@ void versionStylesForCompat(const std::shared_ptr<ResourceTable>& table) { }; Style& newStyle = static_cast<Style&>(*value.value); newStyle.weak = true; // Move the recorded stripped attributes into this new style. std::move(stripped.begin(), stripped.end(), Loading tools/aapt2/ResourceParser.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -1163,7 +1163,7 @@ bool ResourceParser::parseUntypedItem(XmlPullParser* parser, Style& style) { 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"); Loading @@ -1181,6 +1181,16 @@ bool ResourceParser::parseStyle(XmlPullParser* parser, const ResourceNameRef& re // 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; Loading tools/aapt2/ResourceParser_test.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -355,6 +355,28 @@ TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedItems) { style->entries[0].key.name); } TEST_F(ResourceParserTest, ParseStyleWithInferredParent) { std::string input = "<style name=\"foo.bar\"/>"; ASSERT_TRUE(testParse(input)); const Style* style = findResource<Style>(ResourceName{ u"android", ResourceType::kStyle, u"foo.bar" }); ASSERT_NE(style, nullptr); EXPECT_EQ(style->parent.name, (ResourceName{ u"android", ResourceType::kStyle, u"foo" })); EXPECT_TRUE(style->parentInferred); } TEST_F(ResourceParserTest, ParseStyleWithInferredParentOverridenByEmptyParentAttribute) { std::string input = "<style name=\"foo.bar\" parent=\"\"/>"; ASSERT_TRUE(testParse(input)); const Style* style = findResource<Style>(ResourceName{ u"android", ResourceType::kStyle, u"foo.bar" }); ASSERT_NE(style, nullptr); EXPECT_FALSE(style->parent.name.isValid()); EXPECT_FALSE(style->parentInferred); } TEST_F(ResourceParserTest, ParseAutoGeneratedIdReference) { std::string input = "<string name=\"foo\">@+id/bar</string>"; ASSERT_TRUE(testParse(input)); Loading Loading
tools/aapt2/BinaryResourceParser.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -735,8 +735,7 @@ std::unique_ptr<Value> BinaryResourceParser::parseMapEntry(const ResourceNameRef std::unique_ptr<Style> BinaryResourceParser::parseStyle(const ResourceNameRef& name, const ConfigDescription& config, const ResTable_map_entry* map) { const bool isWeak = (map->flags & ResTable_entry::FLAG_WEAK) != 0; std::unique_ptr<Style> style = util::make_unique<Style>(isWeak); std::unique_ptr<Style> style = util::make_unique<Style>(); if (map->parent.ident == 0) { // The parent is either not set or it is an unresolved symbol. // Check to see if it is a symbol. Loading
tools/aapt2/Linker_test.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ TEST_F(LinkerTest, DoNotInterpretEscapedStringAsReference) { } TEST_F(LinkerTest, EscapeAndConvertRawString) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"integer" }, util::make_unique<RawString>(mTable->getValueStringPool().makeRef(u" 123")) Loading @@ -93,7 +93,7 @@ TEST_F(LinkerTest, EscapeAndConvertRawString) { } TEST_F(LinkerTest, FailToConvertRawString) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"integer" }, util::make_unique<RawString>(mTable->getValueStringPool().makeRef(u"yo what is up?")) Loading @@ -105,7 +105,7 @@ TEST_F(LinkerTest, FailToConvertRawString) { } TEST_F(LinkerTest, ConvertRawStringToString) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"string" }, util::make_unique<RawString>( Loading @@ -124,7 +124,7 @@ TEST_F(LinkerTest, ConvertRawStringToString) { } TEST_F(LinkerTest, ConvertRawStringToFlags) { std::unique_ptr<Style> style = util::make_unique<Style>(false); std::unique_ptr<Style> style = util::make_unique<Style>(); style->entries.push_back(Style::Entry{ ResourceNameRef{ u"android", ResourceType::kAttr, u"flags" }, util::make_unique<RawString>(mTable->getValueStringPool().makeRef(u"banana | apple")) Loading
tools/aapt2/Main.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -158,7 +158,6 @@ void versionStylesForCompat(const std::shared_ptr<ResourceTable>& table) { }; Style& newStyle = static_cast<Style&>(*value.value); newStyle.weak = true; // Move the recorded stripped attributes into this new style. std::move(stripped.begin(), stripped.end(), Loading
tools/aapt2/ResourceParser.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -1163,7 +1163,7 @@ bool ResourceParser::parseUntypedItem(XmlPullParser* parser, Style& style) { 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"); Loading @@ -1181,6 +1181,16 @@ bool ResourceParser::parseStyle(XmlPullParser* parser, const ResourceNameRef& re // 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; Loading
tools/aapt2/ResourceParser_test.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -355,6 +355,28 @@ TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedItems) { style->entries[0].key.name); } TEST_F(ResourceParserTest, ParseStyleWithInferredParent) { std::string input = "<style name=\"foo.bar\"/>"; ASSERT_TRUE(testParse(input)); const Style* style = findResource<Style>(ResourceName{ u"android", ResourceType::kStyle, u"foo.bar" }); ASSERT_NE(style, nullptr); EXPECT_EQ(style->parent.name, (ResourceName{ u"android", ResourceType::kStyle, u"foo" })); EXPECT_TRUE(style->parentInferred); } TEST_F(ResourceParserTest, ParseStyleWithInferredParentOverridenByEmptyParentAttribute) { std::string input = "<style name=\"foo.bar\" parent=\"\"/>"; ASSERT_TRUE(testParse(input)); const Style* style = findResource<Style>(ResourceName{ u"android", ResourceType::kStyle, u"foo.bar" }); ASSERT_NE(style, nullptr); EXPECT_FALSE(style->parent.name.isValid()); EXPECT_FALSE(style->parentInferred); } TEST_F(ResourceParserTest, ParseAutoGeneratedIdReference) { std::string input = "<string name=\"foo\">@+id/bar</string>"; ASSERT_TRUE(testParse(input)); Loading