From 80b46b6b8dcac69ebeb56ccfaa0257a323fcd6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Tue, 7 Jul 2009 07:48:02 +0000 Subject: [PATCH] * 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 --- .../CSharp/CSharpOutputVisitor.cs | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs index dc28e7a71f..07f35a3b15 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs @@ -2793,10 +2793,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data) { - outputFormatter.PrintToken(Tokens.OpenCurlyBrace); - outputFormatter.Space(); - this.AppendCommaSeparatedList(arrayInitializerExpression.CreateExpressions); - outputFormatter.Space(); + outputFormatter.PrintToken (Tokens.OpenCurlyBrace); + if (arrayInitializerExpression.CreateExpressions.Count == 1) { + outputFormatter.Space (); + } 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 } public void AppendCommaSeparatedList(ICollection list) where T : class, INode + { + AppendCommaSeparatedList(list, false); + } + + public void AppendCommaSeparatedList(ICollection list, bool alwaysBreakLine) where T : class, INode { if (list != null) { int i = 0; @@ -2923,10 +2940,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter node.AcceptVisitor(this, null); if (i + 1 < list.Count) { PrintFormattedComma(); - } - if ((i + 1) % 10 == 0) { - outputFormatter.NewLine(); - outputFormatter.Indent(); + if (alwaysBreakLine || (i + 1) % 10 == 0) { + outputFormatter.NewLine(); + outputFormatter.Indent(); + } } i++; }