resolveUnitAt method Null safety

Future<ResolvedUnitResult> resolveUnitAt(
  1. Uri uri
)

Implementation

Future<ResolvedUnitResult> resolveUnitAt(Uri uri) async {
  assert(
    FileSystemEntity.isFileSync(
      uri.toFilePath(windows: Platform.isWindows),
    ),
  );
  for (final ctx in contexts.contexts) {
    final path = getPath(uri);
    if (_resolvedAsts.containsKey(path)) {
      return _resolvedAsts[path]! as ResolvedUnitResult;
    }

    final output =
        await ctx.currentSession.getResolvedUnit(path) as ResolvedUnitResult;
    return _resolvedAsts[path] = output;
  }

  throw ArgumentError("'uri' could not be resolved (contexts: "
      "${contexts.contexts.map((c) => c.contextRoot.root.toUri()).join(", ")})");
}