summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-12-08 20:08:04 +0000
committerDaniel Jasper <djasper@google.com>2014-12-08 20:08:04 +0000
commit211e1329cccc6db8b30368c1464baa512dce98de (patch)
treef80b9a8cef3245d757f716a854dda0c1500052a2
parent818a3676aa34b0ec76c9b346c0794e8c4376585d (diff)
downloadbcm5719-llvm-211e1329cccc6db8b30368c1464baa512dce98de.tar.gz
bcm5719-llvm-211e1329cccc6db8b30368c1464baa512dce98de.zip
clang-format: [Java] Always break after annotations of multiline decls.
Before: @Mock DataLoader loooooooooooooooooooooooader = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; After: @Mock DataLoader loooooooooooooooooooooooader = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 223688
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp9
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTestJava.cpp4
3 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index e053d4c1aac..8538f9a4601 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/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/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ede60eede3c..deda40cab89 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/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/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp
index 5b677ef00bd..91b38ad7588 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/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) {
OpenPOWER on IntegriCloud