Browse Source

Fixed property formatting bug.

newNRvisualizers
Mike Krüger 13 years ago
parent
commit
523971996b
  1. 14
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 52
      ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

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

@ -470,12 +470,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -470,12 +470,22 @@ namespace ICSharpCode.NRefactory.CSharp
switch (policy.PropertyFormatting) {
case PropertyFormatting.AllowOneLine:
bool isSimple = IsSimpleAccessor(propertyDeclaration.Getter) && IsSimpleAccessor(propertyDeclaration.Setter);
if (!isSimple || propertyDeclaration.LBraceToken.StartLocation.Line != propertyDeclaration.RBraceToken.StartLocation.Line) {
int accessorLine = propertyDeclaration.RBraceToken.StartLocation.Line;
if (!propertyDeclaration.Getter.IsNull && propertyDeclaration.Setter.IsNull) {
accessorLine = propertyDeclaration.Getter.StartLocation.Line;
} else if (propertyDeclaration.Getter.IsNull && !propertyDeclaration.Setter.IsNull) {
accessorLine = propertyDeclaration.Setter.StartLocation.Line;
} else {
var acc = propertyDeclaration.Getter.StartLocation < propertyDeclaration.Setter.StartLocation ?
propertyDeclaration.Getter : propertyDeclaration.Setter;
accessorLine = acc.StartLocation.Line;
}
if (!isSimple || propertyDeclaration.LBraceToken.StartLocation.Line != accessorLine) {
EnforceBraceStyle(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken, propertyDeclaration.RBraceToken);
} else {
ForceSpacesBefore(propertyDeclaration.Getter, true);
ForceSpacesBefore(propertyDeclaration.Setter, true);
ForceSpacesBefore(propertyDeclaration.RBraceToken, true);
ForceSpacesBeforeRemoveNewLines(propertyDeclaration.RBraceToken, true);
oneLine = true;
}
break;

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

@ -522,7 +522,59 @@ set; @@ -522,7 +522,59 @@ set;
}
}");
}
[Test()]
public void TestPropertyIndentationClosingBracketCorrection ()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
Test (policy,
@"class Test
{
public int Prop { get;
}
}",@"class Test
{
public int Prop { get; }
}");
}
[Test()]
public void TestPropertyIndentationClosingBracketCorrection2 ()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
Test (policy,
@"class Test
{
public int Prop {
get;}
}",@"class Test
{
public int Prop {
get;
}
}");
}
[Test()]
public void TestPropertyCorrection()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
Test(policy,
@"class Test
{
public int Prop { get; private set; }
}", @"class Test
{
public int Prop {
get;
private set;
}
}");
}
[Test()]
public void TestIndentEventBody ()

Loading…
Cancel
Save