add method

void add(
  1. Object object, {
  2. SourceLocation? location,
  3. SourceSpan? span,
  4. bool isOriginal = false,
})

Adds object to this printer. object can be a String, NestedPrinter, or anything implementing NestedItem. If object is a String, the value is appended directly, without doing any formatting changes. If you wish to add a line of code with automatic indentation, use addLine instead. NestedPrinters and NestedItems are not processed until build gets called later on. We ensure that build emits every object in the order that they were added to this printer.

The location and span parameters indicate the corresponding source map location of object in the original input. Only one, location or span, should be provided at a time.

Indicate isOriginal when object is copied directly from the user code. Setting isOriginal will make this printer propagate source map locations on every line-break.

Implementation

void add(Object object,
    {SourceLocation? location, SourceSpan? span, bool isOriginal = false}) {
  if (object is! String || location != null || span != null || isOriginal) {
    _flush();
    assert(location == null || span == null);
    if (location != null) _items.add(location);
    if (span != null) _items.add(span);
    if (isOriginal) _items.add(_original);
  }

  if (object is String) {
    _appendString(object);
  } else {
    _items.add(object);
  }
}