Skip to content

Commit c5aabf9

Browse files
authored
Remove deprecated methods (#751)
* Remove deprecated API. * Fix for prefer_final_locals. * Update example. * Address deprecations in build. * Retrigger CI.
1 parent 957e4cb commit c5aabf9

19 files changed

+22
-236
lines changed

example/lib/src/multiplier_generator.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import '../annotations.dart';
1010

1111
class MultiplierGenerator extends GeneratorForAnnotation<Multiplier> {
1212
@override
13-
String generateForAnnotatedElement2(
13+
String generateForAnnotatedElement(
1414
Element2 element,
1515
ConstantReader annotation,
1616
BuildStep buildStep,

source_gen/lib/builder.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class CombiningBuilder implements Builder {
119119
.join('\n\n');
120120
if (assets.isEmpty) return;
121121

122-
final inputLibrary = await buildStep.inputLibrary2;
122+
final inputLibrary = await buildStep.inputLibrary;
123123
final outputId = buildStep.allowedOutputs.single;
124124
final partOfUri = uriOfPartial(inputLibrary, buildStep.inputId, outputId);
125125

source_gen/lib/source_gen.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export 'src/generator.dart'
1111
export 'src/generator_for_annotation.dart' show GeneratorForAnnotation;
1212
export 'src/library.dart'
1313
show AnnotatedDirective, AnnotatedElement, LibraryReader;
14-
export 'src/span_for_element.dart' show spanForElement, spanForElement2;
14+
export 'src/span_for_element.dart' show spanForElement;
1515
export 'src/type_checker.dart' show TypeChecker, UnresolvedAnnotationException;
1616
export 'src/utils.dart' show typeNameOf;

source_gen/lib/src/builder.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class _Builder extends Builder {
103103
}
104104

105105
final lib = await buildStep.resolver
106-
.libraryFor2(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors);
106+
.libraryFor(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors);
107107
await _generateForLibrary(lib, buildStep);
108108
}
109109

@@ -431,10 +431,6 @@ String languageOverrideForLibrary(LibraryElement2 library) {
431431
: '// @dart=${override.major}.${override.minor}\n';
432432
}
433433

434-
@Deprecated('Use languageOverrideForLibrary instead')
435-
String languageOverrideForLibrary2(LibraryElement2 library) =>
436-
languageOverrideForLibrary(library);
437-
438434
/// A comment configuring `dart_style` to use the default code width so no
439435
/// configuration discovery is required.
440436
const dartFormatWidth = '// dart format width=80';

source_gen/lib/src/constants/utils.dart

-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ void assertHasField(InterfaceElement2 root, String name) {
2828
);
2929
}
3030

31-
/// Throws a [FormatException] if [root] does not have a given field [name].
32-
///
33-
/// Super types [InterfaceElement2.supertype] are also checked before throwing.
34-
@Deprecated('Use assertHasField() instead')
35-
void assertHasField2(InterfaceElement2 root, String name) =>
36-
assertHasField(root, name);
37-
3831
/// Returns whether or not [object] is or represents a `null` value.
3932
bool isNullLike(DartObject? object) => object?.isNull != false;
4033

source_gen/lib/src/generator.dart

-11
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@ class InvalidGenerationSource implements Exception {
6464
this.node,
6565
});
6666

67-
@Deprecated('use the unnamed constructor instead')
68-
InvalidGenerationSource.v2(
69-
this.message, {
70-
this.todo = '',
71-
this.element,
72-
this.node,
73-
});
74-
75-
@Deprecated('use element instead')
76-
Element2? get element2 => element;
77-
7867
@override
7968
String toString() {
8069
final buffer = StringBuffer(message);

source_gen/lib/src/generator_for_annotation.dart

+1-30
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ abstract class GeneratorForAnnotation<T> extends Generator {
7373
typeChecker,
7474
throwOnUnresolved: throwOnUnresolved,
7575
)) {
76-
var generatedValue = generateForAnnotatedElement(
77-
annotatedElement.element,
78-
annotatedElement.annotation,
79-
buildStep,
80-
);
81-
generatedValue ??= generateForAnnotatedElement2(
76+
final generatedValue = generateForAnnotatedElement(
8277
annotatedElement.element,
8378
annotatedElement.annotation,
8479
buildStep,
@@ -115,30 +110,6 @@ abstract class GeneratorForAnnotation<T> extends Generator {
115110
BuildStep buildStep,
116111
) {}
117112

118-
/// Implement to return source code to generate for [element].
119-
///
120-
/// This method is invoked based on finding elements annotated with an
121-
/// instance of [T]. The [annotation] is provided as a [ConstantReader].
122-
///
123-
/// Supported return values include a single [String] or multiple [String]
124-
/// instances within an [Iterable] or [Stream]. It is also valid to return a
125-
/// [Future] of [String], [Iterable], or [Stream]. When multiple values are
126-
/// returned through an iterable or stream they will be deduplicated.
127-
/// Typically each value will be an independent unit of code and the
128-
/// deduplication prevents re-defining the same member multiple times. For
129-
/// example if multiple annotated elements may need a specific utility method
130-
/// available it can be output for each one, and the single deduplicated
131-
/// definition can be shared.
132-
///
133-
/// Implementations should return `null` when no content is generated. Empty
134-
/// or whitespace-only [String] instances are also ignored.
135-
@Deprecated('use generateForAnnotatedElement instead')
136-
dynamic generateForAnnotatedElement2(
137-
Element2 element,
138-
ConstantReader annotation,
139-
BuildStep buildStep,
140-
) {}
141-
142113
/// Implement to return source code to generate for [directive]:
143114
/// - [LibraryImport]
144115
/// - [LibraryExport]

source_gen/lib/src/library.dart

-35
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class AnnotatedElement {
2727

2828
const AnnotatedElement(this.annotation, this.element);
2929

30-
@Deprecated('use element instead')
31-
Element2 get element2 => element;
32-
3330
Metadata? get metadata2 {
3431
if (element case final Annotatable annotatable) {
3532
return annotatable.metadata2;
@@ -44,33 +41,15 @@ class LibraryReader {
4441

4542
LibraryReader(this.element);
4643

47-
@Deprecated('use the default constructor instead')
48-
LibraryReader.v2(this.element);
49-
50-
@Deprecated('use element instead')
51-
LibraryElement2 get element2 => element;
52-
5344
/// All of the declarations in this library.
5445
Iterable<Element2> get allElements => [element, ...element.children2];
5546

56-
/// All of the declarations in this library.
57-
@Deprecated('use allElements instead')
58-
Iterable<Element2> get allElements2 => allElements;
59-
6047
/// All of the elements representing classes in this library.
6148
Iterable<ClassElement2> get classes => element.classes;
6249

63-
/// All of the elements representing classes in this library.
64-
@Deprecated('use classes instead')
65-
Iterable<ClassElement2> get classes2 => classes;
66-
6750
/// All of the elements representing enums in this library.
6851
Iterable<EnumElement2> get enums => element.enums;
6952

70-
/// All of the elements representing enums in this library.
71-
@Deprecated('use enums instead')
72-
Iterable<EnumElement2> get enums3 => enums;
73-
7453
/// All of the declarations in this library annotated with [checker].
7554
Iterable<AnnotatedElement> annotatedWith(
7655
TypeChecker checker, {
@@ -137,13 +116,6 @@ class LibraryReader {
137116
return type is ClassElement2 ? type : null;
138117
}
139118

140-
/// Returns a top-level [ClassElement2] publicly visible in by [name].
141-
///
142-
/// Unlike `LibraryElement2.getClass`, this also correctly traverses
143-
/// identifiers that are accessible via one or more `export` directives.
144-
@Deprecated('Use findType() instead')
145-
ClassElement2? findType2(String name) => findType(name);
146-
147119
/// Returns a [Uri] from the current library to the target [asset].
148120
///
149121
/// This is a typed convenience function for using [pathToUrl], and the same
@@ -157,13 +129,6 @@ class LibraryReader {
157129
Uri pathToElement(Element2 element) =>
158130
pathToUrl(element.firstFragment.libraryFragment!.source.uri);
159131

160-
/// Returns a [Uri] from the current library to the target [element].
161-
///
162-
/// This is a typed convenience function for using [pathToUrl], and the same
163-
/// API restrictions hold around supported schemes and relative paths.
164-
@Deprecated('use pathToElement instead')
165-
Uri pathToElement2(Element2 element) => pathToElement(element);
166-
167132
/// Returns a [Uri] from the current library to the one provided.
168133
///
169134
/// If possible, a `package:` or `dart:` URL scheme will be used to reference

source_gen/lib/src/span_for_element.dart

-15
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ SourceSpan spanForElement(Element2 element, [SourceFile? file]) {
5454
);
5555
}
5656

57-
/// Returns a source span that spans the location where [element] is defined.
58-
///
59-
/// May be used to emit user-friendly warning and error messages:
60-
/// ```dart
61-
/// void invalidClass(ClassElement class) {
62-
/// log.warning(spanForElement.message('Cannot implement "Secret"'));
63-
/// }
64-
/// ```
65-
///
66-
/// Not all results from the analyzer API may return source information as part
67-
/// of the element, so [file] may need to be manually provided in those cases.
68-
@Deprecated('use spanForElement instead')
69-
SourceSpan spanForElement2(Element2 element, [SourceFile? file]) =>
70-
spanForElement(element, file);
71-
7257
/// Returns a source span that spans the location where [node] is written.
7358
SourceSpan spanForNode(AstNode node) {
7459
final unit = node.thisOrAncestorOfType<CompilationUnit>()!;

0 commit comments

Comments
 (0)