[PATCH] D53434: Java annotation declaration being handled correctly
Sam Maier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 19 06:50:41 PDT 2018
SamMaier created this revision.
Herald added a subscriber: cfe-commits.
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 {}
}
Repository:
rC Clang
https://reviews.llvm.org/D53434
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJava.cpp
Index: unittests/Format/FormatTestJava.cpp
===================================================================
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -155,6 +155,15 @@
" 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) {
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1130,6 +1130,10 @@
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53434.170197.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181019/9fa56b73/attachment.bin>
More information about the cfe-commits
mailing list