From 22997eeae8fcbd9dc5a3471cb8622792dcc32fad Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 8 Dec 2014 20:08:04 +0000 Subject: [PATCH] clang-format: [Java] Always break after annotations of multiline decls. 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 | 9 ++++++--- lib/Format/TokenAnnotator.cpp | 2 -- unittests/Format/FormatTestJava.cpp | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index e053d4c1aa..8538f9a460 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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) && diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ede60eede3..deda40cab8 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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)) diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 5b677ef00b..91b38ad758 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -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) { -- 2.40.0