summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/NamespaceEndCommentsFixer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/NamespaceEndCommentsFixer.cpp')
-rw-r--r--clang/lib/Format/NamespaceEndCommentsFixer.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/clang/lib/Format/NamespaceEndCommentsFixer.cpp b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
index 495c34db754..578dcf7b670 100644
--- a/clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -23,7 +23,7 @@ namespace clang {
namespace format {
namespace {
-// The maximal number of lines that a short namespace spans.
+// The maximal number of unwrapped lines that a short namespace spans.
// Short namespaces don't need an end comment.
static const int kShortNamespaceMaxLines = 1;
@@ -60,14 +60,6 @@ std::string computeEndCommentText(StringRef NamespaceName, bool AddNewline) {
return text;
}
-bool isShort(const FormatToken *NamespaceTok, const FormatToken *RBraceTok,
- const SourceManager &SourceMgr) {
- int StartLine =
- SourceMgr.getSpellingLineNumber(NamespaceTok->Tok.getLocation());
- int EndLine = SourceMgr.getSpellingLineNumber(RBraceTok->Tok.getLocation());
- return EndLine - StartLine + 1 <= kShortNamespaceMaxLines;
-}
-
bool hasEndComment(const FormatToken *RBraceTok) {
return RBraceTok->Next && RBraceTok->Next->is(tok::comment);
}
@@ -151,7 +143,8 @@ tooling::Replacements NamespaceEndCommentsFixer::analyze(
const std::string EndCommentText =
computeEndCommentText(NamespaceName, AddNewline);
if (!hasEndComment(RBraceTok)) {
- if (!isShort(NamespaceTok, RBraceTok, SourceMgr))
+ bool isShort = I - StartLineIndex <= kShortNamespaceMaxLines + 1;
+ if (!isShort)
addEndComment(RBraceTok, EndCommentText, SourceMgr, &Fixes);
continue;
}
OpenPOWER on IntegriCloud