diff options
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 |