From 7bd618f5aa91fff0dbff9350793a3e06afe3f4b9 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 2 Nov 2014 21:52:57 +0000 Subject: [PATCH] clang-format: [Java] Support generics with "?". Before: @Override public Map < String, ? > getAll() { // ... } After: @Override public Map getAll() { // ... } This fixes llvm.org/PR21454. llvm-svn: 221109 --- clang/lib/Format/TokenAnnotator.cpp | 9 ++++++++- clang/unittests/Format/FormatTestJava.cpp | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ebcad05..a131397 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -64,7 +64,10 @@ private: return true; } if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace, - tok::colon, tok::question)) + tok::colon)) + return false; + if (CurrentToken->is(tok::question) && + Style.Language != FormatStyle::LK_Java) 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 @@ -364,6 +367,10 @@ 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 62b3e92..bcbf283 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -120,6 +120,10 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("Iterable a;"); verifyFormat("A.doSomething();"); + + verifyFormat("@Override\n" + "public Map getAll() {\n" + "}"); } TEST_F(FormatTestJava, StringConcatenation) { -- 2.7.4