Before:
@Override public String toString() { .. }
After:
@Override
public String toString() { .. }
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220274
91177308-0d34-0410-b5e6-
96231b3b80d8
!PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
PreviousNonComment->Type != TT_TemplateCloser &&
PreviousNonComment->Type != TT_BinaryOperator &&
+ PreviousNonComment->Type != TT_JavaAnnotation &&
Current.Type != TT_BinaryOperator && !PreviousNonComment->opensScope())
State.Stack.back().BreakBeforeParameter = true;
if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0)
return State.Stack.back().VariablePos;
if ((PreviousNonComment && (PreviousNonComment->ClosesTemplateDeclaration ||
- PreviousNonComment->Type == TT_AttributeParen)) ||
+ PreviousNonComment->Type == TT_AttributeParen ||
+ PreviousNonComment->Type == TT_JavaAnnotation)) ||
(!Style.IndentWrappedFunctionNames &&
(NextNonComment->is(tok::kw_operator) ||
NextNonComment->Type == TT_FunctionDeclarationName)))
TT_ImplicitStringLiteral,
TT_InheritanceColon,
TT_InlineASMColon,
+ TT_JavaAnnotation,
TT_LambdaLSquare,
TT_LineComment,
TT_ObjCBlockLBrace,
// Line.MightBeFunctionDecl can only be true after the parentheses of a
// function declaration have been found.
Current.Type = TT_TrailingAnnotation;
+ } else if (Style.Language == FormatStyle::LK_Java && Current.Previous &&
+ Current.Previous->is(tok::at)) {
+ Current.Type = TT_JavaAnnotation;
}
}
}
if (Right.is(tok::char_constant) && Left.is(tok::plus) && Left.Previous &&
Left.Previous->is(tok::char_constant))
return true;
+ } else if (Style.Language == FormatStyle::LK_Java) {
+ if (Left.Type == TT_JavaAnnotation && Line.MightBeFunctionDecl)
+ return true;
}
return false;
" throws LooooooooooooooooooooooooooooongException {}");
}
+TEST_F(FormatTestJava, Annotations) {
+ verifyFormat("@Override\n"
+ "public String toString() {\n}");
+ verifyFormat("@Override\n"
+ "@Nullable\n"
+ "public String getNameIfPresent() {\n}");
+ verifyFormat("@Partial @Mock DataLoader loader;");
+}
+
} // end namespace tooling
} // end namespace clang