TypeDefinition.fromDartType constructor

TypeDefinition.fromDartType(
  1. DartType type
)

Creates an TypeDefinition from a given DartType. throws FromDartTypeClassNameException if the class name could not be determined.

Implementation

factory TypeDefinition.fromDartType(DartType type) {
  var generics = (type is ParameterizedType)
      ? type.typeArguments.map((e) => TypeDefinition.fromDartType(e)).toList()
      : <TypeDefinition>[];
  var url = type.element?.librarySource?.uri.toString();
  var nullable = type.nullabilitySuffix == NullabilitySuffix.question;

  var className = type is! VoidType ? type.element?.displayName : 'void';

  if (className == null) {
    throw FromDartTypeClassNameException(type);
  }

  return TypeDefinition(
    className: className,
    nullable: nullable,
    dartType: type,
    generics: generics,
    url: url,
  );
}