Browse Source

Implemented array initializer formatting.

pull/32/merge
Mike Krüger 13 years ago
parent
commit
d8314d7e49
  1. 26
      ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Expressions.cs
  2. 31
      ICSharpCode.NRefactory.Tests/FormattingTests/TestExpressionFormatting.cs

26
ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Expressions.cs

@ -368,7 +368,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -368,7 +368,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (!objectCreateExpression.Type.IsNull)
objectCreateExpression.Type.AcceptVisitor(this);
objectCreateExpression.Initializer.AcceptVisitor(this);
FormatArguments(objectCreateExpression);
}
@ -398,7 +398,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -398,7 +398,29 @@ namespace ICSharpCode.NRefactory.CSharp
init.AcceptVisitor(this);
}
} else {
base.VisitArrayInitializerExpression(arrayInitializerExpression);
foreach (var child in arrayInitializerExpression.Children) {
if (child.Role == Roles.LBrace) {
FixOpenBrace(policy.ArrayInitializerBraceStyle, child);
curIndent.Push(IndentType.Block);
continue;
}
if (child.Role == Roles.RBrace) {
curIndent.Pop();
FixClosingBrace(policy.ArrayInitializerBraceStyle, child);
continue;
}
if (child.Role == Roles.Expression) {
if (child.PrevSibling.Role == Roles.NewLine)
FixIndentation(child);
if (child.PrevSibling.Role == Roles.Comma)
ForceSpaceBefore(child, true);
if (child.NextSibling.Role == Roles.Comma)
ForceSpacesAfter(child, false);
continue;
}
child.AcceptVisitor(this);
}
}
}

31
ICSharpCode.NRefactory.Tests/FormattingTests/TestExpressionFormatting.cs

@ -78,6 +78,37 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -78,6 +78,37 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
}
}");
}
[Test]
public void TestArrayInitializer ()
{
var policy = FormattingOptionsFactory.CreateMono ();
Test (policy, @"using System.Collections.Generic;
class Test
{
void Init ()
{
var list = new List<int> {
1, 2,
3 , 4
};
}
}", @"using System.Collections.Generic;
class Test
{
void Init ()
{
var list = new List<int> {
1, 2,
3, 4
};
}
}");
}
}
}

Loading…
Cancel
Save