Browse Source

* Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs: Improved

collection initializer output.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4407 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 16 years ago
parent
commit
80b46b6b8d
  1. 23
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

23
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -2794,9 +2794,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2794,9 +2794,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data)
{
outputFormatter.PrintToken (Tokens.OpenCurlyBrace);
if (arrayInitializerExpression.CreateExpressions.Count == 1) {
outputFormatter.Space ();
this.AppendCommaSeparatedList(arrayInitializerExpression.CreateExpressions);
} else {
outputFormatter.IndentationLevel++;
outputFormatter.NewLine ();
outputFormatter.Indent ();
}
this.AppendCommaSeparatedList (arrayInitializerExpression.CreateExpressions, true);
if (arrayInitializerExpression.CreateExpressions.Count == 1) {
outputFormatter.Space ();
} else {
outputFormatter.IndentationLevel--;
outputFormatter.NewLine();
outputFormatter.Indent();
}
outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
return null;
}
@ -2916,6 +2928,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2916,6 +2928,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
public void AppendCommaSeparatedList<T>(ICollection<T> list) where T : class, INode
{
AppendCommaSeparatedList(list, false);
}
public void AppendCommaSeparatedList<T>(ICollection<T> list, bool alwaysBreakLine) where T : class, INode
{
if (list != null) {
int i = 0;
@ -2923,11 +2940,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2923,11 +2940,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
node.AcceptVisitor(this, null);
if (i + 1 < list.Count) {
PrintFormattedComma();
}
if ((i + 1) % 10 == 0) {
if (alwaysBreakLine || (i + 1) % 10 == 0) {
outputFormatter.NewLine();
outputFormatter.Indent();
}
}
i++;
}
}

Loading…
Cancel
Save