From: Nico Weber Date: Wed, 26 Nov 2014 16:43:18 +0000 (+0000) Subject: clang-format: Tweak -style=Chromium for Java files. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=450425c980137ee1e57dd77f149aecaea8300544;p=platform%2Fupstream%2Fllvm.git clang-format: Tweak -style=Chromium for Java files. 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 llvm-svn: 222839 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 9208646..9fbab27 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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; } diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index b99dec7..10149f5 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -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;");