AAPT2: Add support for comments in R.java
Change-Id: Iaa5f3b75bf7de9dbf458fa5c452f7312989f4c4f
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.cpp b/tools/aapt2/unflatten/BinaryResourceParser.cpp
index 30c6091..0d17e84 100644
--- a/tools/aapt2/unflatten/BinaryResourceParser.cpp
+++ b/tools/aapt2/unflatten/BinaryResourceParser.cpp
@@ -116,7 +116,7 @@
if (util::deviceToHost32(mSymbolEntries[i].offset) == offset) {
// This offset is a symbol!
const StringPiece16 str = util::getString(
- mSymbolPool, util::deviceToHost32(mSymbolEntries[i].stringIndex));
+ mSymbolPool, util::deviceToHost32(mSymbolEntries[i].name.index));
StringPiece16 typeStr;
ResourceUtils::extractResourceName(str, &outSymbol->package, &typeStr,
@@ -425,8 +425,14 @@
Symbol symbol;
if (mSourcePool.getError() == NO_ERROR) {
symbol.source.path = util::utf16ToUtf8(util::getString(
- mSourcePool, util::deviceToHost32(entry->source.index)));
- symbol.source.line = util::deviceToHost32(entry->sourceLine);
+ mSourcePool, util::deviceToHost32(entry->source.path.index)));
+ symbol.source.line = util::deviceToHost32(entry->source.line);
+ }
+
+ StringPiece16 comment = util::getString(mSourcePool,
+ util::deviceToHost32(entry->source.comment.index));
+ if (!comment.empty()) {
+ symbol.comment = comment.toString();
}
switch (util::deviceToHost16(entry->state)) {
@@ -560,7 +566,7 @@
Source source = mSource;
if (sourceBlock) {
size_t len;
- const char* str = mSourcePool.string8At(util::deviceToHost32(sourceBlock->pathIndex),
+ const char* str = mSourcePool.string8At(util::deviceToHost32(sourceBlock->path.index),
&len);
if (str) {
source.path.assign(str, len);
@@ -568,6 +574,12 @@
source.line = util::deviceToHost32(sourceBlock->line);
}
+ StringPiece16 comment = util::getString(mSourcePool,
+ util::deviceToHost32(sourceBlock->comment.index));
+ if (!comment.empty()) {
+ resourceValue->setComment(comment);
+ }
+
resourceValue->setSource(source);
if (!mTable->addResourceAllowMangled(name, config, std::move(resourceValue),
mContext->getDiagnostics())) {