decorate method Null safety

  1. @override
TypeInfo decorate(
  1. TypeInfo typeInfo
)
override

Implementation

@override
TypeInfo decorate(TypeInfo typeInfo) {
  final type = typeInfo.type;
  final typeName = type != null ? type.toString() : '';

  typeInfo.typeName = typeName;

  final mixinTypeNames = detectMixinTypeName(typeInfo);
  typeInfo.isWithMixin = mixinTypeNames.isNotEmpty;
  if (typeInfo.isWithMixin) {
    typeInfo.typeName = mixinTypeNames.first;
    typeInfo.mixinTypeName = mixinTypeNames.last;
  }

  typeInfo.isDynamic = typeName == 'dynamic';
  typeInfo.isList = typeName.indexOf('List<') == 0 ||
      isUnmodifiableListView(typeInfo) ||
      isCastList(typeInfo);
  typeInfo.isSet = typeName.indexOf('Set<') == 0 || isHashSet(typeInfo);
  typeInfo.isMap = typeName.indexOf('Map<') == 0 ||
      isHashMap(typeInfo) ||
      isLinkedHashMap(typeInfo) ||
      isUnmodifiableMapView(typeInfo);
  typeInfo.isIterable = typeInfo.isList || typeInfo.isSet;
  typeInfo.scalarType = detectScalarType(typeInfo);
  typeInfo.genericType = detectGenericType(typeInfo);

  if (_knownClasses[typeName] != null) {
    typeInfo.isEnum = _knownClasses[typeName]!.isEnum;
  } else {
    if (_enumValues[type!] != null) {
      typeInfo.isEnum = _enumValues[type] != null;
    }
  }

  typeInfo.parameters =
      getTypeParams(typeInfo).map((typeName) => detectTypeByName(typeName));

  typeInfo.genericTypeName = detectGenericTypeName(typeInfo);

  if (typeInfo.parameters.isNotEmpty) {
    typeInfo.isGeneric = true;
  }

  if (isBigInt(typeInfo)) {
    typeInfo.type = BigInt;
    typeInfo.genericType = BigInt;
  }

  if (isRegExp(typeInfo)) {
    typeInfo.type = RegExp;
    typeInfo.genericType = RegExp;
  }

  if (isUri(typeInfo)) {
    typeInfo.type = Uri;
    typeInfo.genericType = Uri;
  }

  return typeInfo;
}