diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-11-06 15:14:35 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-11-06 16:37:57 -0800 |
commit | b274e35abfbbd09e0fce983a215c11522c56cce2 (patch) | |
tree | a30ba5aac504bbdfde8ac6931cb8471a46f6e284 /tools/aapt2/java/AnnotationProcessor.cpp | |
parent | 557b64abad9915f92a9d35c748766e873f3a29fd (diff) |
AAPT2: Fix inclusion of comments in R.java javadoc
Comments weren't being copied when merged from the various
resource tables.
Also refactored the JavaClassGenerator to omit a class
if no entries exist for it.
Change-Id: I6eaa89b7b3715bc05403635a2baf0d1db3efd142
Diffstat (limited to 'tools/aapt2/java/AnnotationProcessor.cpp')
-rw-r--r-- | tools/aapt2/java/AnnotationProcessor.cpp | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/tools/aapt2/java/AnnotationProcessor.cpp b/tools/aapt2/java/AnnotationProcessor.cpp index b36682d98bfd..9c25d4e35975 100644 --- a/tools/aapt2/java/AnnotationProcessor.cpp +++ b/tools/aapt2/java/AnnotationProcessor.cpp @@ -25,33 +25,20 @@ void AnnotationProcessor::appendCommentLine(const std::string& comment) { static const std::string sDeprecated = "@deprecated"; static const std::string sSystemApi = "@SystemApi"; - if (comment.find(sDeprecated) != std::string::npos && !mDeprecated) { - mDeprecated = true; - if (!mAnnotations.empty()) { - mAnnotations += "\n"; - } - mAnnotations += mPrefix; - mAnnotations += "@Deprecated"; + if (comment.find(sDeprecated) != std::string::npos) { + mAnnotationBitMask |= kDeprecated; } - if (comment.find(sSystemApi) != std::string::npos && !mSystemApi) { - mSystemApi = true; - if (!mAnnotations.empty()) { - mAnnotations += "\n"; - } - mAnnotations += mPrefix; - mAnnotations += "@android.annotations.SystemApi"; + if (comment.find(sSystemApi) != std::string::npos) { + mAnnotationBitMask |= kSystemApi; } - if (mComment.empty()) { - mComment += mPrefix; - mComment += "/**"; + if (!mHasComments) { + mHasComments = true; + mComment << "/**"; } - mComment += "\n"; - mComment += mPrefix; - mComment += " * "; - mComment += std::move(comment); + mComment << "\n" << " * " << std::move(comment); } void AnnotationProcessor::appendComment(const StringPiece16& comment) { @@ -73,17 +60,22 @@ void AnnotationProcessor::appendComment(const StringPiece& comment) { } } -std::string AnnotationProcessor::buildComment() { - if (!mComment.empty()) { - mComment += "\n"; - mComment += mPrefix; - mComment += " */"; +void AnnotationProcessor::writeToStream(std::ostream* out, const StringPiece& prefix) { + if (mHasComments) { + std::string result = mComment.str(); + for (StringPiece line : util::tokenize<char>(result, '\n')) { + *out << prefix << line << "\n"; + } + *out << prefix << " */" << "\n"; } - return std::move(mComment); -} -std::string AnnotationProcessor::buildAnnotations() { - return std::move(mAnnotations); + if (mAnnotationBitMask & kDeprecated) { + *out << prefix << "@Deprecated\n"; + } + + if (mAnnotationBitMask & kSystemApi) { + *out << prefix << "@android.annotation.SystemApi\n"; + } } } // namespace aapt |