r221104 - clang-format: [Java] Support try/catch/finally blocks.
Daniel Jasper
djasper at google.com
Sun Nov 2 11:21:48 PST 2014
Author: djasper
Date: Sun Nov 2 13:21:48 2014
New Revision: 221104
URL: http://llvm.org/viewvc/llvm-project?rev=221104&view=rev
Log:
clang-format: [Java] Support try/catch/finally blocks.
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=221104&r1=221103&r2=221104&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sun Nov 2 13:21:48 2014
@@ -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)) {
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=221104&r1=221103&r2=221104&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Nov 2 13:21:48 2014
@@ -127,5 +127,31 @@ TEST_F(FormatTestJava, StringConcatenati
" + \"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
More information about the cfe-commits
mailing list