clang-format: [Java] Don't break imports.
authorDaniel Jasper <djasper@google.com>
Sun, 2 Nov 2014 22:13:03 +0000 (22:13 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 2 Nov 2014 22:13:03 +0000 (22:13 +0000)
This fixes llvm.org/PR21453.

llvm-svn: 221112

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

index 1056d43..5eb6e10 100644 (file)
@@ -541,8 +541,8 @@ private:
       }
     } else {
       while (CurrentToken) {
-        if (CurrentToken->is(tok::string_literal))
-          // Mark these string literals as "implicit" literals, too, so that
+        if (CurrentToken->isNot(tok::comment))
+          // Mark these tokens as "implicit" string literals, so that
           // they are not split or line-wrapped.
           CurrentToken->Type = TT_ImplicitStringLiteral;
         next();
@@ -622,7 +622,7 @@ public:
     // should not break the line).
     IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo();
     if (Info && Info->getPPKeywordID() == tok::pp_import &&
-        CurrentToken->Next && CurrentToken->Next->is(tok::string_literal)) {
+        CurrentToken->Next) {
       next();
       parseIncludeDirective();
       return LT_Other;
index 2b05ca4..126b163 100644 (file)
@@ -163,5 +163,10 @@ TEST_F(FormatTestJava, SynchronizedKeyword) {
                "}");
 }
 
+TEST_F(FormatTestJava, ImportDeclarations) {
+  verifyFormat("import some.really.loooooooooooooooooooooong.imported.Class;",
+               getStyleWithColumns(50));
+}
+
 } // end namespace tooling
 } // end namespace clang