From: Nico Weber Date: Wed, 27 Sep 2017 17:57:50 +0000 (+0000) Subject: clang-format/java: Unbreak genenrics formatting after r299952. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d80dab7c4537912c95d6df6e12c76ba4f72cd44c;p=clang clang-format/java: Unbreak genenrics formatting after r299952. https://reviews.llvm.org/rL299952 merged '>>>' tokens into a single JavaRightLogicalShift token. This broke formatting of generics nested more than two deep, e.g. Foo>> because the '>>>' now weren't three '>' for parseAngle(). Luckily, just deleting JavaRightLogicalShift fixes things without breaking the test added in r299952, so do that. https://reviews.llvm.org/D38291 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314325 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/FormatTokenLexer.cpp b/lib/Format/FormatTokenLexer.cpp index 6caf9716b5..8fb3d84ea5 100644 --- a/lib/Format/FormatTokenLexer.cpp +++ b/lib/Format/FormatTokenLexer.cpp @@ -96,12 +96,8 @@ void FormatTokenLexer::tryMergePreviousTokens() { } if (Style.Language == FormatStyle::LK_Java) { - static const tok::TokenKind JavaRightLogicalShift[] = { - tok::greater, tok::greater, tok::greater}; static const tok::TokenKind JavaRightLogicalShiftAssign[] = { tok::greater, tok::greater, tok::greaterequal}; - if (tryMergeTokens(JavaRightLogicalShift, TT_BinaryOperator)) - return; if (tryMergeTokens(JavaRightLogicalShiftAssign, TT_BinaryOperator)) return; } diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c321eadf35..a49cbaab5f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -47,7 +47,7 @@ private: if (NonTemplateLess.count(CurrentToken->Previous)) return false; - const FormatToken &Previous = *CurrentToken->Previous; + const FormatToken &Previous = *CurrentToken->Previous; // The '<'. if (Previous.Previous) { if (Previous.Previous->Tok.isLiteral()) return false; @@ -2323,7 +2323,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Left.is(TT_TemplateCloser) && Left.MatchingParen && Left.MatchingParen->Previous && Left.MatchingParen->Previous->is(tok::period)) - // A.DoSomething(); + // A.>>DoSomething(); return false; if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square)) return false; diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 408fdaa85a..2f376f765d 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -333,6 +333,11 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("Iterable a;"); verifyFormat("A.doSomething();"); + verifyFormat("A.>doSomething();"); + verifyFormat("A.>>doSomething();"); + verifyFormat("A.>>>doSomething();"); + + verifyFormat("OrderedPair>> p = null;"); verifyFormat("@Override\n" "public Map getAll() {}");