Browse Source

Added some formatting options.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
198c085d72
  1. 10
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 33
      ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs
  3. 4
      ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs
  4. 69
      ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs

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

@ -1632,7 +1632,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1632,7 +1632,7 @@ namespace ICSharpCode.NRefactory.CSharp
var oce = node as ObjectCreateExpression;
methodCallArgumentWrapping = policy.MethodCallArgumentWrapping;
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses;
methodClosingParenthesesOnNewLine = policy.MethodClosingParenthesesOnNewLine;
methodClosingParenthesesOnNewLine = policy.MethodCallClosingParenthesesOnNewLine;
spaceWithinMethodCallParentheses = policy.SpacesWithinNewParentheses;
spaceAfterMethodCallParameterComma = policy.SpaceAfterNewParameterComma;
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeNewParameterComma;
@ -1643,7 +1643,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1643,7 +1643,7 @@ namespace ICSharpCode.NRefactory.CSharp
InvocationExpression invocationExpression = node as InvocationExpression;
methodCallArgumentWrapping = policy.MethodCallArgumentWrapping;
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses;
methodClosingParenthesesOnNewLine = policy.MethodClosingParenthesesOnNewLine;
methodClosingParenthesesOnNewLine = policy.MethodCallClosingParenthesesOnNewLine;
spaceWithinMethodCallParentheses = policy.SpaceWithinMethodCallParentheses;
spaceAfterMethodCallParameterComma = policy.SpaceAfterMethodCallParameterComma;
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeMethodCallParameterComma;
@ -1673,7 +1673,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1673,7 +1673,8 @@ namespace ICSharpCode.NRefactory.CSharp
FixStatementIndentation(rParToken.StartLocation);
} else {
foreach (var arg in arguments) {
ForceSpacesBeforeRemoveNewLines(arg, spaceAfterMethodCallParameterComma && arg.PrevSibling.Role == Roles.Comma);
if (methodCallArgumentWrapping == Wrapping.DoNotWrap)
ForceSpacesBeforeRemoveNewLines(arg, spaceAfterMethodCallParameterComma && arg.PrevSibling.Role == Roles.Comma);
arg.AcceptVisitor(this);
}
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
@ -1704,7 +1705,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1704,7 +1705,8 @@ namespace ICSharpCode.NRefactory.CSharp
FixStatementIndentation(mt.DotToken.StartLocation);
curIndent.Pop();
} else {
ForceSpacesBeforeRemoveNewLines(mt.DotToken, false);
if (policy.ChainedMethodCallWrapping == Wrapping.DoNotWrap)
ForceSpacesBeforeRemoveNewLines(mt.DotToken, false);
}
}
}

33
ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs

@ -56,6 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -56,6 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public enum Wrapping {
DoNotChange,
DoNotWrap,
WrapAlways,
WrapIfTooLong
@ -801,7 +802,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -801,7 +802,7 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public bool MethodClosingParenthesesOnNewLine {
public bool MethodCallClosingParenthesesOnNewLine {
get;
set;
}
@ -820,6 +821,36 @@ namespace ICSharpCode.NRefactory.CSharp @@ -820,6 +821,36 @@ namespace ICSharpCode.NRefactory.CSharp
get;
set;
}
public Wrapping MethodDeclarationParameterWrapping {
get;
set;
}
public bool NewLineAferMethodDeclarationOpenParentheses {
get;
set;
}
public bool MethodDeclarationClosingParenthesesOnNewLine {
get;
set;
}
public Wrapping IndexerDeclarationParameterWrapping {
get;
set;
}
public bool NewLineAferIndexerDeclarationOpenBracket {
get;
set;
}
public bool IndexerDeclarationClosingBracketOnNewLine {
get;
set;
}
#endregion
internal CSharpFormattingOptions()

4
ICSharpCode.NRefactory.CSharp/Formatter/FormattingOptionsFactory.cs

@ -178,7 +178,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -178,7 +178,7 @@ namespace ICSharpCode.NRefactory.CSharp
ChainedMethodCallWrapping = Wrapping.WrapAlways,
MethodCallArgumentWrapping = Wrapping.WrapIfTooLong,
NewLineAferMethodCallOpenParentheses = true,
MethodClosingParenthesesOnNewLine = true,
MethodCallClosingParenthesesOnNewLine = true,
IndexerArgumentWrapping = Wrapping.WrapIfTooLong,
NewLineAferIndexerOpenBracket = false,
@ -324,7 +324,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -324,7 +324,7 @@ namespace ICSharpCode.NRefactory.CSharp
ChainedMethodCallWrapping = Wrapping.WrapAlways,
MethodCallArgumentWrapping = Wrapping.WrapIfTooLong,
NewLineAferMethodCallOpenParentheses = true,
MethodClosingParenthesesOnNewLine = true,
MethodCallClosingParenthesesOnNewLine = true,
IndexerArgumentWrapping = Wrapping.WrapIfTooLong,
NewLineAferIndexerOpenBracket = false,

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

@ -172,7 +172,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -172,7 +172,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true;
policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
@ -200,7 +200,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -200,7 +200,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = false;
policy.MethodClosingParenthesesOnNewLine = false;
policy.MethodCallClosingParenthesesOnNewLine = false;
Test(policy, @"class Test
{
@ -227,7 +227,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -227,7 +227,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.DoNotWrap;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true;
policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
@ -254,9 +254,9 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -254,9 +254,9 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
public void TestIndexerCallArgumentNoNewLineWrapping()
{
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true;
policy.IndexerArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferIndexerOpenBracket = true;
policy.IndexerClosingBracketOnNewLine = true;
Test(policy, @"class Test
{
@ -284,7 +284,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -284,7 +284,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true;
policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
@ -306,6 +306,61 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -306,6 +306,61 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
}");
}
[Ignore("Not Implemented")]
[Test()]
public void TestMethodDeclarationParameterNewLineWrapping()
{
var policy = FormattingOptionsFactory.CreateMono();
policy.MethodDeclarationParameterWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodDeclarationOpenParentheses = true;
policy.MethodDeclarationClosingParenthesesOnNewLine = true;
Test(policy, @"class Test
{
void TestMe (int i, int j, int k)
{
}
}",
@"class Test
{
void TestMe (
int i,
int j,
int k
)
{
}
}");
}
[Ignore("Not Implemented")]
[Test()]
public void TestIndexerDeclarationParameterNewLineWrapping()
{
var policy = FormattingOptionsFactory.CreateMono();
policy.IndexerDeclarationParameterWrapping = Wrapping.WrapAlways;
policy.NewLineAferIndexerDeclarationOpenBracket = true;
policy.IndexerDeclarationClosingBracketOnNewLine = true;
Test(policy, @"class Test
{
int this [int i, int j, int k] {
get {
}
}
}",
@"class Test
{
int this [
int i,
int j,
int k
] {
get {
}
}
}");
}
}
}

Loading…
Cancel
Save