From: Daniel Jasper Date: Sun, 2 Nov 2014 19:21:48 +0000 (+0000) Subject: clang-format: [Java] Support try/catch/finally blocks. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=054b75770a050e3c9c5e4653c1d75746e2007cee;p=clang clang-format: [Java] Support try/catch/finally blocks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221104 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 256fc28720..aa1bfdc725 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/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/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 73a1848e62..62b3e92edc 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/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