From 8379107afe9ebbaecae13123515af64cc4dab1e2 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 3 Dec 2014 13:20:49 +0000 Subject: [PATCH] clang-format: Fix expression parser not closing stuff at end of stmt. Uncovered by a Java test case: Before: public some.package.Type someFunction( // comment int parameter) {} After: public some.package.Type someFunction( // comment int parameter) {} llvm-svn: 223228 --- clang/lib/Format/TokenAnnotator.cpp | 21 +++++++++++---------- clang/unittests/Format/FormatTestJava.cpp | 5 +++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6c04a01..3b04e49 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1147,16 +1147,7 @@ public: (CurrentPrecedence != -1 && CurrentPrecedence < Precedence) || (CurrentPrecedence == prec::Conditional && Precedence == prec::Assignment && Current->is(tok::colon))) { - if (LatestOperator) { - LatestOperator->LastOperator = true; - if (Precedence == PrecedenceArrowAndPeriod) { - // Call expressions don't have a binary operator precedence. - addFakeParenthesis(Start, prec::Unknown); - } else { - addFakeParenthesis(Start, prec::Level(Precedence)); - } - } - return; + break; } // Consume scopes: (), [], <> and {} @@ -1176,6 +1167,16 @@ public: next(/*SkipPastLeadingComments=*/Precedence > 0); } } + + if (LatestOperator && (Current || Precedence > 0)) { + LatestOperator->LastOperator = true; + if (Precedence == PrecedenceArrowAndPeriod) { + // Call expressions don't have a binary operator precedence. + addFakeParenthesis(Start, prec::Unknown); + } else { + addFakeParenthesis(Start, prec::Level(Precedence)); + } + } } private: diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index ad80d13..5b677ef 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -84,6 +84,11 @@ TEST_F(FormatTestJava, Chromium) { getChromiumStyle(FormatStyle::LK_Java)); } +TEST_F(FormatTestJava, QualifiedNames) { + verifyFormat("public some.package.Type someFunction( // comment\n" + " int parameter) {}"); +} + TEST_F(FormatTestJava, ClassKeyword) { verifyFormat("SomeClass.class.getName();"); verifyFormat("Class c = SomeClass.class;"); -- 2.7.4