Browse Source

Fixed formatting bug.

pull/45/merge
Mike Krüger 12 years ago
parent
commit
9521f329b3
  1. 6
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs
  2. 7
      ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Global.cs
  3. 7
      ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_TypeMembers.cs
  4. 40
      ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

6
ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs

@ -36,7 +36,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,7 +36,11 @@ namespace ICSharpCode.NRefactory.CSharp
public override EntityType EntityType {
get { return EntityType.Field; }
}
public CSharpTokenNode AssignToken {
get { return GetChildByRole (Roles.Assign); }
}
public Expression Initializer {
get { return GetChildByRole (InitializerRole); }
set { SetChildByRole (InitializerRole, value); }

7
ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_Global.cs

@ -173,10 +173,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -173,10 +173,15 @@ namespace ICSharpCode.NRefactory.CSharp
}
if (!startFormat || !NoWhitespacePredicate (child))
return;
if (child.Role == Roles.Comma) {
ForceSpacesBeforeRemoveNewLines (child, false);
EnsureNewLinesAfter(child, 1);
return;
}
if (NoWhitespacePredicate(child))
FixIndentationForceNewLine(child);
child.AcceptVisitor(this);
if (NoWhitespacePredicate(child))
if (NoWhitespacePredicate(child) && child.GetNextSibling (NoWhitespacePredicate).Role != Roles.Comma)
EnsureNewLinesAfter(child, GetTypeLevelNewLinesFor(child));
});

7
ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_TypeMembers.cs

@ -316,8 +316,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -316,8 +316,11 @@ namespace ICSharpCode.NRefactory.CSharp
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)
{
FixAttributes(enumMemberDeclaration);
base.VisitEnumMemberDeclaration(enumMemberDeclaration);
var initializer = enumMemberDeclaration.Initializer;
if (!initializer.IsNull) {
ForceSpacesAround(enumMemberDeclaration.AssignToken, policy.SpaceAroundAssignment);
initializer.AcceptVisitor (this);
}
}
public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)

40
ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

@ -282,6 +282,46 @@ A @@ -282,6 +282,46 @@ A
}");
}
[Test]
public void TestIndentEnumBodyCase2()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
policy.IndentEnumBody = true;
Test(policy,
@"enum Test
{
A ,
B,
C
}", @"enum Test
{
A,
B,
C
}");
}
[Test]
public void TestIndentEnumBodyCase3()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
policy.IndentEnumBody = true;
Test(policy,
@"enum Test
{
A = 3 + 5,
B=5 ,
C=5 << 12
}", @"enum Test
{
A = 3 + 5,
B = 5,
C = 5 << 12
}");
}
[Test]
public void TestIndentMethodBody()
{

Loading…
Cancel
Save