clang-format: Fix expression parser not closing stuff at end of stmt.
authorDaniel Jasper <djasper@google.com>
Wed, 3 Dec 2014 13:20:49 +0000 (13:20 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 3 Dec 2014 13:20:49 +0000 (13:20 +0000)
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
clang/unittests/Format/FormatTestJava.cpp

index 6c04a01..3b04e49 100644 (file)
@@ -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:
index ad80d13..5b677ef 100644 (file)
@@ -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;");