From e47c3133f2602b52d84a54bddf51c0f2e2606f6e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 26 Nov 2014 16:43:18 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222839 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 17 +++++++++++------ unittests/Format/FormatTestJava.cpp | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 92086461d4..9fbab27bb5 100644 --- a/lib/Format/Format.cpp +++ b/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/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index b99dec73ee..10149f59b9 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/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;"); -- 2.40.0