diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-04-24 19:19:30 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-05-04 16:43:24 -0700 |
commit | 24aad163bc88cb10d2275385e9afc3de7f342d65 (patch) | |
tree | 361fc0b3fbef5f68a16f357ae9d2bed5e93efbf5 /tools/aapt2/Linker.cpp | |
parent | ab2581398c812917145088590bd18eb83f3a2ea6 (diff) | |
download | frameworks_base-24aad163bc88cb10d2275385e9afc3de7f342d65.zip frameworks_base-24aad163bc88cb10d2275385e9afc3de7f342d65.tar.gz frameworks_base-24aad163bc88cb10d2275385e9afc3de7f342d65.tar.bz2 |
Add namespace handling in attribute values
Previously, you could only reference namespace prefixes in attribute names:
<View xmlns:appcompat="http://schemas.android.com/apk/res/android.support.v7.appcompat"
appcompat:name="hey"
...
Now you can also reference them in resource names within an attribute value:
...
android:text="@appcompat:string/confirm"
...
Which will be treated as "@android.support.v7.appcompat:string/confirm".
Change-Id: Ib076e867a990c80cf877a704eb77cd1ef0b23b52
Diffstat (limited to 'tools/aapt2/Linker.cpp')
-rw-r--r-- | tools/aapt2/Linker.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/tools/aapt2/Linker.cpp b/tools/aapt2/Linker.cpp index 4346c8b..42ea0f1 100644 --- a/tools/aapt2/Linker.cpp +++ b/tools/aapt2/Linker.cpp @@ -16,6 +16,8 @@ #include "Linker.h" #include "Logger.h" +#include "NameMangler.h" +#include "Resolver.h" #include "ResourceParser.h" #include "ResourceTable.h" #include "ResourceValues.h" @@ -38,7 +40,7 @@ namespace aapt { Linker::Args::Args(const ResourceNameRef& r, const SourceLine& s) : referrer(r), source(s) { } -Linker::Linker(std::shared_ptr<ResourceTable> table, std::shared_ptr<Resolver> resolver) : +Linker::Linker(std::shared_ptr<ResourceTable> table, std::shared_ptr<IResolver> resolver) : mTable(table), mResolver(resolver), mError(false) { } @@ -100,11 +102,15 @@ bool Linker::linkAndValidate() { } entry->entryId = nextIndex++; + std::u16string unmangledPackage = mTable->getPackage(); + std::u16string unmangledName = entry->name; + NameMangler::unmangle(&unmangledName, &unmangledPackage); + // Update callers of this resource with the right ID. auto callersIter = mGraph.find(ResourceNameRef{ - mTable->getPackage(), + unmangledPackage, type->type, - entry->name + unmangledName }); if (callersIter != std::end(mGraph)) { @@ -175,13 +181,14 @@ void Linker::processAttributeValue(const ResourceNameRef& name, const SourceLine // we called through the original value. auto onCreateReference = [&](const ResourceName& name) { - mTable->addResource(name, ConfigDescription{}, - source, util::make_unique<Id>()); + // We should never get here. All references would have been + // parsed in the parser phase. + assert(false); + //mTable->addResource(name, ConfigDescription{}, source, util::make_unique<Id>()); }; - convertedValue = ResourceParser::parseItemForAttribute( - *str.value, attr, mResolver->getDefaultPackage(), - onCreateReference); + convertedValue = ResourceParser::parseItemForAttribute(*str.value, attr, + onCreateReference); if (!convertedValue && attr.typeMask & android::ResTable_map::TYPE_STRING) { // Last effort is to parse as a string. util::StringBuilder builder; @@ -225,13 +232,13 @@ void Linker::visit(Style& style, ValueVisitorArgs& a) { } for (Style::Entry& styleEntry : style.entries) { - Maybe<Resolver::Entry> result = mResolver->findAttribute(styleEntry.key.name); + Maybe<IResolver::Entry> result = mResolver->findAttribute(styleEntry.key.name); if (!result || !result.value().attr) { addUnresolvedSymbol(styleEntry.key.name, args.source); continue; } - const Resolver::Entry& entry = result.value(); + const IResolver::Entry& entry = result.value(); if (entry.id.isValid()) { styleEntry.key.id = entry.id; } else { |