Author: nico Date: Thu Oct 15 11:03:01 2015 New Revision: 250422 URL: http://llvm.org/viewvc/llvm-project?rev=250422&view=rev Log: clang-format/java: Break after annotations on fields in Chromium style.
Chromium follows the Android style guide for Java code, and that doesn't make the distinction between fields and non-fields that the Google Java style guide makes: https://source.android.com/source/code-style.html#use-standard-java-annotations https://google.github.io/styleguide/javaguide.html#s4.8.5-annotations Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestJava.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=250422&r1=250421&r2=250422&view=diff ============================================================================== --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Thu Oct 15 11:03:01 2015 @@ -236,6 +236,9 @@ struct FormatStyle { /// the commas with the colon. bool BreakConstructorInitializersBeforeComma; + /// \brief Break after each annotation on a field in Java files. + bool BreakAfterJavaFieldAnnotations; + /// \brief The column limit. /// /// A column limit of \c 0 means that there is no column limit. In this case, @@ -560,8 +563,8 @@ struct FormatStyle { BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && BreakConstructorInitializersBeforeComma == R.BreakConstructorInitializersBeforeComma && - ColumnLimit == R.ColumnLimit && - CommentPragmas == R.CommentPragmas && + BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations && + ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas && ConstructorInitializerAllOnOneLineOrOnePerLine == R.ConstructorInitializerAllOnOneLineOrOnePerLine && ConstructorInitializerIndentWidth == @@ -604,8 +607,7 @@ struct FormatStyle { SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses && SpacesInParentheses == R.SpacesInParentheses && SpacesInSquareBrackets == R.SpacesInSquareBrackets && - Standard == R.Standard && - TabWidth == R.TabWidth && + Standard == R.Standard && TabWidth == R.TabWidth && UseTab == R.UseTab; } }; Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=250422&r1=250421&r2=250422&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Thu Oct 15 11:03:01 2015 @@ -447,6 +447,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.BraceWrapping = {false, false, false, false, false, false, false, false, false, false, false}; LLVMStyle.BreakConstructorInitializersBeforeComma = false; + LLVMStyle.BreakAfterJavaFieldAnnotations = false; LLVMStyle.ColumnLimit = 80; LLVMStyle.CommentPragmas = "^ IWYU pragma:"; LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false; @@ -550,8 +551,9 @@ FormatStyle getChromiumStyle(FormatStyle FormatStyle ChromiumStyle = getGoogleStyle(Language); if (Language == FormatStyle::LK_Java) { ChromiumStyle.AllowShortIfStatementsOnASingleLine = true; - ChromiumStyle.IndentWidth = 4; + ChromiumStyle.BreakAfterJavaFieldAnnotations = true; ChromiumStyle.ContinuationIndentWidth = 8; + ChromiumStyle.IndentWidth = 4; } else { ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false; ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=250422&r1=250421&r2=250422&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Oct 15 11:03:01 2015 @@ -2176,7 +2176,7 @@ bool TokenAnnotator::mustBreakBefore(con Style.Language == FormatStyle::LK_JavaScript) && Left.is(TT_LeadingJavaAnnotation) && Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) && - Line.Last->is(tok::l_brace)) + (Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations)) return true; return false; Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=250422&r1=250421&r2=250422&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJava.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJava.cpp Thu Oct 15 11:03:01 2015 @@ -276,6 +276,10 @@ TEST_F(FormatTestJava, Annotations) { verifyFormat("void SomeFunction(@org.llvm.Nullable String something) {}"); verifyFormat("@Partial @Mock DataLoader loader;"); + verifyFormat("@Partial\n" + "@Mock\n" + "DataLoader loader;", + getChromiumStyle(FormatStyle::LK_Java)); verifyFormat("@SuppressWarnings(value = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")\n" "public static int iiiiiiiiiiiiiiiiiiiiiiii;"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits