summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-04-19 15:20:51 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-04-19 15:20:51 -0700
commit027453d6fb3581cee81f6b3c49c3ec653c0a82f7 (patch)
tree9f08a8f8e1daca18c2a31d80296f4ceadc560e63 /tools/aapt2/ResourceParser.cpp
parentee3558584b66b001c8ca1258225bbb5dea33f7b7 (diff)
parente9bbefa7dc44a666c0cba72fdbd7825cc1f89dac (diff)
Merge "AAPT2: Support id reference chaining from AAPT" into pi-dev am: 247ecfa498
am: e9bbefa7dc Change-Id: Ic40b9e08352e561e21284d72592860b868f6edc1
Diffstat (limited to 'tools/aapt2/ResourceParser.cpp')
-rw-r--r--tools/aapt2/ResourceParser.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index 2260ba4f120f..0271d8bad37a 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -589,7 +589,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;
}