From: Daniel Jasper Date: Wed, 26 Nov 2014 11:20:43 +0000 (+0000) Subject: clang-format: [Java] Fix breaking after annotations. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd89313ce417c08e209f579a97b350f73a7b4102;p=clang clang-format: [Java] Fix breaking after annotations. Before: @Annotation1 // comment @Annotation2 class C {} After: @Annotation1 // comment @Annotation2 class C {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222825 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 3daea77f96..9b32c35601 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -864,7 +864,8 @@ private: Current.Previous->is(tok::at) && Current.isNot(Keywords.kw_interface)) { const FormatToken &AtToken = *Current.Previous; - if (!AtToken.Previous || AtToken.Previous->is(TT_LeadingJavaAnnotation)) + const FormatToken *Previous = AtToken.getPreviousNonComment(); + if (!Previous || Previous->is(TT_LeadingJavaAnnotation)) Current.Type = TT_LeadingJavaAnnotation; else Current.Type = TT_JavaAnnotation; diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 946ae32d87..5c80babf26 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -206,6 +206,9 @@ TEST_F(FormatTestJava, Annotations) { verifyFormat("@Override\n" "@Nullable\n" "public String getNameIfPresent() {}"); + verifyFormat("@Override // comment\n" + "@Nullable\n" + "public String getNameIfPresent() {}"); verifyFormat("@SuppressWarnings(value = \"unchecked\")\n" "public void doSomething() {}");