diff --git a/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs b/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs index 5794d76353..dd7f55424f 100644 --- a/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs +++ b/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs @@ -1763,8 +1763,12 @@ namespace ICSharpCode.NRefactory.CSharp } curIndent.ExtraSpaces -= extraSpaces; } - if (methodClosingParenthesesOnNewLine) { - FixStatementIndentation(rParToken.StartLocation); + if (!rParToken.IsNull) { + if (methodClosingParenthesesOnNewLine) { + FixStatementIndentation(rParToken.StartLocation); + } else { + ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses); + } } } else { foreach (var arg in arguments) { @@ -1777,7 +1781,18 @@ namespace ICSharpCode.NRefactory.CSharp } 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) { foreach (CSharpTokenNode comma in rParToken.Parent.Children.Where(n => n.Role == Roles.Comma)) { diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs index 9829479a23..2c60d503d9 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs +++ b/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); + } +}"); + } + } }