@@ -5,6 +5,7 @@ import 'package:analyzer/dart/analysis/results.dart';
55import 'package:analyzer/dart/analysis/session.dart' ;
66import 'package:analyzer/dart/ast/ast.dart' ;
77import 'package:analyzer/dart/element/element.dart' ;
8+ import 'package:analyzer/dart/element/element2.dart' ;
89import 'package:analyzer/error/error.dart' ;
910
1011import '../asset/id.dart' ;
@@ -29,6 +30,17 @@ abstract class Resolver {
2930 /// instance because due to imports or exports.
3031 Stream <LibraryElement > get libraries;
3132
33+ /// All libraries resolved by this resolver.
34+ ///
35+ /// This includes the following libraries:
36+ /// - The primary input of this resolver (in other words, the
37+ /// [BuildStep.inputId] of a build step).
38+ /// - Libraries resolved with a direct [libraryFor] call.
39+ /// - Every public `dart:` library part of the SDK.
40+ /// - All libraries recursively accessible from the mentioned sources, for
41+ /// instance because due to imports or exports.
42+ Stream <LibraryElement2 > get libraries2;
43+
3244 /// Returns the parsed [AstNode] for [Element] .
3345 ///
3446 /// This should always be preferred over using the [AnalysisSession]
@@ -42,6 +54,19 @@ abstract class Resolver {
4254 /// reason.
4355 Future <AstNode ?> astNodeFor (Element element, {bool resolve = false });
4456
57+ /// Returns the parsed [AstNode] for [Element] .
58+ ///
59+ /// This should always be preferred over using the [AnalysisSession]
60+ /// directly, because it avoids [InconsistentAnalysisException] issues.
61+ ///
62+ /// If [resolve] is `true` then you will get a resolved ast node, otherwise
63+ /// it will only be a parsed ast node.
64+ ///
65+ /// Returns `null` if the ast node can not be found. This can happen if an
66+ /// element is coming from a summary, or is unavailable for some other
67+ /// reason.
68+ Future <AstNode ?> astNodeFor2 (Fragment element, {bool resolve = false });
69+
4570 /// Returns a parsed AST structor representing the file defined in [assetId] .
4671 ///
4772 /// * If the [assetId] has syntax errors, and [allowSyntaxErrors] is set to
@@ -60,6 +85,14 @@ abstract class Resolver {
6085 Future <LibraryElement > libraryFor (AssetId assetId,
6186 {bool allowSyntaxErrors = false });
6287
88+ /// Returns a resolved library representing the file defined in [assetId] .
89+ ///
90+ /// * Throws [NonLibraryAssetException] if [assetId] is not a Dart library.
91+ /// * If the [assetId] has syntax errors, and [allowSyntaxErrors] is set to
92+ /// `false` (the default), throws a [SyntaxErrorInAssetException] .
93+ Future <LibraryElement2 > libraryFor2 (AssetId assetId,
94+ {bool allowSyntaxErrors = false });
95+
6396 /// Returns the first resolved library identified by [libraryName] .
6497 ///
6598 /// A library is resolved if it's recursively accessible from the entry point
@@ -72,6 +105,19 @@ abstract class Resolver {
72105 /// being unique.
73106 Future <LibraryElement ?> findLibraryByName (String libraryName);
74107
108+ /// Returns the first resolved library identified by [libraryName] .
109+ ///
110+ /// A library is resolved if it's recursively accessible from the entry point
111+ /// or subsequent calls to [libraryFor] . In other words, this searches for
112+ /// libraries in [libraries] .
113+ /// If no library can be found, returns `null` .
114+ ///
115+ /// **NOTE**: In general, its recommended to use [libraryFor] with an absolute
116+ /// asset id instead of a named identifier that has the possibility of not
117+ /// being unique.
118+ Future <LibraryElement2 ?> findLibraryByName2 (
119+ String libraryName);
120+
75121 /// Returns the [AssetId] of the Dart library or part declaring [element] .
76122 ///
77123 /// If [element] is defined in the SDK or in a summary throws
@@ -81,6 +127,16 @@ abstract class Resolver {
81127 /// The returned asset is not necessarily the asset that should be imported to
82128 /// use the element, it may be a part file instead of the library.
83129 Future <AssetId > assetIdForElement (Element element);
130+
131+ /// Returns the [AssetId] of the Dart library or part declaring [element] .
132+ ///
133+ /// If [element] is defined in the SDK or in a summary throws
134+ /// `UnresolvableAssetException` , although a non-throwing return here does not
135+ /// guarantee that the asset is readable.
136+ ///
137+ /// The returned asset is not necessarily the asset that should be imported to
138+ /// use the element, it may be a part file instead of the library.
139+ Future <AssetId > assetIdForElement2 (Element2 element);
84140}
85141
86142/// A resolver that should be manually released at the end of a build step.
0 commit comments