Skip to content

Commit f5f148c

Browse files
authored
Bring up to analyzer 8.1.1, get rid of deprecated classes and methods. (#782)
* Remove deprecated methods and classes in tests. * Remove DartObjectImpl import * Update type_checker.dart * Remove unnecessary comment
1 parent 469d242 commit f5f148c

25 files changed

+216
-280
lines changed

example/lib/src/multiplier_generator.dart

Lines changed: 3 additions & 5 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:source_gen/source_gen.dart';
108

@@ -13,13 +11,13 @@ import '../annotations.dart';
1311
class MultiplierGenerator extends GeneratorForAnnotation<Multiplier> {
1412
@override
1513
String generateForAnnotatedElement(
16-
Element2 element,
14+
Element element,
1715
ConstantReader annotation,
1816
BuildStep buildStep,
1917
) {
2018
final numValue = annotation.read('value').literalValue as num;
2119

22-
return 'num ${element.name3}Multiplied() => ${element.name3} * $numValue;';
20+
return 'num ${element.name}Multiplied() => ${element.name} * $numValue;';
2321
}
2422

2523
// Override this method to respond to annotations on directives: `import`,

example/lib/src/property_product_generator.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class PropertyProductGenerator extends Generator {
1212
String generate(LibraryReader library, BuildStep buildStep) {
1313
final productNames = topLevelNumVariables(
1414
library,
15-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
16-
).map((element) => element.name3).join(' * ');
15+
).map((element) => element.name).join(' * ');
1716

1817
return '''
1918
num allProduct() => $productNames;

example/lib/src/property_sum_generator.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class PropertySumGenerator extends Generator {
1212
String generate(LibraryReader library, BuildStep buildStep) {
1313
final sumNames = topLevelNumVariables(
1414
library,
15-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
16-
).map((element) => element.name3).join(' + ');
15+
).map((element) => element.name).join(' + ');
1716

1817
return '''
1918
num allSum() => $sumNames;

example/lib/src/utils.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
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

10-
/// Returns all [TopLevelVariableElement2] members in [reader]'s library that
8+
/// Returns all [TopLevelVariableElement] members in [reader]'s library that
119
/// have a type of [num].
12-
Iterable<TopLevelVariableElement2> topLevelNumVariables(LibraryReader reader) =>
13-
reader.allElements.whereType<TopLevelVariableElement2>().where(
10+
Iterable<TopLevelVariableElement> topLevelNumVariables(LibraryReader reader) =>
11+
reader.allElements.whereType<TopLevelVariableElement>().where(
1412
(element) =>
1513
element.type.isDartCoreNum ||
1614
element.type.isDartCoreInt ||

source_gen/lib/src/builder.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import 'dart:convert';
66

77
import 'package:analyzer/dart/ast/ast.dart';
8-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
9-
import 'package:analyzer/dart/element/element2.dart';
8+
import 'package:analyzer/dart/element/element.dart';
109
import 'package:build/build.dart';
1110
import 'package:dart_style/dart_style.dart';
1211
import 'package:pub_semver/pub_semver.dart';
@@ -110,8 +109,7 @@ class _Builder extends Builder {
110109
}
111110

112111
Future<void> _generateForLibrary(
113-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
114-
LibraryElement2 library,
112+
LibraryElement library,
115113
BuildStep buildStep,
116114
) async {
117115
final generatedOutputs =
@@ -357,8 +355,7 @@ class LibraryBuilder extends _Builder {
357355
}
358356

359357
Stream<GeneratedOutput> _generate(
360-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
361-
LibraryElement2 library,
358+
LibraryElement library,
362359
List<Generator> generators,
363360
BuildStep buildStep,
364361
) async* {
@@ -450,8 +447,7 @@ const partIdRegExpLiteral = r'[A-Za-z_\d-]+';
450447

451448
final _partIdRegExp = RegExp('^$partIdRegExpLiteral\$');
452449

453-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
454-
String languageOverrideForLibrary(LibraryElement2 library) {
450+
String languageOverrideForLibrary(LibraryElement library) {
455451
final override = library.languageVersion.override;
456452
return override == null
457453
? ''

source_gen/lib/src/constants/reader.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/constant/value.dart';
6-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
7-
import 'package:analyzer/dart/element/element2.dart';
6+
import 'package:analyzer/dart/element/element.dart';
87
import 'package:analyzer/dart/element/type.dart';
98

109
import '../type_checker.dart';
@@ -269,8 +268,7 @@ class _DartObjectConstant extends ConstantReader {
269268
ConstantReader read(String field) {
270269
final reader = peek(field);
271270
if (reader == null) {
272-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
273-
assertHasField(objectValue.type!.element3 as InterfaceElement2, field);
271+
assertHasField(objectValue.type!.element as InterfaceElement, field);
274272
return const _NullConstant();
275273
}
276274
return reader;

source_gen/lib/src/constants/revive.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
// TODO(kevmoo): migrate analyzer APIs when we can get latest with a stable SDK
6-
// ignore_for_file: deprecated_member_use
76

87
import 'package:analyzer/dart/constant/value.dart';
9-
import 'package:analyzer/dart/element/element2.dart';
8+
import 'package:analyzer/dart/element/element.dart';
109
import 'package:analyzer/dart/element/type.dart';
11-
// ignore: implementation_imports
12-
import 'package:analyzer/src/dart/constant/value.dart' show DartObjectImpl;
1310

1411
import '../utils.dart';
1512

@@ -22,37 +19,37 @@ import '../utils.dart';
2219
/// **NOTE**: Some returned [Revivable] instances are not representable as valid
2320
/// Dart source code (such as referencing private constructors). It is up to the
2421
/// build tool(s) using this library to surface error messages to the user.
25-
Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) {
22+
Revivable reviveInstance(DartObject object, [LibraryElement? origin]) {
2623
final objectType = object.type;
27-
Element2? element = objectType!.alias?.element2;
24+
Element? element = objectType!.alias?.element;
2825
if (element == null) {
2926
if (objectType is InterfaceType) {
30-
element = objectType.element3;
27+
element = objectType.element;
3128
} else {
32-
element = object.toFunctionValue2();
29+
element = object.toFunctionValue();
3330
}
3431
}
35-
origin ??= element!.library2;
32+
origin ??= element!.library;
3633
var url = Uri.parse(urlOfElement(element!));
3734
if (element is TopLevelFunctionElement || element is LocalFunctionElement) {
38-
return Revivable._(source: url.removeFragment(), accessor: element.name3!);
35+
return Revivable._(source: url.removeFragment(), accessor: element.name!);
3936
}
4037

41-
if (element is MethodElement2 && element.isStatic) {
38+
if (element is MethodElement && element.isStatic) {
4239
return Revivable._(
4340
source: url.removeFragment(),
4441
accessor:
45-
'${element.firstFragment.enclosingFragment!.name2}.${element.name3}',
42+
'${element.firstFragment.enclosingFragment!.name}.${element.name}',
4643
);
4744
}
4845

49-
if (element is InterfaceElement2) {
50-
for (final e in element.fields2.where(
46+
if (element is InterfaceElement) {
47+
for (final e in element.fields.where(
5148
(f) => f.isPublic && f.isConst && f.computeConstantValue() == object,
5249
)) {
5350
return Revivable._(
5451
source: url.removeFragment(),
55-
accessor: '${element.name3}.${e.name3}',
52+
accessor: '${element.name}.${e.name}',
5653
);
5754
}
5855
}
@@ -67,25 +64,25 @@ Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) {
6764
}
6865

6966
for (final type in origin!.classes) {
70-
for (final e in type.fields2.where(
67+
for (final e in type.fields.where(
7168
(f) => f.isConst && f.computeConstantValue() == object,
7269
)) {
7370
final result = Revivable._(
7471
source: url.removeFragment(),
75-
accessor: '${type.name3}.${e.name3}',
72+
accessor: '${type.name}.${e.name}',
7673
);
7774
if (tryResult(result)) {
7875
return result;
7976
}
8077
}
8178
}
82-
final i = (object as DartObjectImpl).getInvocation();
79+
final i = object.constructorInvocation;
8380
if (i != null) {
84-
url = Uri.parse(urlOfElement(i.constructor2.enclosingElement2));
81+
url = Uri.parse(urlOfElement(i.constructor.enclosingElement));
8582
String newToEmpty(String string) => string == 'new' ? '' : string;
8683
final result = Revivable._(
8784
source: url,
88-
accessor: newToEmpty(i.constructor2.name3!),
85+
accessor: newToEmpty(i.constructor.name!),
8986
namedArguments: i.namedArguments,
9087
positionalArguments: i.positionalArguments,
9188
);
@@ -98,7 +95,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) {
9895
)) {
9996
final result = Revivable._(
10097
source: Uri.parse(urlOfElement(origin)).replace(fragment: ''),
101-
accessor: e.name3!,
98+
accessor: e.name!,
10299
);
103100
if (tryResult(result)) {
104101
return result;

source_gen/lib/src/constants/utils.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,29 @@
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

108
/// Throws a [FormatException] if [root] does not have a given field [name].
119
///
12-
/// Super types [InterfaceElement2.supertype] are also checked before throwing.
13-
void assertHasField(InterfaceElement2 root, String name) {
14-
InterfaceElement2? element = root;
10+
/// Super types [InterfaceElement.supertype] are also checked before throwing.
11+
void assertHasField(InterfaceElement root, String name) {
12+
InterfaceElement? element = root;
1513
while (element != null) {
16-
final field = element.getField2(name);
14+
final field = element.getField(name);
1715
if (field != null) {
1816
return;
1917
}
20-
element = element.supertype?.element3;
18+
element = element.supertype?.element;
2119
}
2220
final allFields = {
23-
...root.fields2,
24-
for (var t in root.allSupertypes) ...t.element3.fields2,
21+
...root.fields,
22+
for (var t in root.allSupertypes) ...t.element.fields,
2523
};
2624

2725
throw FormatException(
28-
'Class ${root.name3} does not have field "$name".',
29-
'Fields: \n - ${allFields.map((e) => e.name3).join('\n - ')}',
26+
'Class ${root.name} does not have field "$name".',
27+
'Fields: \n - ${allFields.map((e) => e.name).join('\n - ')}',
3028
);
3129
}
3230

source_gen/lib/src/generator.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import 'dart:async';
66

77
import 'package:analyzer/dart/ast/ast.dart';
8-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
9-
import 'package:analyzer/dart/element/element2.dart';
8+
import 'package:analyzer/dart/element/element.dart';
109
import 'package:build/build.dart';
1110
import 'package:source_span/source_span.dart';
1211

@@ -48,8 +47,7 @@ class InvalidGenerationSource implements Exception {
4847
final String todo;
4948

5049
/// The `Element2` associated with this error, if any.
51-
/// ignore: deprecated_member_use until analyzer 7 support is dropped.
52-
final Element2? element;
50+
final Element? element;
5351

5452
/// The [ElementDirective] associated with this error, if any.
5553
final ElementDirective? elementDirective;

source_gen/lib/src/generator_for_annotation.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import 'dart:async';
66

7-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
8-
import 'package:analyzer/dart/element/element2.dart';
7+
import 'package:analyzer/dart/element/element.dart';
98
import 'package:build/build.dart';
109

1110
import 'constants/reader.dart';
@@ -127,8 +126,7 @@ abstract class GeneratorForAnnotation<T> extends Generator {
127126
/// Implementations should return `null` when no content is generated. Empty
128127
/// or whitespace-only [String] instances are also ignored.
129128
dynamic generateForAnnotatedElement(
130-
// ignore: deprecated_member_use until analyzer 7 support is dropped.
131-
Element2 element,
129+
Element element,
132130
ConstantReader annotation,
133131
BuildStep buildStep,
134132
) {}

0 commit comments

Comments
 (0)