Browse Source

Fixed some issues in the output visitor.

Note that the block statement newline should be done more elegant (new
lines should be done in the parent).
newNRvisualizers
Mike Krüger 13 years ago
parent
commit
eb6a774ca0
  1. 11
      ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 16
      ICSharpCode.NRefactory.Tests/CSharp/CSharpOutputVisitorTests.cs

11
ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -519,6 +519,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -519,6 +519,7 @@ namespace ICSharpCode.NRefactory.CSharp
void WriteEmbeddedStatement(Statement embeddedStatement)
{
if (embeddedStatement.IsNull) {
NewLine();
return;
}
BlockStatement block = embeddedStatement as BlockStatement;
@ -1584,7 +1585,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1584,7 +1585,8 @@ namespace ICSharpCode.NRefactory.CSharp
node.AcceptVisitor(this);
}
CloseBrace(style);
NewLine();
if (!(blockStatement.Parent is Expression))
NewLine();
EndNode(blockStatement);
}
@ -1694,9 +1696,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1694,9 +1696,10 @@ namespace ICSharpCode.NRefactory.CSharp
forStatement.Condition.AcceptVisitor(this);
Space(policy.SpaceBeforeForSemicolon);
WriteToken(Roles.Semicolon);
Space(policy.SpaceAfterForSemicolon);
WriteCommaSeparatedList(forStatement.Iterators);
if (forStatement.Iterators.Any()) {
Space(policy.SpaceAfterForSemicolon);
WriteCommaSeparatedList(forStatement.Iterators);
}
Space(policy.SpacesWithinForParentheses);
RPar();

16
ICSharpCode.NRefactory.Tests/CSharp/CSharpOutputVisitorTests.cs

@ -35,6 +35,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -35,6 +35,22 @@ namespace ICSharpCode.NRefactory.CSharp
Assert.AreEqual(expected.Replace("\r", ""), w.ToString());
}
[Test]
public void AnonymousLocalVariableDeclaration()
{
var code = @"class Test
{
void Foo ()
{
Action<int> act = delegate (int testMe) {
};
}
}
";
var unit = CompilationUnit.Parse(code);
AssertOutput("class Test\n{\n$void Foo ()\n${\n$$Action<int> act = delegate (int testMe) {\n$$};\n$}\n}\n", unit);
}
[Test]
public void AssignmentInCollectionInitializer()
{

Loading…
Cancel
Save