r221121 - clang-format: [Java] Fix class declaration formatting.
Daniel Jasper
djasper at google.com
Sun Nov 2 18:27:28 PST 2014
Author: djasper
Date: Sun Nov 2 20:27:28 2014
New Revision: 221121
URL: http://llvm.org/viewvc/llvm-project?rev=221121&view=rev
Log:
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 {
}
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=221121&r1=221120&r2=221121&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Nov 2 20:27:28 2014
@@ -428,7 +428,9 @@ unsigned ContinuationIndenter::addTokenO
!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)))
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=221121&r1=221120&r2=221121&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Nov 2 20:27:28 2014
@@ -1474,6 +1474,11 @@ unsigned TokenAnnotator::splitPenalty(co
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(co
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
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=221121&r1=221120&r2=221121&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Nov 2 20:27:28 2014
@@ -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) {
More information about the cfe-commits
mailing list