r220279 - clang-format: [Java] Support annotations with parameters.
Daniel Jasper
djasper at google.com
Tue Oct 21 02:25:40 PDT 2014
Author: djasper
Date: Tue Oct 21 04:25:39 2014
New Revision: 220279
URL: http://llvm.org/viewvc/llvm-project?rev=220279&view=rev
Log:
clang-format: [Java] Support annotations with parameters.
Before:
@SuppressWarnings
(value = "unchecked") public void doSomething() { .. }
After:
@SuppressWarnings(value = "unchecked")
public void doSomething() { .. }
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=220279&r1=220278&r2=220279&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Oct 21 04:25:39 2014
@@ -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(con
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;
}
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=220279&r1=220278&r2=220279&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Tue Oct 21 04:25:39 2014
@@ -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;");
}
More information about the cfe-commits
mailing list