clang-format: [Java] Fix breaking after annotations.
authorDaniel Jasper <djasper@google.com>
Wed, 26 Nov 2014 11:20:43 +0000 (11:20 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 26 Nov 2014 11:20:43 +0000 (11:20 +0000)
Before:
  @Annotation1 // comment
  @Annotation2 class C {}

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

llvm-svn: 222825

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestJava.cpp

index 3daea77..9b32c35 100644 (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;
index 946ae32..5c80bab 100644 (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() {}");