Browse Source

Added 'default' section keywords.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
22a97b5e9f
  1. 3
      ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs
  2. 14
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

3
ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs

@ -151,6 +151,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -151,6 +151,9 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
/// <summary>
/// Gets or sets the expression. The expression can be null - if the expression is null, it's the default switch section.
/// </summary>
public Expression Expression {
get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole (Roles.Expression, value); }

14
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -1616,12 +1616,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1616,12 +1616,16 @@ namespace ICSharpCode.NRefactory.CSharp
var newSection = new SwitchSection ();
foreach (var caseLabel in section.Labels) {
var newLabel = new CaseLabel ();
newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), "case".Length), SwitchStatement.Roles.Keyword);
if (caseLabel.Label != null)
if (caseLabel.Label != null) {
newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), "case".Length), SwitchStatement.Roles.Keyword);
newLabel.AddChild ((Expression)caseLabel.Label.Accept (this), SwitchStatement.Roles.Expression);
var colonLocation = LocationsBag.GetLocations (caseLabel);
if (colonLocation != null)
result.AddChild (new CSharpTokenNode (Convert (colonLocation [0]), 1), SwitchStatement.Roles.Colon);
var colonLocation = LocationsBag.GetLocations (caseLabel);
if (colonLocation != null)
newLabel.AddChild (new CSharpTokenNode (Convert (colonLocation [0]), 1), SwitchStatement.Roles.Colon);
} else {
newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), "default".Length), SwitchStatement.Roles.Keyword);
newLabel.AddChild (new CSharpTokenNode (new TextLocation (caseLabel.Location.Row, caseLabel.Location.Column + "default".Length), 1), SwitchStatement.Roles.Colon);
}
newSection.AddChild (newLabel, SwitchSection.CaseLabelRole);
}

Loading…
Cancel
Save