AAPT2: Add support for comments in R.java

Change-Id: Iaa5f3b75bf7de9dbf458fa5c452f7312989f4c4f
This commit is contained in:
Adam Lesinski
2015-10-30 16:31:42 -07:00
parent 104e028c3a
commit 3b4cd94034
9 changed files with 249 additions and 52 deletions

View File

@@ -21,16 +21,10 @@
namespace aapt {
void AnnotationProcessor::appendCommentLine(const StringPiece16& line) {
void AnnotationProcessor::appendCommentLine(const std::string& comment) {
static const std::string sDeprecated = "@deprecated";
static const std::string sSystemApi = "@SystemApi";
if (line.empty()) {
return;
}
std::string comment = util::utf16ToUtf8(line);
if (comment.find(sDeprecated) != std::string::npos && !mDeprecated) {
mDeprecated = true;
if (!mAnnotations.empty()) {
@@ -63,14 +57,28 @@ void AnnotationProcessor::appendCommentLine(const StringPiece16& line) {
void AnnotationProcessor::appendComment(const StringPiece16& comment) {
// We need to process line by line to clean-up whitespace and append prefixes.
for (StringPiece16 line : util::tokenize(comment, u'\n')) {
appendCommentLine(util::trimWhitespace(line));
line = util::trimWhitespace(line);
if (!line.empty()) {
appendCommentLine(util::utf16ToUtf8(line));
}
}
}
void AnnotationProcessor::appendComment(const StringPiece& comment) {
for (StringPiece line : util::tokenize(comment, '\n')) {
line = util::trimWhitespace(line);
if (!line.empty()) {
appendCommentLine(line.toString());
}
}
}
std::string AnnotationProcessor::buildComment() {
mComment += "\n";
mComment += mPrefix;
mComment += " */";
if (!mComment.empty()) {
mComment += "\n";
mComment += mPrefix;
mComment += " */";
}
return std::move(mComment);
}