Browse Source

Fixed formatting bug.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
944ba9c62b
  1. 4
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 34
      ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs

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

@ -996,7 +996,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -996,7 +996,7 @@ namespace ICSharpCode.NRefactory.CSharp
return;
}
}
//Console.WriteLine ("offset={0}, removedChars={1}, insertedText={2}", offset, removedChars, insertedText == null ? "<null>" : insertedText.Replace ("\n", "\\n").Replace ("\r", "\\r").Replace ("\t", "\\t").Replace (" ", "."));
//Console.WriteLine ("offset={0}, removedChars={1}, insertedText={2}, removedText={3}", offset, removedChars, insertedText == null ? "<null>" : insertedText.Replace ("\n", "\\n").Replace ("\r", "\\r").Replace ("\t", "\\t").Replace (" ", "."), removedChars > 0 ? document.GetText (offset, removedChars).Replace ("\n", "\\n").Replace ("\r", "\\r").Replace ("\t", "\\t").Replace (" ", ".") : "null");
//Console.WriteLine (Environment.StackTrace);
changes.Add (factory.CreateTextReplaceAction (offset, removedChars, insertedText));
@ -1211,7 +1211,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1211,7 +1211,7 @@ namespace ICSharpCode.NRefactory.CSharp
FixEmbeddedStatment (policy.StatementBraceStyle, BraceForcement.DoNotChange, tryCatchStatement.FinallyBlock);
}
return VisitChildren (tryCatchStatement, data);
return null;
}
public override object VisitCatchClause (CatchClause catchClause, object data)

34
ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs

@ -192,6 +192,40 @@ using (IDisposable b = null) { @@ -192,6 +192,40 @@ using (IDisposable b = null) {
}");
}
/// <summary>
/// Bug 3586 -Format code is removing try { code blocks
/// </summary>
[Test()]
public void TestBug3586 ()
{
var policy = new CSharpFormattingOptions ();
policy.ConstructorBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"public class A
{
public object GetValue ()
{
try
{
foo ();
}
catch
{
}
}
}",
@"public class A
{
public object GetValue ()
{
try {
foo ();
} catch {
}
}
}");
}
}
}

Loading…
Cancel
Save