From: Daniel Jasper Date: Sun, 2 Nov 2014 22:13:03 +0000 (+0000) Subject: clang-format: [Java] Don't break imports. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa97742e7ac3ca4631291a888451643eece11fb3;p=clang clang-format: [Java] Don't break imports. This fixes llvm.org/PR21453. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221112 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1056d43420..5eb6e10554 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 2b05ca4937..126b163c60 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -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