llvm-project/clang/lib/Format
Ben Hamilton 01cbd5aa68 [clang-format] Do not break after ObjC category open paren
Summary:
Previously, `clang-format` would break Objective-C
category extensions after the opening parenthesis to avoid
breaking the protocol list:

```
% echo "@interface ccccccccccccc (ccccccccccc) <ccccccccccccc> { }" | \
  clang-format -assume-filename=foo.h -style="{BasedOnStyle: llvm, \
  ColumnLimit: 40}"
@interface ccccccccccccc (
    ccccccccccc) <ccccccccccccc> {
}
```

This looks fairly odd, as we could have kept the category extension
on the previous line.

Category extensions are a single item, so they are generally very
short compared to protocol lists. We should prefer breaking after the
opening `<` of the protocol list over breaking after the opening `(`
of the category extension.

With this diff, we now avoid breaking after the category extension's
open paren, which causes us to break after the protocol list's
open angle bracket:

```
% echo "@interface ccccccccccccc (ccccccccccc) <ccccccccccccc> { }" | \
  ./bin/clang-format -assume-filename=foo.h -style="{BasedOnStyle: llvm, \
  ColumnLimit: 40}"
@interface ccccccccccccc (ccccccccccc) <
    ccccccccccccc> {
}
```

Test Plan: New test added. Confirmed test failed before diff and
  passed after diff by running:
  % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 329919
2018-04-12 15:11:55 +00:00
..
AffectedRangeManager.cpp Added Fixer implementation and fix() interface in clang-format for removing redundant code. 2016-04-25 15:09:22 +00:00
AffectedRangeManager.h removed redundant '#' 2016-04-28 07:52:06 +00:00
BreakableToken.cpp [format] Eliminate global destructors. 2018-03-20 21:52:19 +00:00
BreakableToken.h [clang-format] Ignore UnbreakableTailLength sometimes during breaking 2018-01-23 11:26:19 +00:00
CMakeLists.txt [clang-format] Support sorting using declarations 2017-06-21 12:03:12 +00:00
ContinuationIndenter.cpp [clang-format] Always indent wrapped Objective-C selector names 2018-04-12 15:11:48 +00:00
ContinuationIndenter.h [clang-format] Do not break Objective-C string literals inside array literals 2018-02-08 16:07:25 +00:00
Encoding.h [Format] Remove dead code. 2016-12-19 21:10:50 +00:00
Format.cpp [clang-format] Improve ObjC guessing heuristic by supporting all @keywords 2018-04-12 15:11:53 +00:00
FormatInternal.h FormatInternal.h: Add missing includes. 2017-11-21 01:09:17 +00:00
FormatToken.cpp clang-format clang-format. 2017-09-20 09:51:03 +00:00
FormatToken.h [clang-format] Don't detect C++11 attribute specifiers as ObjC 2018-03-12 15:42:38 +00:00
FormatTokenLexer.cpp [clang] Change std::sort to llvm::sort in response to r327219 2018-03-27 16:50:00 +00:00
FormatTokenLexer.h [clang-format] Support python-style comments in text protos 2017-11-10 12:50:09 +00:00
NamespaceEndCommentsFixer.cpp [format] Initialize regex lazily 2018-03-20 20:43:12 +00:00
NamespaceEndCommentsFixer.h [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
SortJavaScriptImports.cpp [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
SortJavaScriptImports.h clang-format: [JS] sort ES6 imports. 2016-05-20 11:24:24 +00:00
TokenAnalyzer.cpp [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
TokenAnalyzer.h [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
TokenAnnotator.cpp [clang-format] Do not break after ObjC category open paren 2018-04-12 15:11:55 +00:00
TokenAnnotator.h [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
UnwrappedLineFormatter.cpp Revert "[clang-format] Remove empty lines before }[;] // comment" 2018-03-27 13:14:29 +00:00
UnwrappedLineFormatter.h [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
UnwrappedLineParser.cpp Fix bugs around handling C++11 attributes. 2018-04-11 14:51:54 +00:00
UnwrappedLineParser.h Fix typos in clang 2018-04-06 15:14:32 +00:00
UsingDeclarationsSorter.cpp [clang-format] Deduplicate using declarations 2017-11-24 18:00:01 +00:00
UsingDeclarationsSorter.h [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00
WhitespaceManager.cpp [clang] Change std::sort to llvm::sort in response to r327219 2018-03-27 16:50:00 +00:00
WhitespaceManager.h [clang-format] Format raw string literals 2017-10-30 14:01:50 +00:00