clang-format: Fix space between generic type parameter and square
authorDaniel Jasper <djasper@google.com>
Tue, 18 Nov 2014 23:48:01 +0000 (23:48 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 18 Nov 2014 23:48:01 +0000 (23:48 +0000)
bracket

Before:
  public Foo<X, Y> [] foos;

After:
  public Foo<X, Y>[] foos;

Patch by Harry Terkelsen. Thank you!

llvm-svn: 222283

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

index dfd880a..fdb1179 100644 (file)
@@ -1677,6 +1677,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
       Left.MatchingParen->Previous->is(tok::period))
     // A.<B>DoSomething();
     return false;
+  if (Left.Type == TT_TemplateCloser && Right.is(tok::l_square))
+    return false;
   return true;
 }
 
index eecac0f..d60ab96 100644 (file)
@@ -217,6 +217,9 @@ 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;");
+
+  verifyFormat("private Foo<X, Y>[] foos;");
+  verifyFormat("Foo<X, Y>[] foos = this.foos;");
 }
 
 TEST_F(FormatTestJava, StringConcatenation) {