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

Daniel Jasper djasper at google.com
Wed Nov 26 03:20:43 PST 2014


Author: djasper
Date: Wed Nov 26 05:20:43 2014
New Revision: 222825

URL: http://llvm.org/viewvc/llvm-project?rev=222825&view=rev
Log:
clang-format: [Java] Fix breaking after annotations.

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

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

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJava.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222825&r1=222824&r2=222825&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 26 05:20:43 2014
@@ -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;

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222825&r1=222824&r2=222825&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Wed Nov 26 05:20:43 2014
@@ -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() {}");





More information about the cfe-commits mailing list