diff options
author | y <rtmitchell@google.com> | 2018-04-18 11:29:09 -0700 |
---|---|---|
committer | y <rtmitchell@google.com> | 2018-04-18 11:46:53 -0700 |
commit | 9efbbef2e060cd5e05f5b652ba5c7aaf687f64d6 (patch) | |
tree | a906595eedebc28b14a4e86e135b225eb1d5d79b /tools/aapt2/ResourceParser.cpp | |
parent | 34a0b18a5c730e4fa16e27c63ed0cd79a6df188e (diff) |
AAPT2: Support id reference chaining from AAPT
AAPT would allow for ids to be declared in the form:
<item name="name" type="id>@id/other</item>
@id/name should hold a reference to @id/other. When
getResources().getValue() is called on R.id.name with resolveRefs
enabled, the resuling reference should be R.id.other.
Bug: 69445910
Test: Created tests for correct parsing of id references and correct
resolving of deep references
Change-Id: Id1feb37b2565c213dc6a19b4c401906260d7fc14
Diffstat (limited to 'tools/aapt2/ResourceParser.cpp')
-rw-r--r-- | tools/aapt2/ResourceParser.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index 1b6f8827291b..19c6c3107e7c 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -586,7 +586,29 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser, out_resource->name.type = ResourceType::kId; out_resource->name.entry = maybe_name.value().to_string(); - out_resource->value = util::make_unique<Id>(); + + // Ids either represent a unique resource id or reference another resource id + auto item = ParseItem(parser, out_resource, resource_format); + if (!item) { + return false; + } + + String* empty = ValueCast<String>(out_resource->value.get()); + if (empty && *empty->value == "") { + // If no inner element exists, represent a unique identifier + out_resource->value = util::make_unique<Id>(); + } else { + // If an inner element exists, the inner element must be a reference to + // another resource id + Reference* ref = ValueCast<Reference>(out_resource->value.get()); + if (!ref || ref->name.value().type != ResourceType::kId) { + diag_->Error(DiagMessage(out_resource->source) + << "<" << parser->element_name() + << "> inner element must either be a resource reference or empty"); + return false; + } + } + return true; } |