]> granicus.if.org Git - clang/commitdiff
Java annotation declaration being handled correctly
authorHans Wennborg <hans@hanshq.net>
Fri, 19 Oct 2018 16:19:52 +0000 (16:19 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 19 Oct 2018 16:19:52 +0000 (16:19 +0000)
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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJava.cpp

index 4debdd15ba7c5ed90d811073f0398e3ace81b2ac..3cd3c8f9cdf69f2304ef58cf2ee4c7e7d9220567 100644 (file)
@@ -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:
index aee8a993fe600674855b1e75ea1c297c787dded8..f12d7fba50593a480d0c382dd6feede12de582fa 100644 (file)
@@ -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) {