clang-format: [Java] Fix breaking after annotations.

Before:
  @Annotation1 // comment
  @Annotation2 class C {}

After:
  @Annotation1 // comment
  @Annotation2
  class C {}

llvm-svn: 222825
This commit is contained in:
Daniel Jasper 2014-11-26 11:20:43 +00:00
parent 2db4107a36
commit 07013a42d2
2 changed files with 5 additions and 1 deletions

View File

@ -864,7 +864,8 @@ private:
Current.Previous->is(tok::at) &&
Current.isNot(Keywords.kw_interface)) {
const FormatToken &AtToken = *Current.Previous;
if (!AtToken.Previous || AtToken.Previous->is(TT_LeadingJavaAnnotation))
const FormatToken *Previous = AtToken.getPreviousNonComment();
if (!Previous || Previous->is(TT_LeadingJavaAnnotation))
Current.Type = TT_LeadingJavaAnnotation;
else
Current.Type = TT_JavaAnnotation;

View File

@ -206,6 +206,9 @@ TEST_F(FormatTestJava, Annotations) {
verifyFormat("@Override\n"
"@Nullable\n"
"public String getNameIfPresent() {}");
verifyFormat("@Override // comment\n"
"@Nullable\n"
"public String getNameIfPresent() {}");
verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
"public void doSomething() {}");