diff --git a/example/lib/src/multiplier_generator.dart b/example/lib/src/multiplier_generator.dart index 60b34ca6..d061e59f 100644 --- a/example/lib/src/multiplier_generator.dart +++ b/example/lib/src/multiplier_generator.dart @@ -10,7 +10,7 @@ import '../annotations.dart'; class MultiplierGenerator extends GeneratorForAnnotation { @override - String generateForAnnotatedElement2( + String generateForAnnotatedElement( Element2 element, ConstantReader annotation, BuildStep buildStep, diff --git a/source_gen/lib/builder.dart b/source_gen/lib/builder.dart index f0195ecb..9daadb0a 100644 --- a/source_gen/lib/builder.dart +++ b/source_gen/lib/builder.dart @@ -119,7 +119,7 @@ class CombiningBuilder implements Builder { .join('\n\n'); if (assets.isEmpty) return; - final inputLibrary = await buildStep.inputLibrary2; + final inputLibrary = await buildStep.inputLibrary; final outputId = buildStep.allowedOutputs.single; final partOfUri = uriOfPartial(inputLibrary, buildStep.inputId, outputId); diff --git a/source_gen/lib/source_gen.dart b/source_gen/lib/source_gen.dart index 57010a22..e17ca4bf 100644 --- a/source_gen/lib/source_gen.dart +++ b/source_gen/lib/source_gen.dart @@ -11,6 +11,6 @@ export 'src/generator.dart' export 'src/generator_for_annotation.dart' show GeneratorForAnnotation; export 'src/library.dart' show AnnotatedDirective, AnnotatedElement, LibraryReader; -export 'src/span_for_element.dart' show spanForElement, spanForElement2; +export 'src/span_for_element.dart' show spanForElement; export 'src/type_checker.dart' show TypeChecker, UnresolvedAnnotationException; export 'src/utils.dart' show typeNameOf; diff --git a/source_gen/lib/src/builder.dart b/source_gen/lib/src/builder.dart index 9e6acb1a..10fa5d6a 100644 --- a/source_gen/lib/src/builder.dart +++ b/source_gen/lib/src/builder.dart @@ -103,7 +103,7 @@ class _Builder extends Builder { } final lib = await buildStep.resolver - .libraryFor2(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors); + .libraryFor(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors); await _generateForLibrary(lib, buildStep); } @@ -431,10 +431,6 @@ String languageOverrideForLibrary(LibraryElement2 library) { : '// @dart=${override.major}.${override.minor}\n'; } -@Deprecated('Use languageOverrideForLibrary instead') -String languageOverrideForLibrary2(LibraryElement2 library) => - languageOverrideForLibrary(library); - /// A comment configuring `dart_style` to use the default code width so no /// configuration discovery is required. const dartFormatWidth = '// dart format width=80'; diff --git a/source_gen/lib/src/constants/utils.dart b/source_gen/lib/src/constants/utils.dart index c36cad0f..a557f1fb 100644 --- a/source_gen/lib/src/constants/utils.dart +++ b/source_gen/lib/src/constants/utils.dart @@ -28,13 +28,6 @@ void assertHasField(InterfaceElement2 root, String name) { ); } -/// Throws a [FormatException] if [root] does not have a given field [name]. -/// -/// Super types [InterfaceElement2.supertype] are also checked before throwing. -@Deprecated('Use assertHasField() instead') -void assertHasField2(InterfaceElement2 root, String name) => - assertHasField(root, name); - /// Returns whether or not [object] is or represents a `null` value. bool isNullLike(DartObject? object) => object?.isNull != false; diff --git a/source_gen/lib/src/generator.dart b/source_gen/lib/src/generator.dart index 6a6a41e9..4159dcd5 100644 --- a/source_gen/lib/src/generator.dart +++ b/source_gen/lib/src/generator.dart @@ -64,17 +64,6 @@ class InvalidGenerationSource implements Exception { this.node, }); - @Deprecated('use the unnamed constructor instead') - InvalidGenerationSource.v2( - this.message, { - this.todo = '', - this.element, - this.node, - }); - - @Deprecated('use element instead') - Element2? get element2 => element; - @override String toString() { final buffer = StringBuffer(message); diff --git a/source_gen/lib/src/generator_for_annotation.dart b/source_gen/lib/src/generator_for_annotation.dart index ff5b17c8..7b41f133 100644 --- a/source_gen/lib/src/generator_for_annotation.dart +++ b/source_gen/lib/src/generator_for_annotation.dart @@ -73,12 +73,7 @@ abstract class GeneratorForAnnotation extends Generator { typeChecker, throwOnUnresolved: throwOnUnresolved, )) { - var generatedValue = generateForAnnotatedElement( - annotatedElement.element, - annotatedElement.annotation, - buildStep, - ); - generatedValue ??= generateForAnnotatedElement2( + final generatedValue = generateForAnnotatedElement( annotatedElement.element, annotatedElement.annotation, buildStep, @@ -115,30 +110,6 @@ abstract class GeneratorForAnnotation extends Generator { BuildStep buildStep, ) {} - /// Implement to return source code to generate for [element]. - /// - /// This method is invoked based on finding elements annotated with an - /// instance of [T]. The [annotation] is provided as a [ConstantReader]. - /// - /// Supported return values include a single [String] or multiple [String] - /// instances within an [Iterable] or [Stream]. It is also valid to return a - /// [Future] of [String], [Iterable], or [Stream]. When multiple values are - /// returned through an iterable or stream they will be deduplicated. - /// Typically each value will be an independent unit of code and the - /// deduplication prevents re-defining the same member multiple times. For - /// example if multiple annotated elements may need a specific utility method - /// available it can be output for each one, and the single deduplicated - /// definition can be shared. - /// - /// Implementations should return `null` when no content is generated. Empty - /// or whitespace-only [String] instances are also ignored. - @Deprecated('use generateForAnnotatedElement instead') - dynamic generateForAnnotatedElement2( - Element2 element, - ConstantReader annotation, - BuildStep buildStep, - ) {} - /// Implement to return source code to generate for [directive]: /// - [LibraryImport] /// - [LibraryExport] diff --git a/source_gen/lib/src/library.dart b/source_gen/lib/src/library.dart index 52679eb4..698cf56f 100644 --- a/source_gen/lib/src/library.dart +++ b/source_gen/lib/src/library.dart @@ -27,9 +27,6 @@ class AnnotatedElement { const AnnotatedElement(this.annotation, this.element); - @Deprecated('use element instead') - Element2 get element2 => element; - Metadata? get metadata2 { if (element case final Annotatable annotatable) { return annotatable.metadata2; @@ -44,33 +41,15 @@ class LibraryReader { LibraryReader(this.element); - @Deprecated('use the default constructor instead') - LibraryReader.v2(this.element); - - @Deprecated('use element instead') - LibraryElement2 get element2 => element; - /// All of the declarations in this library. Iterable get allElements => [element, ...element.children2]; - /// All of the declarations in this library. - @Deprecated('use allElements instead') - Iterable get allElements2 => allElements; - /// All of the elements representing classes in this library. Iterable get classes => element.classes; - /// All of the elements representing classes in this library. - @Deprecated('use classes instead') - Iterable get classes2 => classes; - /// All of the elements representing enums in this library. Iterable get enums => element.enums; - /// All of the elements representing enums in this library. - @Deprecated('use enums instead') - Iterable get enums3 => enums; - /// All of the declarations in this library annotated with [checker]. Iterable annotatedWith( TypeChecker checker, { @@ -137,13 +116,6 @@ class LibraryReader { return type is ClassElement2 ? type : null; } - /// Returns a top-level [ClassElement2] publicly visible in by [name]. - /// - /// Unlike `LibraryElement2.getClass`, this also correctly traverses - /// identifiers that are accessible via one or more `export` directives. - @Deprecated('Use findType() instead') - ClassElement2? findType2(String name) => findType(name); - /// Returns a [Uri] from the current library to the target [asset]. /// /// This is a typed convenience function for using [pathToUrl], and the same @@ -157,13 +129,6 @@ class LibraryReader { Uri pathToElement(Element2 element) => pathToUrl(element.firstFragment.libraryFragment!.source.uri); - /// Returns a [Uri] from the current library to the target [element]. - /// - /// This is a typed convenience function for using [pathToUrl], and the same - /// API restrictions hold around supported schemes and relative paths. - @Deprecated('use pathToElement instead') - Uri pathToElement2(Element2 element) => pathToElement(element); - /// Returns a [Uri] from the current library to the one provided. /// /// If possible, a `package:` or `dart:` URL scheme will be used to reference diff --git a/source_gen/lib/src/span_for_element.dart b/source_gen/lib/src/span_for_element.dart index 386a63f8..a0dd38ef 100644 --- a/source_gen/lib/src/span_for_element.dart +++ b/source_gen/lib/src/span_for_element.dart @@ -54,21 +54,6 @@ SourceSpan spanForElement(Element2 element, [SourceFile? file]) { ); } -/// Returns a source span that spans the location where [element] is defined. -/// -/// May be used to emit user-friendly warning and error messages: -/// ```dart -/// void invalidClass(ClassElement class) { -/// log.warning(spanForElement.message('Cannot implement "Secret"')); -/// } -/// ``` -/// -/// Not all results from the analyzer API may return source information as part -/// of the element, so [file] may need to be manually provided in those cases. -@Deprecated('use spanForElement instead') -SourceSpan spanForElement2(Element2 element, [SourceFile? file]) => - spanForElement(element, file); - /// Returns a source span that spans the location where [node] is written. SourceSpan spanForNode(AstNode node) { final unit = node.thisOrAncestorOfType()!; diff --git a/source_gen/lib/src/type_checker.dart b/source_gen/lib/src/type_checker.dart index ac73ad8a..77a86e86 100644 --- a/source_gen/lib/src/type_checker.dart +++ b/source_gen/lib/src/type_checker.dart @@ -78,31 +78,12 @@ abstract class TypeChecker { return results.isEmpty ? null : results.first; } - /// Returns the first constant annotating [element] assignable to this type. - /// - /// Otherwise returns `null`. - /// - /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. - @Deprecated('use firstAnnotationOf instead') - DartObject? firstAnnotationOf2( - Object element, { - bool throwOnUnresolved = true, - }) => - firstAnnotationOf(element, throwOnUnresolved: throwOnUnresolved); - /// Returns if a constant annotating [element] is assignable to this type. /// /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. bool hasAnnotationOf(Element2 element, {bool throwOnUnresolved = true}) => firstAnnotationOf(element, throwOnUnresolved: throwOnUnresolved) != null; - /// Returns if a constant annotating [element] is assignable to this type. - /// - /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. - @Deprecated('use hasAnnotationOf instead') - bool hasAnnotationOf2(Element2 element, {bool throwOnUnresolved = true}) => - hasAnnotationOf(element, throwOnUnresolved: throwOnUnresolved); - /// Returns the first constant annotating [element] that is exactly this type. /// /// Throws [UnresolvedAnnotationException] on unresolved annotations unless @@ -125,17 +106,6 @@ abstract class TypeChecker { return null; } - /// Returns the first constant annotating [element] that is exactly this type. - /// - /// Throws [UnresolvedAnnotationException] on unresolved annotations unless - /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use firstAnnotationOfExact instead') - DartObject? firstAnnotationOfExact2( - Element2 element, { - bool throwOnUnresolved = true, - }) => - firstAnnotationOfExact(element, throwOnUnresolved: throwOnUnresolved); - /// Returns if a constant annotating [element] is exactly this type. /// /// Throws [UnresolvedAnnotationException] on unresolved annotations unless @@ -147,17 +117,6 @@ abstract class TypeChecker { firstAnnotationOfExact(element, throwOnUnresolved: throwOnUnresolved) != null; - /// Returns if a constant annotating [element] is exactly this type. - /// - /// Throws [UnresolvedAnnotationException] on unresolved annotations unless - /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use hasAnnotationOfExact instead') - bool hasAnnotationOfExact2( - Element2 element, { - bool throwOnUnresolved = true, - }) => - hasAnnotationOfExact(element, throwOnUnresolved: throwOnUnresolved); - DartObject? _computeConstantValue( Object element, ElementAnnotation annotation, @@ -185,17 +144,6 @@ abstract class TypeChecker { throwOnUnresolved: throwOnUnresolved, ); - /// Returns annotating constants on [element] assignable to this type. - /// - /// Throws [UnresolvedAnnotationException] on unresolved annotations unless - /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use annotationsOf instead') - Iterable annotationsOf2( - Object element, { - bool throwOnUnresolved = true, - }) => - annotationsOf(element, throwOnUnresolved: throwOnUnresolved); - Iterable _annotationsWhere( Object element, bool Function(DartType) predicate, { @@ -231,27 +179,12 @@ abstract class TypeChecker { throwOnUnresolved: throwOnUnresolved, ); - /// Returns annotating constants on [element] of exactly this type. - /// - /// Throws [UnresolvedAnnotationException] on unresolved annotations unless - /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use annotationsOfExact instead') - Iterable annotationsOfExact2( - Element2 element, { - bool throwOnUnresolved = true, - }) => - annotationsOfExact(element, throwOnUnresolved: throwOnUnresolved); - /// Returns `true` if the type of [element] can be assigned to this type. bool isAssignableFrom(Element2 element) => isExactly(element) || (element is InterfaceElement2 && element.allSupertypes.any(isExactlyType)); - /// Returns `true` if the type of [element] can be assigned to this type. - @Deprecated('use isAssignableFrom instead') - bool isAssignableFrom2(Element2 element) => isAssignableFrom(element); - /// Returns `true` if [staticType] can be assigned to this type. bool isAssignableFromType(DartType staticType) { final element = staticType.element3; @@ -261,10 +194,6 @@ abstract class TypeChecker { /// Returns `true` if representing the exact same class as [element]. bool isExactly(Element2 element); - /// Returns `true` if representing the exact same class as [element]. - @Deprecated('use isExactly instead') - bool isExactly2(Element2 element) => isExactly(element); - /// Returns `true` if representing the exact same type as [staticType]. /// /// This will always return false for types without a backingclass such as @@ -298,13 +227,6 @@ abstract class TypeChecker { return false; } - /// Returns `true` if representing a super class of [element]. - /// - /// This check only takes into account the *extends* hierarchy. If you wish - /// to check mixins and interfaces, use [isAssignableFrom]. - @Deprecated('use isSuperOf instead') - bool isSuperOf2(Element2 element) => isSuperOf(element); - /// Returns `true` if representing a super type of [staticType]. /// /// This only takes into account the *extends* hierarchy. If you wish @@ -322,10 +244,6 @@ class _LibraryTypeChecker extends TypeChecker { bool isExactly(Element2 element) => element is InterfaceElement2 && element == _type.element3; - @Deprecated('Use isExactly() instead') - @override - bool isExactly2(Element2 element) => isExactly(element); - @override String toString() => urlOfElement(_type.element3!); } @@ -349,10 +267,6 @@ class _MirrorTypeChecker extends TypeChecker { @override bool isExactly(Element2 element) => _computed.isExactly(element); - @Deprecated('use isExactly instead') - @override - bool isExactly2(Element2 element) => isExactly(element); - @override String toString() => _computed.toString(); } @@ -385,10 +299,6 @@ class _UriTypeChecker extends TypeChecker { @override bool isExactly(Element2 element) => hasSameUrl(urlOfElement(element)); - @Deprecated('use isExactly instead') - @override - bool isExactly2(Element2 element) => isExactly(element); - @override String toString() => '$uri'; } @@ -401,10 +311,6 @@ class _AnyChecker extends TypeChecker { @override bool isExactly(Element2 element) => _checkers.any((c) => c.isExactly(element)); - - @Deprecated('use isExactly2 instead') - @override - bool isExactly2(Element2 element) => isExactly(element); } /// Exception thrown when [TypeChecker] fails to resolve a metadata annotation. @@ -422,9 +328,6 @@ class UnresolvedAnnotationException implements Exception { /// May be `null` if the import library was not found. final SourceSpan? annotationSource; - @Deprecated('use annotatedElement instead') - Element2 get annotatedElement2 => annotatedElement; - static SourceSpan? _findSpan(Element2 annotatedElement, int annotationIndex) { try { final parsedLibrary = diff --git a/source_gen/lib/src/utils.dart b/source_gen/lib/src/utils.dart index cf5714f7..13cc584e 100644 --- a/source_gen/lib/src/utils.dart +++ b/source_gen/lib/src/utils.dart @@ -49,13 +49,6 @@ String uriOfPartial(LibraryElement2 element, AssetId source, AssetId output) { return p.url.relative(source.path, from: p.url.dirname(output.path)); } -/// Returns a uri suitable for `part of "..."` when pointing to [element]. -@Deprecated('use uriOfPartial instead') -String uriOfPartial2(LibraryElement2 element, AssetId source, AssetId output) { - assert(source.package == output.package); - return p.url.relative(source.path, from: p.url.dirname(output.path)); -} - /// Returns what 'part "..."' URL is needed to import [output] from [input]. /// /// For example, will return `test_lib.g.dart` for `test_lib.dart`. @@ -71,15 +64,6 @@ String urlOfElement(Element2 element) => element.kind == ElementKind.DYNAMIC .replace(fragment: element.name3) .toString(); -/// Returns a URL representing [element]. -@Deprecated('use urlOfElement instead') -String urlOfElement2(Element2 element) => element.kind == ElementKind.DYNAMIC - ? 'dart:core#dynamic' - // using librarySource.uri – in case the element is in a part - : normalizeUrl(element.library2!.uri) - .replace(fragment: element.name3) - .toString(); - Uri normalizeUrl(Uri url) => switch (url.scheme) { 'dart' => normalizeDartUrl(url), 'package' => _packageToAssetUrl(url), diff --git a/source_gen/test/constants/utils_test.dart b/source_gen/test/constants/utils_test.dart index f36bdb0b..e6ff3cdb 100644 --- a/source_gen/test/constants/utils_test.dart +++ b/source_gen/test/constants/utils_test.dart @@ -29,7 +29,7 @@ void main() { String c; } ''', - (resolver) async => (await resolver.findLibraryByName2('test_lib'))!, + (resolver) async => (await resolver.findLibraryByName('test_lib'))!, ); }); @@ -83,7 +83,7 @@ void main() { const C(this.c); } ''', - (resolver) async => (await resolver.findLibraryByName2('test_lib'))!, + (resolver) async => (await resolver.findLibraryByName('test_lib'))!, ); objects = testLib .getClass2('Example')! diff --git a/source_gen/test/constants_test.dart b/source_gen/test/constants_test.dart index 35ef8560..f1ffe4be 100644 --- a/source_gen/test/constants_test.dart +++ b/source_gen/test/constants_test.dart @@ -58,7 +58,7 @@ void main() { const Super() : super(aString: 'Super Hello'); } ''', - (resolver) async => (await resolver.findLibraryByName2('test_lib'))!, + (resolver) async => (await resolver.findLibraryByName('test_lib'))!, ); constants = library .getClass2('Example')! @@ -298,7 +298,7 @@ void main() { void _privateFunction() {} ''', - (resolver) async => (await resolver.findLibraryByName2('test_lib'))!, + (resolver) async => (await resolver.findLibraryByName('test_lib'))!, ); constants = library .getClass2('Example')! diff --git a/source_gen/test/external_only_type_checker_test.dart b/source_gen/test/external_only_type_checker_test.dart index 6ef5bde7..8ee567cc 100644 --- a/source_gen/test/external_only_type_checker_test.dart +++ b/source_gen/test/external_only_type_checker_test.dart @@ -29,7 +29,7 @@ void main() { ''', (resolver) async { thisTest = LibraryReader( - await resolver.libraryFor2( + await resolver.libraryFor( AssetId('source_gen', 'test/external_only_type_checker_test.dart'), ), ); diff --git a/source_gen/test/library/find_type_test.dart b/source_gen/test/library/find_type_test.dart index 83d9b88f..0bc1201d 100644 --- a/source_gen/test/library/find_type_test.dart +++ b/source_gen/test/library/find_type_test.dart @@ -34,7 +34,7 @@ void main() { setUpAll(() async { library = await resolveSources( {'a|source.dart': _source, 'a|part.dart': _partSource}, - (r) async => LibraryReader((await r.findLibraryByName2('test_lib'))!), + (r) async => LibraryReader((await r.findLibraryByName('test_lib'))!), ); }); diff --git a/source_gen/test/span_for_element_test.dart b/source_gen/test/span_for_element_test.dart index b088829d..a36dd256 100644 --- a/source_gen/test/span_for_element_test.dart +++ b/source_gen/test/span_for_element_test.dart @@ -31,7 +31,7 @@ abstract class Example implements List { ''', (r) async { resolver = r; - return (await resolver.findLibraryByName2('test_lib'))!; + return (await resolver.findLibraryByName('test_lib'))!; }, inputId: AssetId('test_lib', 'lib/test_lib.dart'), ); @@ -104,7 +104,7 @@ line 7, column 11 of package:test_lib/test_lib.dart: Here it is test('highlights based on AstNode source location', () async { final element = library.getClass2('Example')!.getField2('field')!.firstFragment; - final node = (await resolver.astNodeFor2(element, resolve: true))!; + final node = (await resolver.astNodeFor(element, resolve: true))!; expect( spanForNode(node).message('Here it is'), r""" diff --git a/source_gen/test/src/comment_generator.dart b/source_gen/test/src/comment_generator.dart index 987b969e..9b69d254 100644 --- a/source_gen/test/src/comment_generator.dart +++ b/source_gen/test/src/comment_generator.dart @@ -24,7 +24,7 @@ class CommentGenerator extends Generator { if (forClasses) { for (var classElement in library.allElements.whereType()) { if (classElement.displayName.contains('GoodError')) { - throw InvalidGenerationSourceError.v2( + throw InvalidGenerationSourceError( "Don't use classes with the word 'Error' in the name", todo: 'Rename ${classElement.displayName} to something else.', element: classElement, diff --git a/source_gen/test/type_checker_test.dart b/source_gen/test/type_checker_test.dart index 06f1a176..7d08823e 100644 --- a/source_gen/test/type_checker_test.dart +++ b/source_gen/test/type_checker_test.dart @@ -55,15 +55,15 @@ void main() { export 'type_checker_test.dart' show NonPublic; ''', (resolver) async { - core = (await resolver.findLibraryByName2('dart.core'))!; - collection = (await resolver.findLibraryByName2('dart.collection'))!; + core = (await resolver.findLibraryByName('dart.core'))!; + collection = (await resolver.findLibraryByName('dart.collection'))!; sourceGen = LibraryReader( - await resolver.libraryFor2( + await resolver.libraryFor( AssetId('source_gen', 'lib/source_gen.dart'), ), ); testSource = await resolver - .libraryFor2(AssetId('source_gen', 'test/type_checker_test.dart')); + .libraryFor(AssetId('source_gen', 'test/type_checker_test.dart')); }, inputId: AssetId('source_gen', 'test/example.dart'), ); @@ -365,7 +365,7 @@ void main() { @depracated // Intentionally mispelled. class X {} ''', - (resolver) async => (await resolver.findLibraryByName2('_test'))!, + (resolver) async => (await resolver.findLibraryByName('_test'))!, ); final classX = library.getClass2('X')!; const $deprecated = TypeChecker.fromRuntime(Deprecated); @@ -435,7 +435,7 @@ void main() { const C(); } ''', - (resolver) async => (await resolver.findLibraryByName2('_test'))!, + (resolver) async => (await resolver.findLibraryByName('_test'))!, ); $A = TypeChecker.fromStatic( @@ -517,7 +517,7 @@ void main() { const A(); } ''', - (resolver) async => (await resolver.findLibraryByName2('_test'))!, + (resolver) async => (await resolver.findLibraryByName('_test'))!, ); $A = TypeChecker.fromStatic( library.getClass2('A')!.instantiate( diff --git a/source_gen/test/utils_test.dart b/source_gen/test/utils_test.dart index 328585c2..1cef0189 100644 --- a/source_gen/test/utils_test.dart +++ b/source_gen/test/utils_test.dart @@ -29,7 +29,7 @@ void main() { example = await resolveSource( source, (resolver) => resolver - .findLibraryByName2('example') + .findLibraryByName('example') .then((e) => e!.getClass2('Example')!), ); });