visitTypeVariantElement method
Implementation
@override
List<Class> visitTypeVariantElement(TypeVariantElement node) {
final typeDefinitionElement = node.enclosingElement;
final variantClass = ClassBuilder(
name: node.name,
withEquality: true,
)..final$ = true;
for (final parameter in node.parameters) {
for (final type in _typeParametersFromType(parameter.type!)) {
variantClass.addParameter(_typeReferenceFromType(type));
}
variantClass.addField(
_typeReferenceFromType(parameter.type!),
parameter,
);
}
if (typeDefinitionElement.variants.length > 1) {
variantClass.defineSupertypeName(typeDefinitionElement.name);
final currentVariantTypes = [
for (final parameter in node.parameters) parameter.type!,
];
final typeParameters = _typeParametersFromTypeList(currentVariantTypes);
for (final typeParameter in typeDefinitionElement.parameters) {
final argument = typeParameters.contains(typeParameter.type) //
? typeParameter.type!
: const BottomType();
final parameter = _typeReferenceFromType(argument);
variantClass.addParameterToSupertype(parameter);
}
}
return [variantClass.asCodeBuilderClass()];
}