linkTypeOf function
Returns a TypeLink to the given statically analyzed DartType
.
Implementation
TypeLink linkTypeOf(DartType type) {
// Return void or Null types.
if (type.isVoid) {
return TypeLink.$void;
}
if (type.isDartCoreNull) {
return TypeLink.$null;
}
// Return dynamic type (no type found or type is unusable/inaccessible).
//
// For example, there are missing imports, we are referring to a FunctionType
// that does not come from a typedef, it is the type of a top-level function
// and that type was not inferred previously by the analyzer. A more proper
// fix from Angular would be to support function types (for now dynamic only).
if (type.isDynamic) {
return TypeLink.$dynamic;
}
type = _resolveBounds(type);
// Return dynamic type (no type found) after _resolveBounds.
// Note: with non_nullable, library is never null: we need to check its name.
if (getTypeName(type) == null) {
return TypeLink.$dynamic;
}
var typeArguments = type.alias?.typeArguments;
if (typeArguments == null) {
if (type is InterfaceType) {
typeArguments = type.typeArguments;
} else {
typeArguments = const <DartType>[];
}
}
return TypeLink(
getTypeName(type)!,
getTypeImport(type),
generics: typeArguments.map(linkTypeOf).toList(),
isNullable: type.nullabilitySuffix == NullabilitySuffix.question,
);
}