Skip to content

Require analyzer 6.10.0, stop using deprecated properties of LibraryElement. #3899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Library extends ModelElement
var localElements = {
// TODO(jcollins-g): Consider switch to `element.topLevelElements`.
..._getDefinedElements(element.definingCompilationUnit),
...element.parts
...element.definingCompilationUnit.parts
.map((e) => e.uri)
.whereType<DirectiveUriWithUnit>()
.map((part) => part.unit)
Expand Down Expand Up @@ -96,7 +96,7 @@ class Library extends ModelElement

/// Allow scope for Libraries.
@override
Scope get scope => element.scope;
Scope get scope => element.definingCompilationUnit.scope;

bool get isInSdk => element.isInSdk;

Expand Down Expand Up @@ -142,7 +142,7 @@ class Library extends ModelElement
Map<String, Set<Library>> get _prefixToLibrary {
var prefixToLibrary = <String, Set<Library>>{};
// It is possible to have overlapping prefixes.
for (var i in element.libraryImports) {
for (var i in element.definingCompilationUnit.libraryImports) {
var prefixName = i.prefix?.element.name;
// Ignore invalid imports.
if (prefixName != null && i.importedLibrary != null) {
Expand Down
10 changes: 4 additions & 6 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,17 @@ extension on Set<String> {

if (add(path)) {
var libraryImports = switch (element) {
LibraryElement(:var libraryImports) ||
CompilationUnitElement(:var libraryImports) =>
libraryImports,
LibraryElement() => element.definingCompilationUnit.libraryImports,
CompilationUnitElement(:var libraryImports) => libraryImports,
_ => const <LibraryImportElement>[],
};
for (var import in libraryImports) {
addFilesReferencedBy(import.importedLibrary);
}

var libraryExports = switch (element) {
LibraryElement(:var libraryExports) ||
CompilationUnitElement(:var libraryExports) =>
libraryExports,
LibraryElement() => element.definingCompilationUnit.libraryExports,
CompilationUnitElement(:var libraryExports) => libraryExports,
_ => const <LibraryExportElement>[],
};
for (var export in libraryExports) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ class PackageGraph with CommentReferable, Nameable {
alreadyTagged.add(key);
// Mark that `publicLibrary` exports `libraryElement`.
_libraryExports.putIfAbsent(libraryElement, () => {}).add(publicLibrary);
for (var exportedElement in libraryElement.libraryExports) {
for (var exportedElement
in libraryElement.definingCompilationUnit.libraryExports) {
var exportedLibrary = exportedElement.exportedLibrary;
if (exportedLibrary != null) {
// Follow the exports down; as `publicLibrary` exports `libraryElement`,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/prefix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Prefix extends ModelElement with HasNoPage {
// TODO(jcollins-g): consider connecting PrefixElement to the imported library
// in analyzer?
late final Library associatedLibrary = getModelForElement(library
.element.libraryImports
.element.definingCompilationUnit.libraryImports
.firstWhere((i) => i.prefix?.element == element)
.importedLibrary!) as Library;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ^3.2.0

dependencies:
analyzer: ^6.9.0
analyzer: ^6.10.0
args: ^2.4.1
collection: ^1.17.0
crypto: ^3.0.3
Expand Down
10 changes: 8 additions & 2 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,14 @@ void main() async {
test('can import other libraries with unusual URIs', () {
final fakeLibraryImportedExported = <Library>{
for (final l in <LibraryElement>{
...fakeLibrary.element.importedLibraries,
...fakeLibrary.element.exportedLibraries
...fakeLibrary.element.definingCompilationUnit.libraryImports
.map((import) => import.uri)
.whereType<DirectiveUriWithLibrary>()
.map((uri) => uri.library),
...fakeLibrary.element.definingCompilationUnit.libraryExports
.map((import) => import.uri)
.whereType<DirectiveUriWithLibrary>()
.map((uri) => uri.library)
})
packageGraph.getModelForElement(l) as Library
};
Expand Down
Loading