typeArguments property Null safety

Iterable<ElementType> typeArguments
override

Implementation

@override
// TODO(jcollins-g): Rewrite this and improve object model so this doesn't
// require type checking everywhere.
Iterable<ElementType> get typeArguments {
  if (_typeArguments == null) {
    Iterable<DartType> dartTypeArguments;
    if (returnedFrom is FunctionTypeElementType) {
      if (type.typeFormals.isEmpty) {
        dartTypeArguments = type.typeArguments;
      } else {
        dartTypeArguments = type.typeFormals.map(_legacyTypeParameterType);
      }
    } else {
      if (type.typeFormals.isEmpty) {
        dartTypeArguments = type.typeArguments;
      } else if (returnedFrom != null &&
          returnedFrom.type.element is GenericFunctionTypeElement) {
        _typeArguments = (returnedFrom as DefinedElementType).typeArguments;
      } else {
        dartTypeArguments = type.typeFormals.map(_legacyTypeParameterType);
      }
    }
    if (dartTypeArguments != null) {
      _typeArguments = dartTypeArguments
          .map((f) => ElementType.from(f, library, packageGraph))
          .toList();
    }
  }
  return _typeArguments;
}