visitWhen method
Implementation
@override
String visitWhen(WhenStmt stmt) {
final output = StringBuffer();
output.write(_lexicon.kWhen);
if (stmt.condition != null) {
final conditionString = formatAST(stmt.condition!);
output.write(
' ${_lexicon.groupExprStart}$conditionString${_lexicon.groupExprEnd}');
}
output.writeln(' ${_lexicon.codeBlockStart}');
++_curIndentCount;
for (final option in stmt.cases.keys) {
output.write(curIndent);
final optionString = formatAST(option);
output.write('$optionString ${_lexicon.whenBranchIndicator} ');
final branchString = formatAST(stmt.cases[option]!);
output.writeln(branchString);
}
if (stmt.elseBranch != null) {
final elseBranchString = formatAST(stmt.elseBranch!);
output.write(curIndent);
output.writeln(
'${_lexicon.kElse} ${_lexicon.whenBranchIndicator} $elseBranchString');
}
--_curIndentCount;
output.write(curIndent);
output.write(_lexicon.codeBlockEnd);
return output.toString();
}