@@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/standard_resolution_map.dart';
77import 'package:analyzer/dart/element/element.dart' ;
88// ignore: implementation_imports
99import 'package:analyzer/src/dart/resolver/scope.dart' ;
10+ import 'package:build/build.dart' ;
1011import 'package:path/path.dart' as p;
1112
1213import 'constants/reader.dart' ;
@@ -72,6 +73,18 @@ class LibraryReader {
7273 }
7374 }
7475
76+ /// Returns a [Uri] from the current library to the target [asset] .
77+ ///
78+ /// This is a typed convenience function for using [pathToUrl] , and the same
79+ /// API restrictions hold around supported schemes and relative paths.
80+ Uri pathToAsset (AssetId asset) => pathToUrl (asset.uri);
81+
82+ /// Returns a [Uri] from the current library to the target [element] .
83+ ///
84+ /// This is a typed convenience function for using [pathToUrl] , and the same
85+ /// API restrictions hold around supported schemes and relative paths.
86+ Uri pathToElement (Element element) => pathToUrl (element.source.uri);
87+
7588 /// Returns a [Uri] from the current library to the one provided.
7689 ///
7790 /// If possible, a `package:` or `dart:` URL scheme will be used to reference
@@ -85,6 +98,9 @@ class LibraryReader {
8598 ///
8699 /// May throw [ArgumentError] if it is not possible to resolve a path.
87100 Uri pathToUrl (dynamic toUrlOrString) {
101+ if (toUrlOrString == null ) {
102+ throw new ArgumentError .notNull ('toUrlOrString' );
103+ }
88104 final to = toUrlOrString is Uri
89105 ? toUrlOrString
90106 : Uri .parse (toUrlOrString as String );
0 commit comments