resolveAbsolute method

  1. @override
Source resolveAbsolute(
  1. Uri uri,
  2. [Uri actualUri]
)

Resolve the given absolute URI. Return a Source representing the file to which it was resolved, whether or not the resulting source exists, or null if it could not be resolved because the URI is invalid.

@param uri the URI to be resolved @param actualUri the actual uri for this source -- if null, the value of uri will be used @return a Source representing the file to which given URI was resolved

Implementation

@override
Source resolveAbsolute(Uri uri, [Uri actualUri]) {
  if (!isPackageUri(uri)) {
    return null;
  }
  // Prepare path.
  String path = uri.path;
  // Prepare path components.
  int index = path.indexOf('/');
  if (index == -1 || index == 0) {
    return null;
  }
  // <pkgName>/<relPath>
  String pkgName = path.substring(0, index);
  String relPath = path.substring(index + 1);
  // If the package is known, return the corresponding file.
  List<Folder> packageDirs = packageMap[pkgName];
  if (packageDirs != null) {
    Folder packageDir = packageDirs.single;
    File file = packageDir.getChildAssumingFile(relPath);
    return file.createSource(uri);
  }
  return null;
}