Browse Source

Generate switch default case. Closes #26

newNRvisualizers
David Srbecký 15 years ago
parent
commit
cafda5f692
  1. 12
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

12
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -1529,8 +1529,13 @@ namespace ICSharpCode.NRefactory.CSharp
public object VisitSwitchSection(SwitchSection switchSection, object data) public object VisitSwitchSection(SwitchSection switchSection, object data)
{ {
StartNode(switchSection); StartNode(switchSection);
foreach (var label in switchSection.CaseLabels) bool first = true;
foreach (var label in switchSection.CaseLabels) {
if (!first)
NewLine();
label.AcceptVisitor(this, data); label.AcceptVisitor(this, data);
first = false;
}
foreach (var statement in switchSection.Statements) foreach (var statement in switchSection.Statements)
statement.AcceptVisitor(this, data); statement.AcceptVisitor(this, data);
return EndNode(switchSection); return EndNode(switchSection);
@ -1539,11 +1544,14 @@ namespace ICSharpCode.NRefactory.CSharp
public object VisitCaseLabel(CaseLabel caseLabel, object data) public object VisitCaseLabel(CaseLabel caseLabel, object data)
{ {
StartNode(caseLabel); StartNode(caseLabel);
if (caseLabel.Expression.IsNull) {
WriteKeyword("default");
} else {
WriteKeyword("case"); WriteKeyword("case");
Space(); Space();
caseLabel.Expression.AcceptVisitor(this, data); caseLabel.Expression.AcceptVisitor(this, data);
}
WriteToken(":", CaseLabel.Roles.Colon); WriteToken(":", CaseLabel.Roles.Colon);
NewLine();
return EndNode(caseLabel); return EndNode(caseLabel);
} }

Loading…
Cancel
Save