summaryrefslogtreecommitdiff
path: root/tools/aapt2/java/AnnotationProcessor.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-10-30 16:31:42 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-11-02 11:53:47 -0800
commit3b4cd94034ff3e5567a2ba6da35d640ff61db4b9 (patch)
tree83c604b9a3b0d1b25769a6afd16578fd97e6effe /tools/aapt2/java/AnnotationProcessor.cpp
parent104e028c3a180a4a151160299ad2e1a4185d6c50 (diff)
AAPT2: Add support for comments in R.java
Change-Id: Iaa5f3b75bf7de9dbf458fa5c452f7312989f4c4f
Diffstat (limited to 'tools/aapt2/java/AnnotationProcessor.cpp')
-rw-r--r--tools/aapt2/java/AnnotationProcessor.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/tools/aapt2/java/AnnotationProcessor.cpp b/tools/aapt2/java/AnnotationProcessor.cpp
index 16440bcf8ad7..b36682d98bfd 100644
--- a/tools/aapt2/java/AnnotationProcessor.cpp
+++ b/tools/aapt2/java/AnnotationProcessor.cpp
@@ -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);
}