diff options
author | Jooyung Han <jooyung@google.com> | 2021-01-21 13:47:59 +0900 |
---|---|---|
committer | Jooyung Han <jooyung@google.com> | 2021-01-22 09:41:31 +0900 |
commit | b7a60ec85d0ad34eefb00746192a15a920f239f3 (patch) | |
tree | 8f495f3f46a0ce18ebc6a5e0b69f5b56419668d9 /comments.cpp | |
parent | 161bb0f56b3ac9559c7c87d64b48be329256cf9d (diff) | |
download | aidl-b7a60ec85d0ad34eefb00746192a15a920f239f3.tar.gz |
Emit comments as javadoc in the Java backend
While AIDL treats /** */ and /* */ alike, but Java tools don't.
So /* */ in AIDL should be formatted as Javadoc style (/** */) so that
Java tools recognize tags correctly.
Bug: 177276893
Test: aidl_unittests
Change-Id: I609660bf7f5e875ed99df7950d8b199613cdb7e1
Diffstat (limited to 'comments.cpp')
-rw-r--r-- | comments.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/comments.cpp b/comments.cpp index 4b724b2d..afbdc8f8 100644 --- a/comments.cpp +++ b/comments.cpp @@ -41,6 +41,7 @@ namespace { static const std::string_view kLineCommentBegin = "//"; static const std::string_view kBlockCommentBegin = "/*"; static const std::string_view kBlockCommentEnd = "*/"; +static const std::string_view kDocCommentBegin = "/**"; static const std::string kTagDeprecated = "@deprecated"; static const std::regex kTagHideRegex{"@hide\\b"}; @@ -214,5 +215,22 @@ std::optional<Deprecated> FindDeprecated(const Comments& comments) { return std::nullopt; } +// Formats comments for the Java backend. +// The last/block comment is transformed into javadoc(/** */) +// and others are used as they are. +std::string FormatCommentsForJava(const Comments& comments) { + std::stringstream out; + for (auto it = begin(comments); it != end(comments); it++) { + const bool last = next(it) == end(comments); + // We only re-format the last/block comment which is not already a doc-style comment. + if (last && it->type == Comment::Type::BLOCK && !StartsWith(it->body, kDocCommentBegin)) { + out << kDocCommentBegin << ConsumePrefix(it->body, kBlockCommentBegin); + } else { + out << it->body; + } + } + return out.str(); +} + } // namespace aidl } // namespace android
\ No newline at end of file |