generateForAnnotatedElement method

  1. @override
dynamic generateForAnnotatedElement(
  1. Element2 element,
  2. ConstantReader annotation,
  3. BuildStep buildStep
)

Generates Dart source for a class marked with the @module() annotation.

Throws InvalidGenerationSourceError if used on anything except a class.

See file-level docs for usage and generated output example.

Implementation

@override
dynamic generateForAnnotatedElement(
  Element2 element,
  ConstantReader annotation,
  BuildStep buildStep,
) {
  if (element is! ClassElement2) {
    throw InvalidGenerationSourceError(
      '@module() can only be applied to classes.',
      element: element,
    );
  }

  final classElement = element;
  final generatedClass = GeneratedClass.fromClassElement(classElement);
  return generatedClass.generate();
}