diff options
author | Daniel Jasper <djasper@google.com> | 2015-03-12 14:44:29 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-03-12 14:44:29 +0000 |
commit | 6acf5130995d9374459f86de7e42ed0e2d9838a9 (patch) | |
tree | fab717cd00505dcf746f3213d1b9710a7f5315fd /clang/lib/Format | |
parent | bbdb712765ff65afee2a72d8c0ff9fe14d63bf8a (diff) | |
download | bcm5719-llvm-6acf5130995d9374459f86de7e42ed0e2d9838a9.tar.gz bcm5719-llvm-6acf5130995d9374459f86de7e42ed0e2d9838a9.zip |
clang-format: [Java] Support anonymous classes after = and return.
Before:
A a = new A(){public String toString(){return "NotReallyA";
}
}
;
After:
A a = return new A() {
public String toString() {
return "NotReallyA";
}
};
This fixes llvm.org/PR22878.
llvm-svn: 232042
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 28 | ||||
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 52224180d5b..cea6e8a2016 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -868,6 +868,9 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::l_square: parseSquare(); break; + case tok::kw_new: + parseNew(); + break; default: nextToken(); break; @@ -1274,6 +1277,31 @@ void UnwrappedLineParser::parseNamespace() { // FIXME: Add error handling. } +void UnwrappedLineParser::parseNew() { + assert(FormatTok->is(tok::kw_new) && "'new' expected"); + nextToken(); + if (Style.Language != FormatStyle::LK_Java) + return; + + // In Java, we can parse everything up to the parens, which aren't optional. + do { + // There should not be a ;, { or } before the new's open paren. + if (FormatTok->isOneOf(tok::semi, tok::l_brace, tok::r_brace)) + return; + + // Consume the parens. + if (FormatTok->is(tok::l_paren)) { + parseParens(); + + // If there is a class body of an anonymous class, consume that as child. + if (FormatTok->is(tok::l_brace)) + parseChildBlock(); + return; + } + nextToken(); + } while (!eof()); +} + void UnwrappedLineParser::parseForOrWhileLoop() { assert((FormatTok->Tok.is(tok::kw_for) || FormatTok->Tok.is(tok::kw_while) || FormatTok->IsForEachMacro) && diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h index 4b953ea6073..76c62cdc1d8 100644 --- a/clang/lib/Format/UnwrappedLineParser.h +++ b/clang/lib/Format/UnwrappedLineParser.h @@ -95,6 +95,7 @@ private: void parseCaseLabel(); void parseSwitch(); void parseNamespace(); + void parseNew(); void parseAccessSpecifier(); void parseEnum(); void parseJavaEnumBody(); |