From 0ba9b5941dfafdf99127b9a9578b9dfac26b8d12 Mon Sep 17 00:00:00 2001
From: Daniel Jasper <djasper@google.com>
Date: Fri, 14 Nov 2014 08:22:46 +0000
Subject: [PATCH] clang-format: [Java] Improve formatting of generics.

Before:
  Function < F, ? extends T > function;

After:
  Function<F, ? extends T> function;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221976 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Format/Format.cpp               |  1 +
 lib/Format/TokenAnnotator.cpp       | 14 ++++++--------
 unittests/Format/FormatTestJava.cpp |  1 +
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 74adaf7605..740adb2b12 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -415,6 +415,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
     GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
     GoogleStyle.ColumnLimit = 100;
     GoogleStyle.SpaceAfterCStyleCast = true;
+    GoogleStyle.SpacesBeforeTrailingComments = 1;
   } else if (Language == FormatStyle::LK_JavaScript) {
     GoogleStyle.BreakBeforeTernaryOperators = false;
     GoogleStyle.MaxEmptyLinesToKeep = 3;
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 8ec8f58d14..f926beb106 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -63,11 +63,13 @@ private:
         next();
         return true;
       }
-      if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace,
-                                tok::colon))
-        return false;
       if (CurrentToken->is(tok::question) &&
-          Style.Language != FormatStyle::LK_Java)
+          Style.Language == FormatStyle::LK_Java) {
+        next();
+        continue;
+      }
+      if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace,
+                                tok::colon, tok::question))
         return false;
       // If a && or || is found and interpreted as a binary operator, this set
       // of angles is likely part of something like "a < b && c > d". If the
@@ -367,10 +369,6 @@ private:
   }
 
   bool parseConditional() {
-    if (Style.Language == FormatStyle::LK_Java &&
-        CurrentToken->isOneOf(tok::comma, tok::greater))
-      return true;  // This is a generic "?".
-
     while (CurrentToken) {
       if (CurrentToken->is(tok::colon)) {
         CurrentToken->Type = TT_ConditionalExpr;
diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp
index 0ee398aa32..650c0af0cb 100644
--- a/unittests/Format/FormatTestJava.cpp
+++ b/unittests/Format/FormatTestJava.cpp
@@ -203,6 +203,7 @@ TEST_F(FormatTestJava, Generics) {
 
   verifyFormat("public static <R> ArrayList<R> get() {\n}");
   verifyFormat("<T extends B> T getInstance(Class<T> type);");
+  verifyFormat("Function<F, ? extends T> function;");
 }
 
 TEST_F(FormatTestJava, StringConcatenation) {
-- 
2.40.0