toAbstractType method

AbstractType toAbstractType({
  1. bool? nullable,
})

Returns StandardType if match found in standardTypes or standardNullableTypes and otherwise a new CustomType.

Implementation

AbstractType toAbstractType({bool? nullable}) {
  final withPostfix = trim();

  final withoutPostfix = withPostfix.removePostfixIfPresent("?");

  final isNullable = nullable ?? withPostfix != withoutPostfix;

  final listType = _listType(
    strType: withoutPostfix,
    nullable: isNullable,
  );

  if (listType != null) {
    return listType;
  }

  final mapType = _mapType(
    strType: withoutPostfix,
    nullable: isNullable,
  );

  if (mapType != null) {
    return mapType;
  }

  final type = isNullable
      ? standardNullableTypes[withoutPostfix]
      : standardTypes[withoutPostfix];

  if (type != null) {
    return type;
  }

  final customType = withoutPostfix._toCustomTypeOrNull;

  if (customType != null) {
    return customType;
  }

  if (this == "dynamic") {
    return const UndeterminedAsDynamic();
  }

  throw SquintException("Unable to determine type: '$this'");
}