AnalyzerBuffer class

A String buffer that is used to generate Dart code.

It helps deal with common problems such as:

  • Writing types while respecting import prefixes and typedefs
  • Automatically adding imports, if writing to a standalone library

It is primarily used with write, as it enables writing code in plain strings, and interpolating types to still support prefixes and co.

Alternatively, you can write code "as usual" by using the writeType method, combined with passing non-interpolated strings to write.

Constructors

AnalyzerBuffer.part(LibraryElement library, {String? header})
Creates a AnalyzerBuffer that generates code for a specific library.
factory
AnalyzerBuffer.part2(LibraryElement2 library, {String? header})
Creates a AnalyzerBuffer that generates code for a specific library.
factory
AnalyzerBuffer.newLibrary({required String packageName, required String path, String? header})
Creates a AnalyzerBuffer that generates a brand new library.

Properties

hashCode int
The hash code for this object.
no setterinherited
A header that will be added at the top of the generated code.
final
isEmpty bool
Whether any write was performed on the buffer.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override
write(String code, {Map<String, void Function()> args = const {}}) → void
Interpolates the given code, gracefully printing types and adding type prefixes if necessary.
writeType(DartType type, {bool recursive = true}) → void
Writes the given type to the buffer.

Operators

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