summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UsingDeclarationsSorter.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-10-18 22:13:25 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-10-18 22:13:25 +0000
commit9da65aa8585ad3d73cb3495bcd018b4e226cac53 (patch)
tree7e7cdcc56a7214914191f97b978e9df818ea390f /clang/lib/Format/UsingDeclarationsSorter.cpp
parent2f27456c826a9266f8f3e9cefafd1f7e08ab51b1 (diff)
downloadbcm5719-llvm-9da65aa8585ad3d73cb3495bcd018b4e226cac53.tar.gz
bcm5719-llvm-9da65aa8585ad3d73cb3495bcd018b4e226cac53.zip
[clang-format] Sort whole block of using declarations while partially formatting
Summary: This patch enables sorting the full block of using declarations when some line is affected. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D39024 llvm-svn: 316130
Diffstat (limited to 'clang/lib/Format/UsingDeclarationsSorter.cpp')
-rw-r--r--clang/lib/Format/UsingDeclarationsSorter.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Format/UsingDeclarationsSorter.cpp b/clang/lib/Format/UsingDeclarationsSorter.cpp
index d4ff7c25ea0..4d60d8fd9a4 100644
--- a/clang/lib/Format/UsingDeclarationsSorter.cpp
+++ b/clang/lib/Format/UsingDeclarationsSorter.cpp
@@ -76,6 +76,17 @@ std::string computeUsingDeclarationLabel(const FormatToken *UsingTok) {
void endUsingDeclarationBlock(
SmallVectorImpl<UsingDeclaration> *UsingDeclarations,
const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
+ bool BlockAffected = false;
+ for (const UsingDeclaration& Declaration : *UsingDeclarations) {
+ if (Declaration.Line->Affected) {
+ BlockAffected = true;
+ break;
+ }
+ }
+ if (!BlockAffected) {
+ UsingDeclarations->clear();
+ return;
+ }
SmallVector<UsingDeclaration, 4> SortedUsingDeclarations(
UsingDeclarations->begin(), UsingDeclarations->end());
std::stable_sort(SortedUsingDeclarations.begin(),
@@ -122,7 +133,7 @@ tooling::Replacements UsingDeclarationsSorter::analyze(
tooling::Replacements Fixes;
SmallVector<UsingDeclaration, 4> UsingDeclarations;
for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
- if (!AnnotatedLines[I]->Affected || AnnotatedLines[I]->InPPDirective ||
+ if (AnnotatedLines[I]->InPPDirective ||
!AnnotatedLines[I]->startsWith(tok::kw_using) ||
AnnotatedLines[I]->First->Finalized) {
endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes);
OpenPOWER on IntegriCloud