describeTypeDescriptor function

String describeTypeDescriptor(
  1. $AT descriptor
)

Implementation

String describeTypeDescriptor($AT descriptor) {
  ListTypeInfo? collection = parseCollectionTypeDescriptor(descriptor);
  if (collection != null) {
    String inner = describeTypeDescriptor(collection.elementTypeDescriptor);
    String wrapped = collection.isSet ? 'Set<$inner>' : 'List<$inner>';
    return collection.nullableCollection ? '$wrapped?' : wrapped;
  }

  MapTypeInfo? mapType = parseMapTypeDescriptor(descriptor);
  if (mapType != null) {
    String key = describeTypeDescriptor(mapType.keyTypeDescriptor);
    String value = describeTypeDescriptor(mapType.valueTypeDescriptor);
    String wrapped = 'Map<$key, $value>';
    return mapType.nullableMap ? '$wrapped?' : wrapped;
  }

  PrimitiveKind? primitive = primitiveKindFromDescriptor(descriptor);
  if (primitive != null) {
    switch (primitive) {
      case PrimitiveKind.string:
        return descriptor.type == getNullishType<String>()
            ? 'String?'
            : 'String';
      case PrimitiveKind.dateTime:
        return descriptor.type == getNullishType<DateTime>()
            ? 'DateTime?'
            : 'DateTime';
      case PrimitiveKind.boolType:
        return descriptor.type == getNullishType<bool>() ? 'bool?' : 'bool';
      case PrimitiveKind.intType:
        return descriptor.type == getNullishType<int>() ? 'int?' : 'int';
      case PrimitiveKind.doubleType:
        return descriptor.type == getNullishType<double>()
            ? 'double?'
            : 'double';
    }
  }

  $AClass? artifactType = resolveArtifactTypeFromDescriptor(descriptor);
  if (artifactType != null) {
    return isNullableTypeDescriptor(descriptor)
        ? '${artifactType.classType}?'
        : artifactType.classType.toString();
  }

  return descriptor.type.toString();
}