visitDestructuringDecl method

  1. @override
String visitDestructuringDecl(
  1. DestructuringDecl stmt
)
override

Implementation

@override
String visitDestructuringDecl(DestructuringDecl stmt) {
  final output = StringBuffer();
  if (!stmt.isMutable) {
    output.write('${_lexicon.kFinal} ');
  } else {
    output.write('${_lexicon.kVar} ');
  }
  if (stmt.isVector) {
    output.write(_lexicon.listStart);
  } else {
    output.write(_lexicon.codeBlockStart);
  }
  for (var i = 0; i < stmt.ids.length; ++i) {
    output.write(' ');
    final id = stmt.ids.keys.elementAt(i);
    output.write(id.id);
    final typeExpr = stmt.ids[id];
    if (typeExpr != null) {
      final typeString = formatAST(typeExpr);
      output.write('${_lexicon.typeIndicator} $typeString');
    }
    if (i < stmt.ids.length - 1) {
      output.writeln(_lexicon.comma);
    }
  }
  if (stmt.isVector) {
    output.write(' ${_lexicon.listStart} ${_lexicon.assign} ');
  } else {
    output.write(' ${_lexicon.codeBlockStart} ${_lexicon.assign} ');
  }
  final initString = formatAST(stmt.initializer);
  output.write(initString);
  if (stmt.hasEndOfStmtMark) {
    output.write(_lexicon.endOfStatementMark);
  }
  return output.toString();
}