From a3ddf86dd49eacdbc3ba43118ab7606157f56dd0 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 2 Nov 2014 19:21:48 +0000 Subject: [PATCH] clang-format: [Java] Support try/catch/finally blocks. llvm-svn: 221104 --- clang/lib/Format/UnwrappedLineParser.cpp | 3 ++- clang/unittests/Format/FormatTestJava.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 256fc28..aa1bfdc 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1174,7 +1174,8 @@ void UnwrappedLineParser::parseTryCatch() { --Line->Level; } while (FormatTok->is(tok::kw_catch) || - (Style.Language == FormatStyle::LK_JavaScript && + ((Style.Language == FormatStyle::LK_Java || + Style.Language == FormatStyle::LK_JavaScript) && FormatTok->TokenText == "finally")) { nextToken(); while (FormatTok->isNot(tok::l_brace)) { diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 73a1848..62b3e92 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -127,5 +127,31 @@ TEST_F(FormatTestJava, StringConcatenation) { " + \"cde\";"); } +TEST_F(FormatTestJava, TryCatchFinally) { + verifyFormat("try {\n" + " Something();\n" + "} catch (SomeException e) {\n" + " HandleException(e);\n" + "}"); + verifyFormat("try {\n" + " Something();\n" + "} finally {\n" + " AlwaysDoThis();\n" + "}"); + verifyFormat("try {\n" + " Something();\n" + "} catch (SomeException e) {\n" + " HandleException(e);\n" + "} finally {\n" + " AlwaysDoThis();\n" + "}"); + + verifyFormat("try {\n" + " Something();\n" + "} catch (SomeException | OtherException e) {\n" + " HandleException(e);\n" + "}"); +} + } // end namespace tooling } // end namespace clang -- 2.7.4