From 09f6abe8d87256d6d1b6285587418a1adad67a40 Mon Sep 17 00:00:00 2001 From: Daniel Jasper <djasper@google.com> Date: Fri, 14 Nov 2014 09:05:32 +0000 Subject: [PATCH] clang-format: [Java] Improve generic return type formatting. Before: public<R> ArrayList<R> get() { After: public <R> ArrayList<R> get() { llvm-svn: 221979 --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTestJava.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f926beb1066e..bce1d64166f9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1684,7 +1684,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, } else if (Style.Language == FormatStyle::LK_Java) { if (Left.is(Keywords.kw_synchronized) && Right.is(tok::l_paren)) return Style.SpaceBeforeParens != FormatStyle::SBPO_Never; - if (Left.is(tok::kw_static) && Right.Type == TT_TemplateOpener) + if (Left.isOneOf(tok::kw_static, tok::kw_public) && + Right.Type == TT_TemplateOpener) return true; } if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo()) diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index e8e35c85ef74..3799003b7760 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -205,6 +205,7 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("@Override\n" "public Map<String, ?> getAll() {\n}"); + verifyFormat("public <R> ArrayList<R> get() {\n}"); verifyFormat("public static <R> ArrayList<R> get() {\n}"); verifyFormat("<T extends B> T getInstance(Class<T> type);"); verifyFormat("Function<F, ? extends T> function;");