From b7a60ec85d0ad34eefb00746192a15a920f239f3 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 21 Jan 2021 13:47:59 +0900 Subject: 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 --- comments.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'comments.cpp') 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 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 -- cgit v1.2.3