Browse Source

Added KeepCommentsAtFirstColumn option.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
9511d48927
  1. 6
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 12
      ICSharpCode.NRefactory.CSharp/Formatter/CSharpFormattingOptions.cs
  3. 84
      ICSharpCode.NRefactory.Tests/FormattingTests/TestKeepReformattingRules.cs
  4. 9
      ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs
  5. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

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

@ -873,8 +873,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -873,8 +873,10 @@ namespace ICSharpCode.NRefactory.CSharp
if (child is Statement) {
FixStatementIndentation(child.StartLocation);
child.AcceptVisitor(this);
} else if (child is Comment) {
child.AcceptVisitor(this);
} else {
// leave comments and pre processor directives at line start, if they are there.
// pre processor directives at line start, if they are there.
if (child.StartLocation.Column > 1)
FixStatementIndentation(child.StartLocation);
}
@ -893,7 +895,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -893,7 +895,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override void VisitComment(Comment comment)
{
if (comment.StartsLine && !HadErrors && comment.StartLocation.Column > 1) {
if (comment.StartsLine && !HadErrors && (!policy.KeepCommentsAtFirstColumn || comment.StartLocation.Column > 1)) {
FixIndentation(comment.StartLocation);
}
}

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

@ -770,7 +770,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -770,7 +770,15 @@ namespace ICSharpCode.NRefactory.CSharp
}
#endregion
#region Keep formatting
public bool KeepCommentsAtFirstColumn {
get;
set;
}
#endregion
public CSharpFormattingOptions()
{
IndentNamespaceBody = true;
@ -883,6 +891,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -883,6 +891,8 @@ namespace ICSharpCode.NRefactory.CSharp
BlankLinesBetweenFields = 0;
BlankLinesBetweenEventFields = 0;
BlankLinesBetweenMembers = 1;
KeepCommentsAtFirstColumn = true;
}
/*public static CSharpFormattingOptions Load (FilePath selectedFile)

84
ICSharpCode.NRefactory.Tests/FormattingTests/TestKeepReformattingRules.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
//
// TestKeepReformattingRules.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestKeepReformattingRules : TestBase
{
[Test()]
public void TestKeepCommentsAtFirstColumnTrue ()
{
var policy = new CSharpFormattingOptions() {
KeepCommentsAtFirstColumn = true
};
Test(policy, @"class Test
{
void TestMe ()
{
// comment
}
}",
@"class Test
{
void TestMe ()
{
// comment
}
}");
}
[Test()]
public void TestKeepCommentsAtFirstColumnFalse ()
{
var policy = new CSharpFormattingOptions() {
KeepCommentsAtFirstColumn = false
};
Test(policy, @"class Test
{
void TestMe ()
{
// comment
}
}",
@"class Test
{
void TestMe ()
{
// comment
}
}");
}
}
}

9
ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs

@ -35,14 +35,14 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -35,14 +35,14 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
public class TestSpacingVisitor : TestBase
{
[Test()]
public void TestFieldSpacesBeforeComma1 ()
public void TestFieldSpacesBeforeComma1()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
CSharpFormattingOptions policy = new CSharpFormattingOptions();
policy.ClassBraceStyle = BraceStyle.EndOfLine;
policy.SpaceBeforeFieldDeclarationComma = false;
policy.SpaceAfterFieldDeclarationComma = false;
Test (policy, @"class Test {
Test(policy, @"class Test {
int a , b, c;
}",
@"class Test {
@ -1631,6 +1631,9 @@ return (Test)null; @@ -1631,6 +1631,9 @@ return (Test)null;
}
}
}

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -263,6 +263,7 @@ @@ -263,6 +263,7 @@
<Compile Include="CSharp\CodeActions\IntroduceConstantTests.cs" />
<Compile Include="CSharp\CodeActions\ExtractMethodTests.cs" />
<Compile Include="CSharp\Parser\Bugs\ParserBugTests.cs" />
<Compile Include="FormattingTests\TestKeepReformattingRules.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

Loading…
Cancel
Save