Browse Source

[Formatting] Fixed some formatting bugs.

newNRvisualizers
Mike Krüger 13 years ago
parent
commit
6126d9bd77
  1. 21
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 90
      ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs

21
ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs

@ -1763,8 +1763,12 @@ namespace ICSharpCode.NRefactory.CSharp
} }
curIndent.ExtraSpaces -= extraSpaces; curIndent.ExtraSpaces -= extraSpaces;
} }
if (methodClosingParenthesesOnNewLine) { if (!rParToken.IsNull) {
FixStatementIndentation(rParToken.StartLocation); if (methodClosingParenthesesOnNewLine) {
FixStatementIndentation(rParToken.StartLocation);
} else {
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
}
} }
} else { } else {
foreach (var arg in arguments) { foreach (var arg in arguments) {
@ -1777,7 +1781,18 @@ namespace ICSharpCode.NRefactory.CSharp
} }
arg.AcceptVisitor(this); arg.AcceptVisitor(this);
} }
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses); if (!rParToken.IsNull) {
if (methodCallArgumentWrapping == Wrapping.DoNotWrap) {
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
} else {
bool sameLine = rParToken.GetPrevNode().StartLocation.Line == rParToken.StartLocation.Line;
if (sameLine) {
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
} else {
FixStatementIndentation(rParToken.StartLocation);
}
}
}
} }
if (!rParToken.IsNull) { if (!rParToken.IsNull) {
foreach (CSharpTokenNode comma in rParToken.Parent.Children.Where(n => n.Role == Roles.Comma)) { foreach (CSharpTokenNode comma in rParToken.Parent.Children.Where(n => n.Role == Roles.Comma)) {

90
ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs

@ -412,5 +412,95 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
} }
[Test()]
public void TestMethodCallArgumentWrappingDoNotChangeCase1()
{
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
void TestMe ()
{
Foo (
1,
2,
3
);
}
}",
@"class Test
{
void TestMe ()
{
Foo (
1,
2,
3
);
}
}");
}
[Test()]
public void TestMethodCallArgumentWrappingDoNotChangeCase2()
{
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
void TestMe ()
{
Foo (1,
2,
3
);
}
}",
@"class Test
{
void TestMe ()
{
Foo (1,
2,
3
);
}
}");
}
[Test()]
public void TestMethodCallArgumentWrappingDoNotChangeCase3()
{
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
void TestMe ()
{
Foo (1,
2,
3 );
}
}",
@"class Test
{
void TestMe ()
{
Foo (1,
2,
3);
}
}");
}
} }
} }

Loading…
Cancel
Save