Browse Source

Fixed some issues in event formatting.

pull/45/merge
Mike Krüger 12 years ago
parent
commit
7a5afe919f
  1. 2
      ICSharpCode.NRefactory.CSharp/Ast/Statements/BreakStatement.cs
  2. 6
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/EntityDeclaration.cs
  3. 6
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/EventDeclaration.cs
  4. 12
      ICSharpCode.NRefactory.CSharp/Formatter/FormattingVisitor_TypeMembers.cs
  5. 20
      ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

2
ICSharpCode.NRefactory.CSharp/Ast/Statements/BreakStatement.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode SemicolonToken { public CSharpTokenNode SemicolonToken {
get { return GetChildByRole (Roles.Semicolon); } get { return GetChildByRole (Roles.Semicolon); }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor (IAstVisitor visitor)
{ {
visitor.VisitBreakStatement (this); visitor.VisitBreakStatement (this);

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

@ -71,7 +71,11 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Type); } get { return GetChildByRole (Roles.Type); }
set { SetChildByRole(Roles.Type, value); } set { SetChildByRole(Roles.Type, value); }
} }
public CSharpTokenNode SemicolonToken {
get { return GetChildByRole (Roles.Semicolon); }
}
internal static Modifiers GetModifiers(AstNode node) internal static Modifiers GetModifiers(AstNode node)
{ {
Modifiers m = 0; Modifiers m = 0;

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

@ -39,7 +39,11 @@ namespace ICSharpCode.NRefactory.CSharp
public override EntityType EntityType { public override EntityType EntityType {
get { return EntityType.Event; } get { return EntityType.Event; }
} }
public CSharpTokenNode EventToken {
get { return GetChildByRole (EventKeywordRole); }
}
public AstNodeCollection<VariableInitializer> Variables { public AstNodeCollection<VariableInitializer> Variables {
get { return GetChildrenByRole (Roles.Variable); } get { return GetChildrenByRole (Roles.Variable); }
} }

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

@ -261,6 +261,14 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
FixAttributes(eventDeclaration); FixAttributes(eventDeclaration);
foreach (var m in eventDeclaration.ModifierTokens) {
ForceSpacesAfter(m, true);
}
ForceSpacesBeforeRemoveNewLines(eventDeclaration.EventToken.GetNextSibling (NoWhitespacePredicate), true);
eventDeclaration.ReturnType.AcceptVisitor(this);
ForceSpacesAfter(eventDeclaration.ReturnType, true);
/*
var lastLoc = eventDeclaration.StartLocation; var lastLoc = eventDeclaration.StartLocation;
curIndent.Push(IndentType.Block); curIndent.Push(IndentType.Block);
foreach (var initializer in eventDeclaration.Variables) { foreach (var initializer in eventDeclaration.Variables) {
@ -271,6 +279,8 @@ namespace ICSharpCode.NRefactory.CSharp
initializer.AcceptVisitor(this); initializer.AcceptVisitor(this);
} }
curIndent.Pop (); curIndent.Pop ();
*/
FixSemicolon(eventDeclaration.SemicolonToken);
} }
@ -293,6 +303,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
initializer.AcceptVisitor(this); initializer.AcceptVisitor(this);
} }
FixSemicolon(fieldDeclaration.SemicolonToken);
} }
public override void VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration) public override void VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration)
@ -311,6 +322,7 @@ namespace ICSharpCode.NRefactory.CSharp
initializer.AcceptVisitor(this); initializer.AcceptVisitor(this);
} }
curIndent.Pop (); curIndent.Pop ();
FixSemicolon(fixedFieldDeclaration.SemicolonToken);
} }
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration) public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)

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

@ -675,6 +675,26 @@ set;
}"); }");
} }
[Test]
public void TestEventField()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
Test(policy,
@"class Test
{
public event
EventHandler TestMe ;
}",
@"class Test
{
public event EventHandler TestMe;
}");
}
[Test] [Test]
public void TestIndentEventBody() public void TestIndentEventBody()
{ {

Loading…
Cancel
Save