GeneratorForAnnotation<T> class abstract

Extend this type to create a Generator that invokes generateForAnnotatedElement for every top level element in the source file annotated with T.

When all annotated elements have been processed, the results will be combined into a single output with duplicate items collapsed.

For example, this will allow code generated for all top level elements which are annotated with @Deprecated:

class DeprecatedGenerator extends GeneratorForAnnotation<Deprecated> {
  @override
  Future<String> generateForAnnotatedElement(
      Element element,
      ConstantReader annotation,
      BuildStep buildStep) async {
    // Return a string representing the code to emit.
  }
}

Elements which are not at the top level, such as the members of a class or extension, are not searched for annotations. To operate on, for instance, annotated fields of a class ensure that the class itself is annotated with T and use the Element to iterate over fields. The TypeChecker utility may be helpful to check which elements have a given annotation.

Inheritance

Constructors

GeneratorForAnnotation()
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
typeChecker TypeChecker
no setter

Methods

generate(LibraryReader library, BuildStep buildStep) FutureOr<String>
Generates Dart code for an input Dart library.
override
generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) → dynamic
Implement to return source code to generate for element.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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