resolveFunctionType method

  1. @override
ImportableType resolveFunctionType(
  1. FunctionType function, [
  2. ExecutableElement? executableElement
])
override

Implementation

@override
ImportableType resolveFunctionType(FunctionType function,
    [ExecutableElement? executableElement]) {
  final functionElement =
      executableElement ?? function.element ?? function.alias?.element;
  if (functionElement == null) {
    throw 'Can not resolve function type \nTry using an alias e.g typedef MyFunction = ${function.getDisplayString(withNullability: false)};';
  }
  final displayName = functionElement.displayName;
  var functionName = displayName;

  Element elementToImport = functionElement;
  var enclosingElement = functionElement.enclosingElement;

  if (enclosingElement != null && enclosingElement is ClassElement) {
    functionName = '${enclosingElement.displayName}.$displayName';
    elementToImport = enclosingElement;
  }
  final imports = resolveImports(elementToImport);
  return ImportableType(
    name: functionName,
    import: imports.firstOrNull,
    otherImports: imports.skip(1).toSet(),
    isNullable: function.nullabilitySuffix == NullabilitySuffix.question,
  );
}