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 llvm-svn: 250422
This commit is contained in:
parent
aa19708f88
commit
2cd92f1cc7
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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::LanguageKind Language) {
|
|||
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;
|
||||
|
|
|
@ -2176,7 +2176,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
|
|||
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;
|
||||
|
|
|
@ -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;");
|
||||
|
||||
|
|
Loading…
Reference in New Issue