r223688 - clang-format: [Java] Always break after annotations of multiline decls.
Daniel Jasper
djasper at google.com
Mon Dec 8 12:08:05 PST 2014
Author: djasper
Date: Mon Dec 8 14:08:04 2014
New Revision: 223688
URL: http://llvm.org/viewvc/llvm-project?rev=223688&view=rev
Log:
clang-format: [Java] Always break after annotations of multiline decls.
Before:
@Mock DataLoader loooooooooooooooooooooooader =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
@Mock
DataLoader loooooooooooooooooooooooader =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=223688&r1=223687&r2=223688&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Dec 8 14:08:04 2014
@@ -206,9 +206,12 @@ bool ContinuationIndenter::mustBreak(con
if (Current.is(TT_SelectorName) && State.Stack.back().ObjCSelectorNameFound &&
State.Stack.back().BreakBeforeParameter)
return true;
- if (Previous.ClosesTemplateDeclaration && Current.NestingLevel == 0 &&
- !Current.isTrailingComment())
- return true;
+ if (Current.NestingLevel == 0 && !Current.isTrailingComment()) {
+ if (Previous.ClosesTemplateDeclaration)
+ return true;
+ if (Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren))
+ return true;
+ }
// If the return type spans multiple lines, wrap before the function name.
if (Current.isOneOf(TT_FunctionDeclarationName ,tok::kw_operator) &&
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=223688&r1=223687&r2=223688&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Dec 8 14:08:04 2014
@@ -1474,8 +1474,6 @@ unsigned TokenAnnotator::splitPenalty(co
return 0;
if (Style.Language == FormatStyle::LK_Java) {
- if (Left.is(TT_LeadingJavaAnnotation))
- return 1;
if (Right.isOneOf(Keywords.kw_extends, Keywords.kw_throws))
return 1;
if (Right.is(Keywords.kw_implements))
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=223688&r1=223687&r2=223688&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Mon Dec 8 14:08:04 2014
@@ -262,6 +262,10 @@ TEST_F(FormatTestJava, Annotations) {
verifyFormat("@SomeAnnotation(\"With some really looooooooooooooong text\")\n"
"private static final long something = 0L;");
+ verifyFormat("@Mock\n"
+ "DataLoader loooooooooooooooooooooooader =\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
+ getStyleWithColumns(60));
}
TEST_F(FormatTestJava, Generics) {
More information about the cfe-commits
mailing list