]> granicus.if.org Git - clang/commitdiff
clang-format/java: Unbreak genenrics formatting after r299952.
authorNico Weber <nicolasweber@gmx.de>
Wed, 27 Sep 2017 17:57:50 +0000 (17:57 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 27 Sep 2017 17:57:50 +0000 (17:57 +0000)
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<Bar<Baz>>> 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

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

index 6caf9716b5950ffad06b7ca31767910ca1edcdae..8fb3d84ea5ce5cbd63477f28b3c6868268cb5a8c 100644 (file)
@@ -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;
   }
index c321eadf3547ba2f0287bdcd56671066f11d4426..a49cbaab5f48e3cfc958e76e33fe37de26c16272 100644 (file)
@@ -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.<B>DoSomething();
+    // A.<B<C<...>>>DoSomething();
     return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
     return false;
index 408fdaa85ada2ea5f2ba9459f8c56aee654f8571..2f376f765d66de27ff7142210104ee31fc2d0d03 100644 (file)
@@ -333,6 +333,11 @@ TEST_F(FormatTestJava, Generics) {
   verifyFormat("Iterable<? extends SomeObject> a;");
 
   verifyFormat("A.<B>doSomething();");
+  verifyFormat("A.<B<C>>doSomething();");
+  verifyFormat("A.<B<C<D>>>doSomething();");
+  verifyFormat("A.<B<C<D<E>>>>doSomething();");
+
+  verifyFormat("OrderedPair<String, List<Box<Integer>>> p = null;");
 
   verifyFormat("@Override\n"
                "public Map<String, ?> getAll() {}");