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
var oce = node as ObjectCreateExpression; var oce = node as ObjectCreateExpression;
methodCallArgumentWrapping = policy.MethodCallArgumentWrapping; methodCallArgumentWrapping = policy.MethodCallArgumentWrapping;
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses; newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses;
methodClosingParenthesesOnNewLine = policy.MethodClosingParenthesesOnNewLine; methodClosingParenthesesOnNewLine = policy.MethodCallClosingParenthesesOnNewLine;
spaceWithinMethodCallParentheses = policy.SpacesWithinNewParentheses; spaceWithinMethodCallParentheses = policy.SpacesWithinNewParentheses;
spaceAfterMethodCallParameterComma = policy.SpaceAfterNewParameterComma; spaceAfterMethodCallParameterComma = policy.SpaceAfterNewParameterComma;
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeNewParameterComma; spaceBeforeMethodCallParameterComma = policy.SpaceBeforeNewParameterComma;
@ -1643,7 +1643,7 @@ namespace ICSharpCode.NRefactory.CSharp
InvocationExpression invocationExpression = node as InvocationExpression; InvocationExpression invocationExpression = node as InvocationExpression;
methodCallArgumentWrapping = policy.MethodCallArgumentWrapping; methodCallArgumentWrapping = policy.MethodCallArgumentWrapping;
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses; newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses;
methodClosingParenthesesOnNewLine = policy.MethodClosingParenthesesOnNewLine; methodClosingParenthesesOnNewLine = policy.MethodCallClosingParenthesesOnNewLine;
spaceWithinMethodCallParentheses = policy.SpaceWithinMethodCallParentheses; spaceWithinMethodCallParentheses = policy.SpaceWithinMethodCallParentheses;
spaceAfterMethodCallParameterComma = policy.SpaceAfterMethodCallParameterComma; spaceAfterMethodCallParameterComma = policy.SpaceAfterMethodCallParameterComma;
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeMethodCallParameterComma; spaceBeforeMethodCallParameterComma = policy.SpaceBeforeMethodCallParameterComma;
@ -1673,7 +1673,8 @@ namespace ICSharpCode.NRefactory.CSharp
FixStatementIndentation(rParToken.StartLocation); FixStatementIndentation(rParToken.StartLocation);
} else { } else {
foreach (var arg in arguments) { 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); arg.AcceptVisitor(this);
} }
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses); ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
@ -1704,7 +1705,8 @@ namespace ICSharpCode.NRefactory.CSharp
FixStatementIndentation(mt.DotToken.StartLocation); FixStatementIndentation(mt.DotToken.StartLocation);
curIndent.Pop(); curIndent.Pop();
} else { } 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
} }
public enum Wrapping { public enum Wrapping {
DoNotChange,
DoNotWrap, DoNotWrap,
WrapAlways, WrapAlways,
WrapIfTooLong WrapIfTooLong
@ -801,7 +802,7 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public bool MethodClosingParenthesesOnNewLine { public bool MethodCallClosingParenthesesOnNewLine {
get; get;
set; set;
} }
@ -820,6 +821,36 @@ namespace ICSharpCode.NRefactory.CSharp
get; get;
set; 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 #endregion
internal CSharpFormattingOptions() internal CSharpFormattingOptions()

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

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

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

@ -172,7 +172,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono(); var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways; policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = true; policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true; policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test Test(policy, @"class Test
{ {
@ -200,7 +200,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono(); var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways; policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = false; policy.NewLineAferMethodCallOpenParentheses = false;
policy.MethodClosingParenthesesOnNewLine = false; policy.MethodCallClosingParenthesesOnNewLine = false;
Test(policy, @"class Test Test(policy, @"class Test
{ {
@ -227,7 +227,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono(); var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.DoNotWrap; policy.MethodCallArgumentWrapping = Wrapping.DoNotWrap;
policy.NewLineAferMethodCallOpenParentheses = true; policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true; policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test Test(policy, @"class Test
{ {
@ -254,9 +254,9 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
public void TestIndexerCallArgumentNoNewLineWrapping() public void TestIndexerCallArgumentNoNewLineWrapping()
{ {
var policy = FormattingOptionsFactory.CreateMono(); var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways; policy.IndexerArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = true; policy.NewLineAferIndexerOpenBracket = true;
policy.MethodClosingParenthesesOnNewLine = true; policy.IndexerClosingBracketOnNewLine = true;
Test(policy, @"class Test Test(policy, @"class Test
{ {
@ -284,7 +284,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
var policy = FormattingOptionsFactory.CreateMono(); var policy = FormattingOptionsFactory.CreateMono();
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways; policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
policy.NewLineAferMethodCallOpenParentheses = true; policy.NewLineAferMethodCallOpenParentheses = true;
policy.MethodClosingParenthesesOnNewLine = true; policy.MethodCallClosingParenthesesOnNewLine = true;
Test(policy, @"class Test Test(policy, @"class Test
{ {
@ -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