Skip to content

Commit 92218f0

Browse files
authored
Stop using deprecated analyzer API. (#4287)
1 parent 58fc033 commit 92218f0

File tree

6 files changed

+67
-83
lines changed

6 files changed

+67
-83
lines changed

build_runner/test/build/build_step_impl_test.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4-
// ignore_for_file: deprecated_member_use
54

65
@TestOn('vm')
76
library;
@@ -147,18 +146,18 @@ void main() {
147146
final resolver = buildStep.resolver;
148147

149148
final aLib = await resolver.libraryFor(primary);
150-
expect(aLib.name3, 'a');
151-
expect(aLib.firstFragment.libraryImports2.length, 2);
149+
expect(aLib.name, 'a');
150+
expect(aLib.firstFragment.libraryImports.length, 2);
152151
expect(
153-
aLib.firstFragment.libraryImports2.any(
154-
(import) => import.importedLibrary2!.name3 == 'b',
152+
aLib.firstFragment.libraryImports.any(
153+
(import) => import.importedLibrary!.name == 'b',
155154
),
156155
isTrue,
157156
);
158157

159158
final bLib = await resolver.findLibraryByName('b');
160-
expect(bLib!.name3, 'b');
161-
expect(bLib.firstFragment.libraryImports2.length, 1);
159+
expect(bLib!.name, 'b');
160+
expect(bLib.firstFragment.libraryImports.length, 1);
162161

163162
await buildStep.complete();
164163
});

build_runner/test/build/resolution_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: deprecated_member_use
6-
75
import 'dart:async';
86

97
import 'package:build/build.dart';
@@ -57,7 +55,7 @@ class ListClassesAndHierarchyBuilder implements Builder {
5755
final outputId = buildStep.inputId.changeExtension('.txt');
5856
for (final type in types) {
5957
output
60-
..write('${type.name3}: [')
58+
..write('${type.name}: [')
6159
..writeAll(type.allSupertypes.map((t) => t.element.name), ', ')
6260
..writeln(']');
6361
}

build_runner/test/build/resolver/resolver_test.dart

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: deprecated_member_use
6-
75
import 'dart:io' show Platform;
86
import 'dart:isolate';
97

@@ -69,13 +67,13 @@ void runTests(ResolversFactory resolversFactory) {
6967
},
7068
(resolver) async {
7169
final lib = await resolver.libraryFor(entryPoint);
72-
expect(lib.firstFragment.libraryImports2.length, 2);
70+
expect(lib.firstFragment.libraryImports.length, 2);
7371
final libA =
7472
lib
75-
..firstFragment.libraryImports2
76-
.where((l) => l.importedLibrary2!.name3 == 'a')
73+
..firstFragment.libraryImports
74+
.where((l) => l.importedLibrary!.name == 'a')
7775
.single;
78-
expect(libA.getClass2('Foo'), isNull);
76+
expect(libA.getClass('Foo'), isNull);
7977
},
8078
resolvers: createResolvers(),
8179
);
@@ -113,13 +111,13 @@ void runTests(ResolversFactory resolversFactory) {
113111
},
114112
(resolver) async {
115113
final lib = await resolver.libraryFor(entryPoint);
116-
expect(lib.firstFragment.libraryImports2.length, 2);
114+
expect(lib.firstFragment.libraryImports.length, 2);
117115
final libB =
118116
lib
119-
..firstFragment.libraryImports2
120-
.where((l) => l.importedLibrary2!.name3 == 'b')
117+
..firstFragment.libraryImports
118+
.where((l) => l.importedLibrary!.name == 'b')
121119
.single;
122-
expect(libB.getClass2('Foo'), isNull);
120+
expect(libB.getClass('Foo'), isNull);
123121
},
124122
resolvers: createResolvers(),
125123
);
@@ -162,8 +160,8 @@ void runTests(ResolversFactory resolversFactory) {
162160
},
163161
(resolver) async {
164162
final lib = await resolver.libraryFor(entryPoint);
165-
expect(lib.getClass2('A'), isNotNull);
166-
expect(lib.getClass2('B'), isNull);
163+
expect(lib.getClass('A'), isNotNull);
164+
expect(lib.getClass('B'), isNull);
167165
},
168166
resolvers: resolvers,
169167
);
@@ -179,8 +177,8 @@ void runTests(ResolversFactory resolversFactory) {
179177
},
180178
(resolver) async {
181179
final lib = await resolver.libraryFor(entryPoint);
182-
expect(lib.getClass2('A'), isNull);
183-
expect(lib.getClass2('B'), isNotNull);
180+
expect(lib.getClass('A'), isNull);
181+
expect(lib.getClass('B'), isNotNull);
184182
},
185183
resolvers: resolvers,
186184
);
@@ -200,8 +198,8 @@ void runTests(ResolversFactory resolversFactory) {
200198
},
201199
(resolver) async {
202200
final lib = await resolver.libraryFor(entryPoint);
203-
expect(lib.getClass2('A'), isNotNull);
204-
expect(lib.getClass2('B'), isNull);
201+
expect(lib.getClass('A'), isNotNull);
202+
expect(lib.getClass('B'), isNull);
205203
},
206204
resolvers: resolvers,
207205
);
@@ -221,8 +219,8 @@ void runTests(ResolversFactory resolversFactory) {
221219
},
222220
(resolver) async {
223221
final lib = await resolver.libraryFor(entryPoint);
224-
expect(lib.getClass2('A'), isNull);
225-
expect(lib.getClass2('B'), isNotNull);
222+
expect(lib.getClass('A'), isNull);
223+
expect(lib.getClass('B'), isNotNull);
226224
},
227225
resolvers: resolvers,
228226
);
@@ -246,14 +244,14 @@ void runTests(ResolversFactory resolversFactory) {
246244
final sourcesWithoutB = Map.of(sources)..remove('a|web/b.dart');
247245
await resolveSources(sourcesWithoutB, (resolver) async {
248246
final lib = await resolver.libraryFor(entryPoint);
249-
final clazz = lib.getClass2('A');
247+
final clazz = lib.getClass('A');
250248
expect(clazz, isNotNull);
251249
expect(clazz!.interfaces, isEmpty);
252250
}, resolvers: resolvers);
253251

254252
await resolveSources(sources, (resolver) async {
255253
final lib = await resolver.libraryFor(entryPoint);
256-
final clazz = lib.getClass2('A');
254+
final clazz = lib.getClass('A');
257255
expect(clazz, isNotNull);
258256
expect(clazz!.interfaces, hasLength(1));
259257
expect(clazz.interfaces.first.getDisplayString(), 'C');
@@ -454,21 +452,21 @@ void runTests(ResolversFactory resolversFactory) {
454452
expect(main, isNotNull);
455453

456454
final other = await resolver.libraryFor(otherId);
457-
expect(other.name3, 'other');
455+
expect(other.name, 'other');
458456
});
459457
});
460458

461459
test('are included in library stream', () {
462460
return runWith((resolver) async {
463461
await expectLater(
464-
resolver.libraries.map((l) => l.name3),
462+
resolver.libraries.map((l) => l.name),
465463
neverEmits('other'),
466464
);
467465

468466
await resolver.libraryFor(otherId);
469467

470468
await expectLater(
471-
resolver.libraries.map((l) => l.name3),
469+
resolver.libraries.map((l) => l.name),
472470
emitsThrough('other'),
473471
);
474472
});
@@ -516,7 +514,7 @@ void runTests(ResolversFactory resolversFactory) {
516514
},
517515
(resolver) async {
518516
final lib = await resolver.libraryFor(entryPoint);
519-
final clazz = lib.getClass2('A');
517+
final clazz = lib.getClass('A');
520518
expect(clazz, isNotNull);
521519
expect(clazz!.interfaces, isEmpty);
522520
},
@@ -537,7 +535,7 @@ void runTests(ResolversFactory resolversFactory) {
537535
},
538536
(resolver) async {
539537
final lib = await resolver.libraryFor(entryPoint);
540-
final clazz = lib.getClass2('A');
538+
final clazz = lib.getClass('A');
541539
expect(clazz, isNotNull);
542540
expect(clazz!.interfaces, hasLength(1));
543541
expect(clazz.interfaces.first.getDisplayString(), 'B');
@@ -562,7 +560,7 @@ void runTests(ResolversFactory resolversFactory) {
562560
},
563561
(resolver) async {
564562
final lib = await resolver.libraryFor(entryPoint);
565-
final clazz = lib.getClass2('A');
563+
final clazz = lib.getClass('A');
566564
expect(clazz, isNotNull);
567565
expect(clazz!.interfaces, hasLength(1));
568566
expect(clazz.interfaces.first.getDisplayString(), 'B');
@@ -582,7 +580,7 @@ void runTests(ResolversFactory resolversFactory) {
582580
},
583581
(resolver) async {
584582
final lib = await resolver.libraryFor(entryPoint);
585-
final clazz = lib.getClass2('A');
583+
final clazz = lib.getClass('A');
586584
expect(clazz, isNotNull);
587585
expect(clazz!.interfaces, isEmpty);
588586
},
@@ -608,7 +606,7 @@ void runTests(ResolversFactory resolversFactory) {
608606
final libs =
609607
await resolver.libraries.where((l) => !l.isInSdk).toList();
610608
expect(
611-
libs.map((l) => l.name3),
609+
libs.map((l) => l.name),
612610
unorderedEquals(['a.main', 'a.a', 'a.b', 'a.c', 'a.d']),
613611
);
614612
},
@@ -673,12 +671,7 @@ void runTests(ResolversFactory resolversFactory) {
673671
(resolver) async {
674672
final main = (await resolver.findLibraryByName('web.main'))!;
675673
final meta =
676-
main
677-
.getClass2('Foo')!
678-
.supertype!
679-
.element3
680-
.metadata2
681-
.annotations[0];
674+
main.getClass('Foo')!.supertype!.element.metadata.annotations[0];
682675
expect(meta, isNotNull);
683676
expect(meta.computeConstantValue()?.toIntValue(), 0);
684677
},
@@ -700,8 +693,7 @@ void runTests(ResolversFactory resolversFactory) {
700693
import 'package:a/a.dart'; ''',
701694
},
702695
(resolver) async {
703-
final libs =
704-
await resolver.libraries.map((lib) => lib.name3).toList();
696+
final libs = await resolver.libraries.map((lib) => lib.name).toList();
705697
expect(libs.contains('a'), isTrue);
706698
expect(libs.contains('b'), isTrue);
707699
},
@@ -725,8 +717,8 @@ void runTests(ResolversFactory resolversFactory) {
725717
(resolver) async {
726718
final entry = await resolver.libraryFor(AssetId('a', 'lib/a.dart'));
727719
final classDefinition =
728-
entry.firstFragment.libraryImports2
729-
.map((l) => l.importedLibrary2!.getClass2('SomeClass'))
720+
entry.firstFragment.libraryImports
721+
.map((l) => l.importedLibrary!.getClass('SomeClass'))
730722
.singleWhere((c) => c != null)!;
731723
expect(
732724
await resolver.assetIdForElement(classDefinition),
@@ -758,11 +750,11 @@ void runTests(ResolversFactory resolversFactory) {
758750
final entry = await resolver.libraryFor(AssetId('a', 'lib/a.dart'));
759751
final element =
760752
entry.topLevelFunctions
761-
.firstWhere((e) => e.name3 == 'main')
762-
.metadata2
753+
.firstWhere((e) => e.name == 'main')
754+
.metadata
763755
.annotations
764756
.single
765-
.element2!;
757+
.element!;
766758
await expectLater(
767759
() => resolver.assetIdForElement(element),
768760
throwsA(isA<UnresolvableAssetException>()),
@@ -795,7 +787,7 @@ int? get x => 1;
795787
);
796788
final errors =
797789
await lib.session.getErrors('/a/web/main.dart') as ErrorsResult;
798-
expect(errors.errors, isEmpty);
790+
expect(errors.diagnostics, isEmpty);
799791
},
800792
resolvers: createResolvers(),
801793
),
@@ -819,7 +811,7 @@ int? get x => 1;
819811
await resolver.assetIdForElement(lib),
820812
);
821813
expect(
822-
await newLib.session.getResolvedLibraryByElement2(newLib),
814+
await newLib.session.getResolvedLibraryByElement(newLib),
823815
isA<ResolvedLibraryResult>(),
824816
);
825817
}, resolvers: resolvers);
@@ -1042,7 +1034,7 @@ int? get x => 1;
10421034
await resolveSources({'a|lib/a.dart': ''}, (resolver) async {
10431035
final convert = await resolver.findLibraryByName('dart.convert');
10441036
expect(convert, isNotNull);
1045-
expect(convert!.getClass2('Codec'), isNotNull);
1037+
expect(convert!.getClass('Codec'), isNotNull);
10461038
final allLibraries = await resolver.libraries.toList();
10471039
expect(
10481040
allLibraries.map((e) => e.uri.toString()),
@@ -1141,14 +1133,14 @@ int? get x => 1;
11411133
},
11421134
(resolver) async {
11431135
final entry = await resolver.libraryFor(AssetId('a', 'lib/a.dart'));
1144-
final classDefinition = entry.getClass2('MyClass')!;
1145-
final color = classDefinition.getField2('color')!;
1136+
final classDefinition = entry.getClass('MyClass')!;
1137+
final color = classDefinition.getField('color')!;
11461138

11471139
if (isFlutter) {
11481140
expect(color.type.element!.name, equals('Color'));
11491141
expect(color.type.element!.library!.name, equals('dart.ui'));
11501142
expect(
1151-
color.type.element3!.library2!.uri.toString(),
1143+
color.type.element!.library!.uri.toString(),
11521144
equals('dart:ui'),
11531145
);
11541146
} else {

build_runner/test/build/resolver_reuse_test.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: deprecated_member_use
6-
75
import 'dart:async';
86

97
import 'package:build/build.dart';
@@ -54,15 +52,15 @@ void main() {
5452
// Check that the `.imported.dart` library is still reachable
5553
// through the resolver.
5654
final importedLibrary =
57-
inputLibrary.firstFragment.libraryImports2
55+
inputLibrary.firstFragment.libraryImports
5856
.firstWhere(
59-
(l) => l.importedLibrary2!.uri.path.endsWith(
57+
(l) => l.importedLibrary!.uri.path.endsWith(
6058
'.imported.dart',
6159
),
6260
)
63-
.importedLibrary2!;
61+
.importedLibrary!;
6462
final classNames =
65-
importedLibrary.classes.map((c) => c.name3).toList();
63+
importedLibrary.classes.map((c) => c.name).toList();
6664
return buildStep.writeAsString(
6765
buildStep.inputId.addExtension('.bar'),
6866
'$classNames',
@@ -107,7 +105,7 @@ void main() {
107105
if (buildStep.inputId.path != 'lib/a.dart') return;
108106
final library = await buildStep.inputLibrary;
109107
final annotation =
110-
library.topLevelFunctions.single.metadata2.annotations.single
108+
library.topLevelFunctions.single.metadata.annotations.single
111109
.computeConstantValue();
112110
await buildStep.writeAsString(
113111
buildStep.inputId.changeExtension('.g2.dart'),

build_runner/test/invalidation/invalidation_tester.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:async';
66
import 'dart:convert';
77
import 'dart:math';
88

9-
import 'package:analyzer/dart/element/element2.dart';
9+
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:build/build.dart';
1111
import 'package:build_runner/src/constants.dart';
1212
import 'package:build_runner/src/logging/build_log.dart';
@@ -603,17 +603,16 @@ extension AssetIdExtension on AssetId {
603603
AssetId(package, path.replaceAll(RegExp('$from\$'), to));
604604
}
605605

606-
// ignore_for_file: deprecated_member_use
607-
extension TransitiveLibrariesExtension on LibraryElement2 {
606+
extension TransitiveLibrariesExtension on LibraryElement {
608607
/// Finds all transitive imports from this library, excluding SDK libraries.
609-
Set<LibraryElement2> get transitiveImports {
610-
final result = Set<LibraryElement2>.identity();
608+
Set<LibraryElement> get transitiveImports {
609+
final result = Set<LibraryElement>.identity();
611610
final work = [this];
612611

613612
while (work.isNotEmpty) {
614613
final current = work.removeLast();
615614
// For each library found, add its direct dependencies.
616-
for (final library in current.firstFragment.importedLibraries2) {
615+
for (final library in current.firstFragment.importedLibraries) {
617616
if (library.isInSdk) continue;
618617
if (result.add(library)) {
619618
work.add(library);

0 commit comments

Comments
 (0)