]> granicus.if.org Git - clang/commitdiff
clang-format: Tweak -style=Chromium for Java files.
authorNico Weber <nicolasweber@gmx.de>
Wed, 26 Nov 2014 16:43:18 +0000 (16:43 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 26 Nov 2014 16:43:18 +0000 (16:43 +0000)
For Java, don't do any of the deviations from Google Style that Chromium style
does for C++.

Chromium's Java follows Android Java style [1], which is roughly Google Java
style with an indent of 4 and a continuation indent of 8.

1: https://source.android.com/source/code-style.html

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222839 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTestJava.cpp

index 92086461d489aee9b5bc6744d226f7a517110731..9fbab27bb51ea9a03c61155a59bf31ff14c2a255 100644 (file)
@@ -435,12 +435,17 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
 
 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
   FormatStyle ChromiumStyle = getGoogleStyle(Language);
-  ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false;
-  ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
-  ChromiumStyle.AllowShortIfStatementsOnASingleLine = false;
-  ChromiumStyle.AllowShortLoopsOnASingleLine = false;
-  ChromiumStyle.BinPackParameters = false;
-  ChromiumStyle.DerivePointerAlignment = false;
+  if (Language == FormatStyle::LK_Java) {
+    ChromiumStyle.IndentWidth = 4;
+    ChromiumStyle.ContinuationIndentWidth = 8;
+  } else {
+    ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false;
+    ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
+    ChromiumStyle.AllowShortIfStatementsOnASingleLine = false;
+    ChromiumStyle.AllowShortLoopsOnASingleLine = false;
+    ChromiumStyle.BinPackParameters = false;
+    ChromiumStyle.DerivePointerAlignment = false;
+  }
   return ChromiumStyle;
 }
 
index b99dec73eefbfc54a39e5ba3f7e76c35a30fa93f..10149f59b94b8ee9ba602dc48138fb30ed2954e7 100644 (file)
@@ -69,6 +69,21 @@ TEST_F(FormatTestJava, FormatsInstanceOfLikeOperators) {
                Style);
 }
 
+TEST_F(FormatTestJava, Chromium) {
+  verifyFormat("class SomeClass {\n"
+               "    void f() {}\n"
+               "    int g() {\n"
+               "        return 0;\n"
+               "    }\n"
+               "    void h() {\n"
+               "        while (true) f();\n"
+               "        for (;;) f();\n"
+               "        if (true) f();\n"
+               "    }\n"
+               "}",
+               getChromiumStyle(FormatStyle::LK_Java));
+}
+
 TEST_F(FormatTestJava, ClassKeyword) {
   verifyFormat("SomeClass.class.getName();");
   verifyFormat("Class c = SomeClass.class;");