r220282 - clang-format: [Java] Make annotation formatting more consistent.

Daniel Jasper djasper at google.com
Tue Oct 21 03:02:03 PDT 2014


Author: djasper
Date: Tue Oct 21 05:02:03 2014
New Revision: 220282

URL: http://llvm.org/viewvc/llvm-project?rev=220282&view=rev
Log:
clang-format: [Java] Make annotation formatting more consistent.

Before:
  DoSomething(new A() {
    @Override public String toString() {
    }
  });

After:
  DoSomething(new A() {
    @Override
    public String toString() {
    }
  });

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=220282&r1=220281&r2=220282&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Oct 21 05:02:03 2014
@@ -1797,7 +1797,7 @@ bool TokenAnnotator::mustBreakBefore(con
       return true;
   } else if (Style.Language == FormatStyle::LK_Java) {
     if (Left.Type == TT_JavaAnnotation && Right.isNot(tok::l_paren) &&
-        Line.MightBeFunctionDecl)
+        Line.Last->is(tok::l_brace))
       return true;
   }
 

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=220282&r1=220281&r2=220282&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Tue Oct 21 05:02:03 2014
@@ -75,6 +75,12 @@ TEST_F(FormatTestJava, Annotations) {
   verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
                "public void doSomething() {\n}");
 
+  verifyFormat("DoSomething(new A() {\n"
+               "  @Override\n"
+               "  public String toString() {\n"
+               "  }\n"
+               "});");
+
   verifyFormat("@Partial @Mock DataLoader loader;");
 }
 





More information about the cfe-commits mailing list