clang-format: [Java] Don't break immediately after "throws".

Before:
  public void doSooooooooooooooooooooooooooomething() throws
      LooooooooooooooooooooooooooooongException {}

After:
  public void doSooooooooooooooooooooooooooomething()
      throws LooooooooooooooooooooooooooooongException {}

llvm-svn: 220041
This commit is contained in:
Daniel Jasper 2014-10-17 13:36:14 +00:00
parent 9758bc473b
commit f26c755d42
2 changed files with 11 additions and 6 deletions

View File

@ -1791,6 +1791,12 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
const FormatToken &Right) {
const FormatToken &Left = *Right.Previous;
if (Style.Language == FormatStyle::LK_Java) {
if (Left.is(tok::identifier) && Left.TokenText == "throws")
return false;
}
if (Left.is(tok::at))
return false;
if (Left.Tok.getObjCKeywordID() == tok::objc_interface)

View File

@ -37,12 +37,6 @@ protected:
return format(Code, 0, Code.size(), Style);
}
static FormatStyle getGoogleJSStyleWithColumns(unsigned ColumnLimit) {
FormatStyle Style = getGoogleStyle(FormatStyle::LK_Java);
Style.ColumnLimit = ColumnLimit;
return Style;
}
static void verifyFormat(
llvm::StringRef Code,
const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
@ -65,5 +59,10 @@ TEST_F(FormatTestJava, ClassDeclarations) {
"}");
}
TEST_F(FormatTestJava, ThrowsDeclarations) {
verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
" throws LooooooooooooooooooooooooooooongException {}");
}
} // end namespace tooling
} // end namespace clang