clang-format: [Java] Support annotations with parameters.
authorDaniel Jasper <djasper@google.com>
Tue, 21 Oct 2014 09:25:39 +0000 (09:25 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 21 Oct 2014 09:25:39 +0000 (09:25 +0000)
Before:
  @SuppressWarnings
  (value = "unchecked") public void doSomething() { .. }

After:
  @SuppressWarnings(value = "unchecked")
  public void doSomething() { .. }

llvm-svn: 220279

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

index ce3d899..4f32b9f 100644 (file)
@@ -184,6 +184,8 @@ private:
 
         if (Left->Type == TT_AttributeParen)
           CurrentToken->Type = TT_AttributeParen;
+        if (Left->Previous && Left->Previous->Type == TT_JavaAnnotation)
+          CurrentToken->Type = TT_JavaAnnotation;
 
         if (!HasMultipleLines)
           Left->PackingKind = PPK_Inconclusive;
@@ -1791,7 +1793,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
         Left.Previous->is(tok::char_constant))
       return true;
   } else if (Style.Language == FormatStyle::LK_Java) {
-    if (Left.Type == TT_JavaAnnotation && Line.MightBeFunctionDecl)
+    if (Left.Type == TT_JavaAnnotation && Right.isNot(tok::l_paren) &&
+        Line.MightBeFunctionDecl)
       return true;
   }
 
index 18d945d..cf48a7a 100644 (file)
@@ -70,6 +70,10 @@ TEST_F(FormatTestJava, Annotations) {
   verifyFormat("@Override\n"
                "@Nullable\n"
                "public String getNameIfPresent() {\n}");
+
+  verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
+               "public void doSomething() {\n}");
+
   verifyFormat("@Partial @Mock DataLoader loader;");
 }