resolve method

String? resolve(
  1. Element? element
)

Implementation

String? resolve(Element? element) {
  // return early if source is null or element is a core type
  if (element?.source == null || _isCoreDartType(element)) {
    return null;
  }

  for (var lib in libs) {
    if (_isCoreDartType(lib)) continue;

    if (lib.exportNamespace.definedNames.keys.contains(element?.name)) {
      final package = lib.source.uri.pathSegments.first;
      if (targetFilePath.startsWith(RegExp('^$package/'))) {
        return p.posix
            .relative(element?.source?.uri.path ?? '', from: targetFilePath)
            .replaceFirst('../', '');
      } else {
        return element?.source?.uri.toString();
      }
    }
  }

  return null;
}