]> granicus.if.org Git - clang/commitdiff
clang-format: [Java] Always break after annotations of multiline decls.
authorDaniel Jasper <djasper@google.com>
Mon, 8 Dec 2014 20:08:04 +0000 (20:08 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 8 Dec 2014 20:08:04 +0000 (20:08 +0000)
Before:
  @Mock DataLoader loooooooooooooooooooooooader =
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

After:
  @Mock
  DataLoader loooooooooooooooooooooooader =
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223688 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJava.cpp

index e053d4c1aace7e901368f3346036b69d7a8ace3d..8538f9a460114800759567f16fc7d762ee229ac6 100644 (file)
@@ -206,9 +206,12 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   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) &&
index ede60eede3c24eaed2523cf573f78a758da64113..deda40cab891b84e6308cf65160d2d8d2ea54a20 100644 (file)
@@ -1474,8 +1474,6 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
     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))
index 5b677ef00bd40418e321d82b57ac33b106c41143..91b38ad758890c8931d2efb11fbc01b73601e6c0 100644 (file)
@@ -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) {