visitIf method

  1. @override
String visitIf(
  1. IfStmt ifStmt
)
override

Implementation

@override
String visitIf(IfStmt ifStmt) {
  final output = StringBuffer();
  output.write('${_lexicon.kIf} ${_lexicon.groupExprStart}');
  final conditionString = formatAST(ifStmt.condition);
  output.write('$conditionString${_lexicon.groupExprEnd} ');
  final thenBranchString = formatAST(ifStmt.thenBranch);
  output.write(thenBranchString);
  if ((ifStmt.elseBranch is IfStmt) || (ifStmt.elseBranch is BlockStmt)) {
    output.write(' ${_lexicon.kElse} ');
    final elseBranchString = formatAST(ifStmt.elseBranch!);
    output.write(elseBranchString);
  } else if (ifStmt.elseBranch != null) {
    output.writeln(' ${_lexicon.kElse} ${_lexicon.codeBlockStart}');
    ++_curIndentCount;
    output.write(curIndent);
    final elseBranchString = formatAST(ifStmt.elseBranch!);
    output.writeln(elseBranchString);
    --_curIndentCount;
    output.write(curIndent);
    output.write(_lexicon.codeBlockEnd);
  }
  return output.toString();
}