clang-format: [Java] Improve formatting of throws declarations.

Before:
  public void doSoooooooooo() throws LoooooooooongException,
      LooooooooooongException {}

After:
  public void doSoooooooooo()
      throws LoooooooooongException, LooooooooooongException {}

llvm-svn: 222829
This commit is contained in:
Daniel Jasper 2014-11-26 12:31:19 +00:00
parent 2a783392d4
commit 375815d24b
2 changed files with 5 additions and 2 deletions

View File

@ -1200,7 +1200,8 @@ private:
else if (Current->isOneOf(tok::period, tok::arrow))
return PrecedenceArrowAndPeriod;
else if (Style.Language == FormatStyle::LK_Java &&
Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements))
Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws))
return 0;
}
return -1;
@ -1470,7 +1471,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Style.Language == FormatStyle::LK_Java) {
if (Left.is(TT_LeadingJavaAnnotation))
return 1;
if (Right.is(Keywords.kw_extends))
if (Right.isOneOf(Keywords.kw_extends, Keywords.kw_throws))
return 1;
if (Right.is(Keywords.kw_implements))
return 2;

View File

@ -202,6 +202,8 @@ TEST_F(FormatTestJava, ArrayInitializers) {
TEST_F(FormatTestJava, ThrowsDeclarations) {
verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
" throws LooooooooooooooooooooooooooooongException {}");
verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
" throws LoooooooooongException, LooooooooooongException {}");
}
TEST_F(FormatTestJava, Annotations) {