From: Hans Wennborg Date: Fri, 19 Oct 2018 16:19:52 +0000 (+0000) Subject: Java annotation declaration being handled correctly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed20274f7146fc838714fad107dcaab1ca81b092;p=clang Java annotation declaration being handled correctly Previously, Java annotation declarations (@interface AnnotationName) were being handled as ObjC interfaces. This caused the brace formatting to mess up, so that when you had a class with an interface defined in it, it would indent the final brace of the class. It used to format this class like so: class A { @interface B {} } But will now just skip the @interface and format it like so: class A { @interface B {} } Patch by Sam Maier! Differential Revision: https://reviews.llvm.org/D53434 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344789 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 4debdd15ba..3cd3c8f9cd 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1130,6 +1130,10 @@ void UnwrappedLineParser::parseStructuralElement() { nextToken(); parseBracedList(); break; + } else if (Style.Language == FormatStyle::LK_Java && + FormatTok->is(Keywords.kw_interface)) { + nextToken(); + break; } switch (FormatTok->Tok.getObjCKeywordID()) { case tok::objc_public: diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index aee8a993fe..f12d7fba50 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -155,6 +155,15 @@ TEST_F(FormatTestJava, ClassDeclarations) { " void doStuff(int theStuff);\n" " void doMoreStuff(int moreStuff);\n" "}"); + verifyFormat("class A {\n" + " public @interface SomeInterface {\n" + " int stuff;\n" + " void doMoreStuff(int moreStuff);\n" + " }\n" + "}"); + verifyFormat("class A {\n" + " public @interface SomeInterface {}\n" + "}"); } TEST_F(FormatTestJava, AnonymousClasses) {