clang-format: [Java] Support annotations with parameters.

Before:
  @SuppressWarnings
  (value = "unchecked") public void doSomething() { .. }

After:
  @SuppressWarnings(value = "unchecked")
  public void doSomething() { .. }

llvm-svn: 220279
This commit is contained in:
Daniel Jasper 2014-10-21 09:25:39 +00:00
parent 38e6d45a46
commit f1f0c35632
2 changed files with 8 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;");
}