clang-format: [Java] Fix static generic methods.
authorDaniel Jasper <djasper@google.com>
Mon, 3 Nov 2014 02:35:14 +0000 (02:35 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 3 Nov 2014 02:35:14 +0000 (02:35 +0000)
Before:
  public static<R> ArrayList<R> get() {}

After:
  public static <R> ArrayList<R> get() {}

llvm-svn: 221122

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

index bebd6cc..0b2b222 100644 (file)
@@ -1685,6 +1685,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
   } else if (Style.Language == FormatStyle::LK_Java) {
     if (Left.TokenText == "synchronized" && Right.is(tok::l_paren))
       return Style.SpaceBeforeParens != FormatStyle::SBPO_Never;
+    if (Left.is(tok::kw_static) && Right.Type == TT_TemplateOpener)
+      return true;
   }
   if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo())
     return true; // Never ever merge two identifiers.
index 60111b1..a47bfca 100644 (file)
@@ -140,8 +140,9 @@ TEST_F(FormatTestJava, Generics) {
   verifyFormat("A.<B>doSomething();");
 
   verifyFormat("@Override\n"
-               "public Map<String, ?> getAll() {\n"
-               "}");
+               "public Map<String, ?> getAll() {\n}");
+
+  verifyFormat("public static <R> ArrayList<R> get() {\n}");
 }
 
 TEST_F(FormatTestJava, StringConcatenation) {