Before:
try
(SomeResource rs = someFunction()) {
Something();
}
After:
try (SomeResource rs = someFunction()) {
Something();
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225973
91177308-0d34-0410-b5e6-
96231b3b80d8
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
(Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
tok::kw_switch, tok::kw_case) ||
- (Left.isOneOf(tok::kw_catch, tok::kw_new, tok::kw_delete) &&
+ (Left.isOneOf(tok::kw_try, tok::kw_catch, tok::kw_new,
+ tok::kw_delete) &&
(!Left.Previous || Left.Previous->isNot(tok::period))) ||
Left.IsForEachMacro)) ||
(Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
nextToken();
}
}
+ // Parse try with resource.
+ if (Style.Language == FormatStyle::LK_Java && FormatTok->is(tok::l_paren)) {
+ parseParens();
+ }
if (FormatTok->is(tok::l_brace)) {
CompoundStatementIndenter Indenter(this, Style, Line->Level);
parseBlock(/*MustBeDeclaration=*/false);
"}");
}
+TEST_F(FormatTestJava, TryWithResources) {
+ verifyFormat("try (SomeResource rs = someFunction()) {\n"
+ " Something();\n"
+ "}");
+ verifyFormat("try (SomeResource rs = someFunction()) {\n"
+ " Something();\n"
+ "} catch (SomeException e) {\n"
+ " HandleException(e);\n"
+ "}");
+}
+
TEST_F(FormatTestJava, SynchronizedKeyword) {
verifyFormat("synchronized (mData) {\n"
" // ...\n"