Author: hans Date: Fri Oct 19 09:19:52 2018 New Revision: 344789 URL: http://llvm.org/viewvc/llvm-project?rev=344789&view=rev Log: 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 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=344789&r1=344788&r2=344789&view=diff ============================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Oct 19 09:19:52 2018 @@ -1130,6 +1130,10 @@ void UnwrappedLineParser::parseStructura 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: Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=344789&r1=344788&r2=344789&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJava.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJava.cpp Fri Oct 19 09:19:52 2018 @@ -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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits