Skip to content

Commit de76fde

Browse files
committed
Remove deprecated methods and classes in tests.
1 parent a8b2a2d commit de76fde

9 files changed

+94
-120
lines changed

source_gen/test/constants/utils_test.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
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 until analyzer 7 support is dropped.
6-
75
import 'package:analyzer/dart/constant/value.dart';
8-
import 'package:analyzer/dart/element/element2.dart';
6+
import 'package:analyzer/dart/element/element.dart';
97
import 'package:build_test/build_test.dart';
108
import 'package:source_gen/src/constants/utils.dart';
119
import 'package:test/test.dart';
1210

1311
void main() {
1412
group('assertHasField', () {
15-
late LibraryElement2 testLib;
13+
late LibraryElement testLib;
1614

1715
setUpAll(() async {
1816
testLib = await resolveSource(
@@ -36,17 +34,17 @@ void main() {
3634
});
3735

3836
test('should not throw when a class contains a field', () {
39-
final $A = testLib.getClass2('A')!;
37+
final $A = testLib.getClass('A')!;
4038
expect(() => assertHasField($A, 'a'), returnsNormally);
4139
});
4240

4341
test('should not throw when a super class contains a field', () {
44-
final $B = testLib.getClass2('B')!;
42+
final $B = testLib.getClass('B')!;
4543
expect(() => assertHasField($B, 'a'), returnsNormally);
4644
});
4745

4846
test('should throw when a class does not contain a field', () {
49-
final $C = testLib.getClass2('C')!;
47+
final $C = testLib.getClass('C')!;
5048
expect(() => assertHasField($C, 'a'), throwsFormatException);
5149
});
5250
});
@@ -86,8 +84,8 @@ void main() {
8684
);
8785
objects =
8886
testLib
89-
.getClass2('Example')!
90-
.metadata2
87+
.getClass('Example')!
88+
.metadata
9189
.annotations
9290
.map((e) => e.computeConstantValue()!)
9391
.toList();

source_gen/test/constants_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 until analyzer 7 support is dropped.
6-
75
import 'package:analyzer/dart/constant/value.dart';
86
import 'package:build_test/build_test.dart';
97
import 'package:source_gen/source_gen.dart';
@@ -61,8 +59,8 @@ void main() {
6159
''', (resolver) async => (await resolver.findLibraryByName('test_lib'))!);
6260
constants =
6361
library
64-
.getClass2('Example')!
65-
.metadata2
62+
.getClass('Example')!
63+
.metadata
6664
.annotations
6765
.map((e) => ConstantReader(e.computeConstantValue()!))
6866
.toList();
@@ -157,7 +155,7 @@ void main() {
157155

158156
test('should read a Type', () {
159157
expect(constants[11].isType, isTrue);
160-
expect(constants[11].typeValue.element3!.name3, 'DateTime');
158+
expect(constants[11].typeValue.element!.name, 'DateTime');
161159
expect(constants[11].isLiteral, isFalse);
162160
expect(() => constants[11].literalValue, throwsFormatException);
163161
});
@@ -304,8 +302,8 @@ void main() {
304302
''', (resolver) async => (await resolver.findLibraryByName('test_lib'))!);
305303
constants =
306304
library
307-
.getClass2('Example')!
308-
.metadata2
305+
.getClass('Example')!
306+
.metadata
309307
.annotations
310308
.map((e) => ConstantReader(e.computeConstantValue()))
311309
.toList();

source_gen/test/external_only_type_checker_test.dart

Lines changed: 2 additions & 4 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 until analyzer 7 support is dropped.
6-
75
// The tests in this file are only ran externally, as the behavior only works
86
// externally. Internally this test is skipped.
97

@@ -58,7 +56,7 @@ void main() {
5856
expect(
5957
checkNonPublic().isExactlyType(staticNonPublic),
6058
isTrue,
61-
reason: '${checkNonPublic()} != ${staticNonPublic.element3.name3}',
59+
reason: '${checkNonPublic()} != ${staticNonPublic.element.name}',
6260
);
6361
});
6462

@@ -68,7 +66,7 @@ void main() {
6866
isTrue,
6967
reason:
7068
'${checkNonPublic()} is not assignable from '
71-
'${staticNonPublic.element3.name3}',
69+
'${staticNonPublic.element.name}',
7270
);
7371
});
7472
});

source_gen/test/library/find_type_test.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
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 until analyzer 7 support is dropped.
6-
7-
import 'package:analyzer/dart/element/element2.dart';
5+
import 'package:analyzer/dart/element/element.dart';
86
import 'package:build/build.dart';
97
import 'package:build_test/build_test.dart';
108
import 'package:source_gen/source_gen.dart';
@@ -46,11 +44,11 @@ void main() {
4644
});
4745

4846
test('class count', () {
49-
expect(library.classes.map((c) => c.name3), ['Example', 'PartClass']);
47+
expect(library.classes.map((c) => c.name), ['Example', 'PartClass']);
5048
});
5149

5250
test('enum count', () {
53-
expect(library.enums.map((e) => e.name3), ['Enum', 'PartEnum']);
51+
expect(library.enums.map((e) => e.name), ['Enum', 'PartEnum']);
5452
});
5553

5654
test('should return a type not exported', () {
@@ -74,4 +72,4 @@ void main() {
7472
});
7573
}
7674

77-
const _isClassElement = TypeMatcher<ClassElement2>();
75+
const _isClassElement = TypeMatcher<ClassElement>();

source_gen/test/library/path_to_url_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
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 until analyzer 7 support is dropped.
6-
75
// Increase timeouts on this test which resolves source code and can be slow.
8-
import 'package:analyzer/dart/element/element2.dart';
6+
import 'package:analyzer/dart/element/element.dart';
97
import 'package:source_gen/source_gen.dart';
108
import 'package:test/test.dart';
119

@@ -159,7 +157,7 @@ void main() {
159157
});
160158
}
161159

162-
class _FakeLibraryElement implements LibraryElement2 {
160+
class _FakeLibraryElement implements LibraryElement {
163161
final Uri _uri;
164162

165163
_FakeLibraryElement(this._uri);

source_gen/test/span_for_element_test.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
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 until analyzer 7 support is dropped.
6-
7-
import 'package:analyzer/dart/element/element2.dart';
5+
import 'package:analyzer/dart/element/element.dart';
86
import 'package:build/build.dart';
97
import 'package:build_test/build_test.dart';
108
import 'package:source_gen/src/span_for_element.dart';
@@ -13,7 +11,7 @@ import 'package:test/test.dart';
1311

1412
void main() {
1513
glyph.ascii = true;
16-
late LibraryElement2 library;
14+
late LibraryElement library;
1715
late Resolver resolver;
1816

1917
setUpAll(() async {
@@ -41,7 +39,7 @@ abstract class Example implements List {
4139

4240
test('should highlight the use of "class Example"', () async {
4341
expect(
44-
spanForElement(library.getClass2('Example')!).message('Here it is'),
42+
spanForElement(library.getClass('Example')!).message('Here it is'),
4543
r"""
4644
line 3, column 16 of package:test_lib/test_lib.dart: Here it is
4745
,
@@ -54,7 +52,7 @@ line 3, column 16 of package:test_lib/test_lib.dart: Here it is
5452
test('should correctly highlight getter', () async {
5553
expect(
5654
spanForElement(
57-
library.getClass2('Example')!.getField2('getter')!,
55+
library.getClass('Example')!.getField('getter')!,
5856
).message('Here it is'),
5957
r"""
6058
line 4, column 15 of package:test_lib/test_lib.dart: Here it is
@@ -68,7 +66,7 @@ line 4, column 15 of package:test_lib/test_lib.dart: Here it is
6866
test('should correctly highlight setter', () async {
6967
expect(
7068
spanForElement(
71-
library.getClass2('Example')!.getField2('setter')!,
69+
library.getClass('Example')!.getField('setter')!,
7270
).message('Here it is'),
7371
r"""
7472
line 5, column 7 of package:test_lib/test_lib.dart: Here it is
@@ -82,7 +80,7 @@ line 5, column 7 of package:test_lib/test_lib.dart: Here it is
8280
test('should correctly highlight field', () async {
8381
expect(
8482
spanForElement(
85-
library.getClass2('Example')!.getField2('field')!,
83+
library.getClass('Example')!.getField('field')!,
8684
).message('Here it is'),
8785
r"""
8886
line 6, column 7 of package:test_lib/test_lib.dart: Here it is
@@ -96,7 +94,7 @@ line 6, column 7 of package:test_lib/test_lib.dart: Here it is
9694
test('highlight getter with getter/setter property', () async {
9795
expect(
9896
spanForElement(
99-
library.getClass2('Example')!.getField2('fieldProp')!,
97+
library.getClass('Example')!.getField('fieldProp')!,
10098
).message('Here it is'),
10199
r"""
102100
line 7, column 11 of package:test_lib/test_lib.dart: Here it is
@@ -109,7 +107,7 @@ line 7, column 11 of package:test_lib/test_lib.dart: Here it is
109107

110108
test('highlights based on AstNode source location', () async {
111109
final element =
112-
library.getClass2('Example')!.getField2('field')!.firstFragment;
110+
library.getClass('Example')!.getField('field')!.firstFragment;
113111
final node = (await resolver.astNodeFor(element, resolve: true))!;
114112
expect(spanForNode(node).message('Here it is'), r"""
115113
line 6, column 7 of package:test_lib/test_lib.dart: Here it is

source_gen/test/src/comment_generator.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
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 until analyzer 7 support is dropped.
6-
7-
import 'package:analyzer/dart/element/element2.dart';
5+
import 'package:analyzer/dart/element/element.dart';
86
import 'package:source_gen/source_gen.dart';
97

108
/// Generates a single-line comment for each class
@@ -17,7 +15,7 @@ class CommentGenerator extends Generator {
1715
Future<String> generate(LibraryReader library, _) async {
1816
final output = <String>[];
1917
if (forLibrary) {
20-
var name = library.element.name3!;
18+
var name = library.element.name!;
2119
if (name.isEmpty) {
2220
name = library.element.uri.pathSegments.last;
2321
}
@@ -46,7 +44,7 @@ class CommentGenerator extends Generator {
4644
// No directive relates to the class, just throw with the first
4745
// export.
4846
elementDirective:
49-
classElement.library2.firstFragment.libraryExports2.first,
47+
classElement.library.firstFragment.libraryExports.first,
5048
);
5149
}
5250
output.add('// Code for "$classElement"');
@@ -60,6 +58,6 @@ class CommentGenerator extends Generator {
6058
class DeprecatedGeneratorForAnnotation
6159
extends GeneratorForAnnotation<Deprecated> {
6260
@override
63-
String generateForAnnotatedElement(Element2 element, _, _) =>
61+
String generateForAnnotatedElement(Element element, _, _) =>
6462
'// "$element" is deprecated!';
6563
}

0 commit comments

Comments
 (0)