From fa67c1ee87d4fee01362cb636b28702352d3222a Mon Sep 17 00:00:00 2001
From: Daniel Jasper <djasper@google.com>
Date: Wed, 26 Nov 2014 18:03:42 +0000
Subject: [PATCH] clang-format: [Java] Don't line-wrap package declarations.

This fixes llvm.org/PR21677.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222843 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Format/FormatToken.h            | 2 ++
 lib/Format/TokenAnnotator.cpp       | 6 ++++--
 unittests/Format/FormatTestJava.cpp | 5 +++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h
index 732096bbcfb..11c4925d010 100644
--- a/lib/Format/FormatToken.h
+++ b/lib/Format/FormatToken.h
@@ -547,6 +547,7 @@ struct AdditionalKeywords {
     kw_implements = &IdentTable.get("implements");
     kw_instanceof = &IdentTable.get("instanceof");
     kw_interface = &IdentTable.get("interface");
+    kw_package = &IdentTable.get("package");
     kw_synchronized = &IdentTable.get("synchronized");
     kw_throws = &IdentTable.get("throws");
 
@@ -573,6 +574,7 @@ struct AdditionalKeywords {
   IdentifierInfo *kw_implements;
   IdentifierInfo *kw_instanceof;
   IdentifierInfo *kw_interface;
+  IdentifierInfo *kw_package;
   IdentifierInfo *kw_synchronized;
   IdentifierInfo *kw_throws;
 
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index ccaac1bb284..93ac447ff1c 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -612,8 +612,10 @@ public:
     // definitions (code.google.com/p/protobuf) or missing "#" (either way we
     // should not break the line).
     IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo();
-    if (Info && Info->getPPKeywordID() == tok::pp_import &&
-        CurrentToken->Next) {
+    if ((Style.Language == FormatStyle::LK_Java &&
+         CurrentToken->is(Keywords.kw_package)) ||
+        (Info && Info->getPPKeywordID() == tok::pp_import &&
+         CurrentToken->Next)) {
       next();
       parseIncludeDirective();
       return LT_ImportStatement;
diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp
index 10149f59b94..829ced7b02e 100644
--- a/unittests/Format/FormatTestJava.cpp
+++ b/unittests/Format/FormatTestJava.cpp
@@ -319,6 +319,11 @@ TEST_F(FormatTestJava, SynchronizedKeyword) {
                "}");
 }
 
+TEST_F(FormatTestJava, PackageDeclarations) {
+  verifyFormat("package some.really.loooooooooooooooooooooong.package;",
+               getStyleWithColumns(50));
+}
+
 TEST_F(FormatTestJava, ImportDeclarations) {
   verifyFormat("import some.really.loooooooooooooooooooooong.imported.Class;",
                getStyleWithColumns(50));
-- 
GitLab