From 22a97b5e9f856b9bc50ffe99df0dfc9f7eb46826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Sun, 4 Sep 2011 15:42:52 +0200 Subject: [PATCH] Added 'default' section keywords. --- .../Ast/Statements/SwitchStatement.cs | 3 +++ .../Parser/CSharpParser.cs | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs b/ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs index c3fd4dd3fb..4df2569da6 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs @@ -151,6 +151,9 @@ namespace ICSharpCode.NRefactory.CSharp } } + /// + /// Gets or sets the expression. The expression can be null - if the expression is null, it's the default switch section. + /// public Expression Expression { get { return GetChildByRole (Roles.Expression); } set { SetChildByRole (Roles.Expression, value); } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs index 481ec8f0ce..ae3d83f0c5 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs @@ -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); }