visitTypeDefinitionElement method

  1. @override
List<Class> visitTypeDefinitionElement(
  1. TypeDefinitionElement typeDefinitionElement
)
override

Implementation

@override
List<Class> visitTypeDefinitionElement(TypeDefinitionElement typeDefinitionElement) {
  final classes = <Class>[];

  if (typeDefinitionElement.variants case [final variant]) {
    final [class_] = variant.accept(this) as List<Class>;
    classes.add(class_);
  } else {
    final topClass = ClassBuilder(name: typeDefinitionElement.name);

    topClass.sealed = true;

    for (final parameter in typeDefinitionElement.parameters) {
      final [reference] = parameter.accept(this) as List<Reference>;
      topClass.addParameter(reference);
    }

    classes.add(topClass.asCodeBuilderClass());

    for (final variant in typeDefinitionElement.variants) {
      final [class_] = variant.accept(this) as List<Class>;
      classes.add(class_);
    }
  }

  return classes;
}