diff options
author | Sergio Campamá <kaipi@google.com> | 2016-08-09 05:26:24 -0700 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2016-08-09 08:26:24 -0400 |
commit | 237f321e338b50503eb38728afa6ad29bea6076a (patch) | |
tree | 0b6c77f4349b1fdb223c59179e286fb83d70ddc7 /src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | |
parent | 56b8f44eede93463f7ec4fbecd5bc7dfc8d6d648 (diff) |
Adds support for appledoc in generated code. (#1928)
Convert mapping of proto comments to appledoc format so they show up in Xcode and cocoadocs.
Fixes https://github.com/google/protobuf/issues/1866
Diffstat (limited to 'src/google/protobuf/compiler/objectivec/objectivec_helpers.cc')
-rw-r--r-- | src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 22c7a883..28b3f5ae 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -830,7 +830,8 @@ string BuildFlagsString(const vector<string>& strings) { return string; } -string BuildCommentsString(const SourceLocation& location) { +string BuildCommentsString(const SourceLocation& location, + bool prefer_single_line) { const string& comments = location.leading_comments.empty() ? location.trailing_comments : location.leading_comments; @@ -839,15 +840,37 @@ string BuildCommentsString(const SourceLocation& location) { while (!lines.empty() && lines.back().empty()) { lines.pop_back(); } - string prefix("///"); - string suffix("\n"); + // If there are no comments, just return an empty string. + if (lines.size() == 0) { + return ""; + } + + string prefix; + string suffix; string final_comments; - for (int i = 0; i < lines.size(); i++) { - // HeaderDoc uses '\' and '@' for markers; escape them. - const string line = StringReplace(lines[i], "\\", "\\\\", true); - final_comments += - prefix + StringReplace(line, "@", "\\@", true) + suffix; + string epilogue; + + if (prefer_single_line && lines.size() == 1) { + prefix = "/** "; + suffix = " */\n"; + } else { + prefix = " * "; + suffix = "\n"; + final_comments += "/**\n"; + epilogue = " **/\n"; } + + for (int i = 0; i < lines.size(); i++) { + string line = StripPrefixString(lines[i], " "); + // HeaderDoc and appledoc use '\' and '@' for markers; escape them. + line = StringReplace(line, "\\", "\\\\", true); + line = StringReplace(line, "@", "\\@", true); + // Decouple / from * to not have inline comments inside comments. + line = StringReplace(line, "/*", "/\\*", true); + line = StringReplace(line, "*/", "*\\/", true); + final_comments += prefix + line + suffix; + } + final_comments += epilogue; return final_comments; } |