From 61d81973c16131e3b9298c4931eb59bbe73dbed2 Mon Sep 17 00:00:00 2001 From: Daniel Jasper 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 function; llvm-svn: 221976 --- clang/lib/Format/Format.cpp | 1 + clang/lib/Format/TokenAnnotator.cpp | 14 ++++++-------- clang/unittests/Format/FormatTestJava.cpp | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 74adaf7..740adb2 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/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/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8ec8f58..f926beb 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 0ee398a..650c0af 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -203,6 +203,7 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("public static ArrayList get() {\n}"); verifyFormat(" T getInstance(Class type);"); + verifyFormat("Function function;"); } TEST_F(FormatTestJava, StringConcatenation) { -- 2.7.4