diff options
author | Daniel Jasper <djasper@google.com> | 2014-11-03 02:27:28 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-11-03 02:27:28 +0000 |
commit | 39af6cd5a40e20f99b03e028942ae55ff7323683 (patch) | |
tree | 01627c8a7ea4022bed7aa0ee3d99d18bbbe8cea0 | |
parent | fcd556074c03ab47fe809e1f94fc78a3b3fe94dd (diff) | |
download | bcm5719-llvm-39af6cd5a40e20f99b03e028942ae55ff7323683.tar.gz bcm5719-llvm-39af6cd5a40e20f99b03e028942ae55ff7323683.zip |
clang-format: [Java] Fix class declaration formatting.
Before:
@SomeAnnotation()
abstract
class aaaaaaaaaaaa extends bbbbbbbbbbbbbbb implements cccccccccccc {
}
After:
@SomeAnnotation()
abstract class aaaaaaaaaaaa extends bbbbbbbbbbbbbbb
implements cccccccccccc {
}
llvm-svn: 221121
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 5 |
3 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 707153242b8..f6fbbba440e 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -428,7 +428,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, !State.Stack.back().AvoidBinPacking) || Previous.Type == TT_BinaryOperator) State.Stack.back().BreakBeforeParameter = false; - if (Previous.Type == TT_TemplateCloser && Current.NestingLevel == 0) + if ((Previous.Type == TT_TemplateCloser || + Previous.Type == TT_JavaAnnotation) && + Current.NestingLevel == 0) State.Stack.back().BreakBeforeParameter = false; if (NextNonComment->is(tok::question) || (PreviousNonComment && PreviousNonComment->is(tok::question))) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 5eb6e10554d..bebd6cc18d7 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1474,6 +1474,11 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, Left.Type == TT_InheritanceColon) return 2; + if (Left.Type == TT_LeadingJavaAnnotation) + return 1; + if (Style.Language == FormatStyle::LK_Java && Right.TokenText == "implements") + return 2; + if (Right.isMemberAccess()) { if (Left.is(tok::r_paren) && Left.MatchingParen && Left.MatchingParen->ParameterCount > 0) @@ -1481,9 +1486,6 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 150; } - if (Left.Type == TT_LeadingJavaAnnotation) - return 1; - if (Right.Type == TT_TrailingAnnotation && (!Right.Next || Right.Next->isNot(tok::l_paren))) { // Moving trailing annotations to the next line is fine for ObjC method diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 96dda9b11b4..60111b19edc 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -77,6 +77,11 @@ TEST_F(FormatTestJava, ClassDeclarations) { " implements SomeInterface,\n" " AnotherInterface {}", getStyleWithColumns(40)); + verifyFormat("@SomeAnnotation()\n" + "abstract class aaaaaaaaaaaa extends bbbbbbbbbbbbbbb\n" + " implements cccccccccccc {\n" + "}", + getStyleWithColumns(76)); } TEST_F(FormatTestJava, EnumDeclarations) { |