r220041 - clang-format: [Java] Don't break immediately after "throws".
Daniel Jasper
djasper at google.com
Fri Oct 17 06:36:15 PDT 2014
Author: djasper
Date: Fri Oct 17 08:36:14 2014
New Revision: 220041
URL: http://llvm.org/viewvc/llvm-project?rev=220041&view=rev
Log:
clang-format: [Java] Don't break immediately after "throws".
Before:
public void doSooooooooooooooooooooooooooomething() throws
LooooooooooooooooooooooooooooongException {}
After:
public void doSooooooooooooooooooooooooooomething()
throws LooooooooooooooooooooooooooooongException {}
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=220041&r1=220040&r2=220041&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct 17 08:36:14 2014
@@ -1791,6 +1791,12 @@ bool TokenAnnotator::mustBreakBefore(con
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)
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=220041&r1=220040&r2=220041&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Fri Oct 17 08:36:14 2014
@@ -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
More information about the cfe-commits
mailing list