[clang-format] Refactor #include insertion/deletion functionality into a class.
authorEric Liu <ioeric@google.com>
Fri, 4 May 2018 17:55:13 +0000 (17:55 +0000)
committerEric Liu <ioeric@google.com>
Fri, 4 May 2018 17:55:13 +0000 (17:55 +0000)
commitbf4c41c7e18ddac1328f7873e2ff8d209a96bd50
treea010a870615c13b429f6f209dd38c2d0f6269b56
parentd7ffbc5c7e5d033ee3812fde2c13f1bb80044e70
[clang-format] Refactor #include insertion/deletion functionality into a class.

Summary:
The class will be moved into libToolingCore as followup.

The new behaviors in this patch:
- New #include is inserted in the right position in a #include block to
preserver sorted #includes. This is best effort - only works when the
block is already sorted.
- When inserting multiple #includes to the end of a file which doesn't
end with a "\n" character, a "\n" will be prepended to each #include.
This is a special and rare case that was previously handled. This is now
relaxed to avoid complexity as it's rare in practice.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, cfe-commits, djasper

Differential Revision: https://reviews.llvm.org/D46180

llvm-svn: 331544
clang/lib/Format/Format.cpp
clang/unittests/Format/CleanupTest.cpp