r225142 - clang-format: [Java] Fix incorrect recognition of annonymous classes.
Daniel Jasper
djasper at google.com
Sun Jan 4 12:40:52 PST 2015
Author: djasper
Date: Sun Jan 4 14:40:51 2015
New Revision: 225142
URL: http://llvm.org/viewvc/llvm-project?rev=225142&view=rev
Log:
clang-format: [Java] Fix incorrect recognition of annonymous classes.
Before:
someFunction(new Runnable() { public void run() { System.out.println(42);
}
});
After:
someFunction(new Runnable() {
public void run() {
System.out.println(42);
}
});
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=225142&r1=225141&r2=225142&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sun Jan 4 14:40:51 2015
@@ -1033,6 +1033,8 @@ void UnwrappedLineParser::parseParens()
switch (FormatTok->Tok.getKind()) {
case tok::l_paren:
parseParens();
+ if (Style.Language == FormatStyle::LK_Java && FormatTok->is(tok::l_brace))
+ parseChildBlock();
break;
case tok::r_paren:
nextToken();
@@ -1043,12 +1045,11 @@ void UnwrappedLineParser::parseParens()
case tok::l_square:
tryToParseLambda();
break;
- case tok::l_brace: {
+ case tok::l_brace:
if (!tryToParseBracedList()) {
parseChildBlock();
}
break;
- }
case tok::at:
nextToken();
if (FormatTok->Tok.is(tok::l_brace))
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=225142&r1=225141&r2=225142&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Jan 4 14:40:51 2015
@@ -387,6 +387,11 @@ TEST_F(FormatTestJava, FormatsInnerBlock
" System.out.println(42);\n"
" }\n"
"}, someOtherParameter);");
+ verifyFormat("someFunction(new Runnable() {\n"
+ " public void run() {\n"
+ " System.out.println(42);\n"
+ " }\n"
+ "});");
verifyFormat("someObject.someFunction(\n"
" new Runnable() {\n"
" @Override\n"
More information about the cfe-commits
mailing list