NestedPrinter class

A more advanced printer that keeps track of offset locations to record source maps, but additionally allows nesting of different kind of items, including NestedPrinters, and it let's you automatically indent text.

This class is especially useful when doing code generation, where different pieces of the code are generated independently on separate printers, and are finally put together in the end.

Implemented types

Constructors

NestedPrinter([int indent = 0])

Properties

hashCode int
The hash code for this object.
no setterinherited
indent int
Current indentation, which can be updated from outside this class.
getter/setter pair
map String?
Returns the source-map information produced after calling build.
no setter
printer Printer?
Printer used during the last call to build, if any.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
text String?
Returns the text produced after calling build.
no setter

Methods

add(Object object, {SourceLocation? location, SourceSpan? span, bool isOriginal = false}) → void
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.
addLine(String? line, {SourceLocation? location, SourceSpan? span}) → void
Add a line, autoindenting to the current value of indent. Note, indentation is not inferred from the contents added to this printer. If a line starts or ends an indentation block, you need to also update indent accordingly. Also, indentation is not adapted for nested printers. If you add a NestedPrinter to this printer, its indentation is set separately and will not include any the indentation set here.
build(String filename) → void
Builds the output of this printer and source map information. After calling this function, you can use text and map to retrieve the geenrated code and source map information, respectively.
insertIndent() → void
Append 2 * indent spaces to this printer.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Returns a string representation of all the contents appended to this printer, including source map location tokens.
override
writeTo(Printer printer) → void
Implements the NestedItem interface.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited