Skip to content

Commit 0e2df35

Browse files
committed
Require analyzer 6.10.0, stop using deprecated properties of LibraryElement.
1 parent 5df03dd commit 0e2df35

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

lib/src/model/library.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Library extends ModelElement
6060
var localElements = {
6161
// TODO(jcollins-g): Consider switch to `element.topLevelElements`.
6262
..._getDefinedElements(element.definingCompilationUnit),
63-
...element.parts
63+
...element.definingCompilationUnit.parts
6464
.map((e) => e.uri)
6565
.whereType<DirectiveUriWithUnit>()
6666
.map((part) => part.unit)
@@ -96,7 +96,7 @@ class Library extends ModelElement
9696

9797
/// Allow scope for Libraries.
9898
@override
99-
Scope get scope => element.scope;
99+
Scope get scope => element.definingCompilationUnit.scope;
100100

101101
bool get isInSdk => element.isInSdk;
102102

@@ -142,7 +142,7 @@ class Library extends ModelElement
142142
Map<String, Set<Library>> get _prefixToLibrary {
143143
var prefixToLibrary = <String, Set<Library>>{};
144144
// It is possible to have overlapping prefixes.
145-
for (var i in element.libraryImports) {
145+
for (var i in element.definingCompilationUnit.libraryImports) {
146146
var prefixName = i.prefix?.element.name;
147147
// Ignore invalid imports.
148148
if (prefixName != null && i.importedLibrary != null) {

lib/src/model/package_builder.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,19 +561,17 @@ extension on Set<String> {
561561

562562
if (add(path)) {
563563
var libraryImports = switch (element) {
564-
LibraryElement(:var libraryImports) ||
565-
CompilationUnitElement(:var libraryImports) =>
566-
libraryImports,
564+
LibraryElement() => element.definingCompilationUnit.libraryImports,
565+
CompilationUnitElement(:var libraryImports) => libraryImports,
567566
_ => const <LibraryImportElement>[],
568567
};
569568
for (var import in libraryImports) {
570569
addFilesReferencedBy(import.importedLibrary);
571570
}
572571

573572
var libraryExports = switch (element) {
574-
LibraryElement(:var libraryExports) ||
575-
CompilationUnitElement(:var libraryExports) =>
576-
libraryExports,
573+
LibraryElement() => element.definingCompilationUnit.libraryExports,
574+
CompilationUnitElement(:var libraryExports) => libraryExports,
577575
_ => const <LibraryExportElement>[],
578576
};
579577
for (var export in libraryExports) {

lib/src/model/package_graph.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ class PackageGraph with CommentReferable, Nameable {
554554
alreadyTagged.add(key);
555555
// Mark that `publicLibrary` exports `libraryElement`.
556556
_libraryExports.putIfAbsent(libraryElement, () => {}).add(publicLibrary);
557-
for (var exportedElement in libraryElement.libraryExports) {
557+
for (var exportedElement
558+
in libraryElement.definingCompilationUnit.libraryExports) {
558559
var exportedLibrary = exportedElement.exportedLibrary;
559560
if (exportedLibrary != null) {
560561
// Follow the exports down; as `publicLibrary` exports `libraryElement`,

lib/src/model/prefix.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Prefix extends ModelElement with HasNoPage {
2626
// TODO(jcollins-g): consider connecting PrefixElement to the imported library
2727
// in analyzer?
2828
late final Library associatedLibrary = getModelForElement(library
29-
.element.libraryImports
29+
.element.definingCompilationUnit.libraryImports
3030
.firstWhere((i) => i.prefix?.element == element)
3131
.importedLibrary!) as Library;
3232

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77
sdk: ^3.2.0
88

99
dependencies:
10-
analyzer: ^6.9.0
10+
analyzer: ^6.10.0
1111
args: ^2.4.1
1212
collection: ^1.17.0
1313
crypto: ^3.0.3

test/end2end/model_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,14 @@ void main() async {
909909
test('can import other libraries with unusual URIs', () {
910910
final fakeLibraryImportedExported = <Library>{
911911
for (final l in <LibraryElement>{
912-
...fakeLibrary.element.importedLibraries,
913-
...fakeLibrary.element.exportedLibraries
912+
...fakeLibrary.element.definingCompilationUnit.libraryImports
913+
.map((import) => import.uri)
914+
.whereType<DirectiveUriWithLibrary>()
915+
.map((uri) => uri.library),
916+
...fakeLibrary.element.definingCompilationUnit.libraryExports
917+
.map((import) => import.uri)
918+
.whereType<DirectiveUriWithLibrary>()
919+
.map((uri) => uri.library)
914920
})
915921
packageGraph.getModelForElement(l) as Library
916922
};

0 commit comments

Comments
 (0)