From 53d21603cbf816f37901b1c5bff8084146c0fd97 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 21 Oct 2014 09:25:39 +0000 Subject: [PATCH] clang-format: [Java] Support annotations with parameters. Before: @SuppressWarnings (value = "unchecked") public void doSomething() { .. } After: @SuppressWarnings(value = "unchecked") public void doSomething() { .. } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220279 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 5 ++++- unittests/Format/FormatTestJava.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ce3d899900..4f32b9f9eb 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -184,6 +184,8 @@ private: if (Left->Type == TT_AttributeParen) CurrentToken->Type = TT_AttributeParen; + if (Left->Previous && Left->Previous->Type == TT_JavaAnnotation) + CurrentToken->Type = TT_JavaAnnotation; if (!HasMultipleLines) Left->PackingKind = PPK_Inconclusive; @@ -1791,7 +1793,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, Left.Previous->is(tok::char_constant)) return true; } else if (Style.Language == FormatStyle::LK_Java) { - if (Left.Type == TT_JavaAnnotation && Line.MightBeFunctionDecl) + if (Left.Type == TT_JavaAnnotation && Right.isNot(tok::l_paren) && + Line.MightBeFunctionDecl) return true; } diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 18d945d0af..cf48a7a11d 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -70,6 +70,10 @@ TEST_F(FormatTestJava, Annotations) { verifyFormat("@Override\n" "@Nullable\n" "public String getNameIfPresent() {\n}"); + + verifyFormat("@SuppressWarnings(value = \"unchecked\")\n" + "public void doSomething() {\n}"); + verifyFormat("@Partial @Mock DataLoader loader;"); } -- 2.40.0