diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2018-04-19 14:58:17 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-04-19 14:58:17 -0700 |
commit | e9bbefa7dc44a666c0cba72fdbd7825cc1f89dac (patch) | |
tree | fdf1adbbcde7034e88ef5b4c28559ec77114e44f /tools/aapt2/ResourceParser.cpp | |
parent | 52489dbf6677e8eb1fd76c6ef428a154d61b68f2 (diff) | |
parent | 247ecfa4989c4a2a1096a9960831286cca7eaab5 (diff) |
Merge "AAPT2: Support id reference chaining from AAPT" into pi-dev
am: 247ecfa498
Change-Id: I507b421d60294ea9262d5be579f22fdc2892c7fe
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; } |