diff --git a/example/lib/src/member_count_library_generator.dart b/example/lib/src/member_count_library_generator.dart index a2a1dd89..b5e7afaf 100644 --- a/example/lib/src/member_count_library_generator.dart +++ b/example/lib/src/member_count_library_generator.dart @@ -13,7 +13,7 @@ class MemberCountLibraryGenerator extends Generator { final topLevelVarCount = topLevelNumVariables(library).length; return ''' -// Source library: ${library.element2.uri} +// Source library: ${library.element.uri} const topLevelNumVarCount = $topLevelVarCount; '''; } diff --git a/example/lib/src/utils.dart b/example/lib/src/utils.dart index 41f5d2b6..257c4786 100644 --- a/example/lib/src/utils.dart +++ b/example/lib/src/utils.dart @@ -8,7 +8,7 @@ import 'package:source_gen/source_gen.dart'; /// Returns all [TopLevelVariableElement2] members in [reader]'s library that /// have a type of [num]. Iterable topLevelNumVariables(LibraryReader reader) => - reader.allElements2.whereType().where( + reader.allElements.whereType().where( (element) => element.type.isDartCoreNum || element.type.isDartCoreInt || diff --git a/source_gen/lib/builder.dart b/source_gen/lib/builder.dart index e9deb1ca..f0195ecb 100644 --- a/source_gen/lib/builder.dart +++ b/source_gen/lib/builder.dart @@ -121,7 +121,7 @@ class CombiningBuilder implements Builder { final inputLibrary = await buildStep.inputLibrary2; final outputId = buildStep.allowedOutputs.single; - final partOfUri = uriOfPartial2(inputLibrary, buildStep.inputId, outputId); + final partOfUri = uriOfPartial(inputLibrary, buildStep.inputId, outputId); // Ensure that the input has a correct `part` statement. final libraryUnit = @@ -143,7 +143,7 @@ class CombiningBuilder implements Builder { final output = ''' $defaultFileHeader -${languageOverrideForLibrary2(inputLibrary)}$ignoreForFile$preamble +${languageOverrideForLibrary(inputLibrary)}$ignoreForFile$preamble part of '$partOfUri'; $assets diff --git a/source_gen/lib/src/builder.dart b/source_gen/lib/src/builder.dart index 6483472b..9e6acb1a 100644 --- a/source_gen/lib/src/builder.dart +++ b/source_gen/lib/src/builder.dart @@ -5,7 +5,6 @@ import 'dart:convert'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; import 'package:dart_style/dart_style.dart'; @@ -130,12 +129,12 @@ class _Builder extends Builder { if (!_isLibraryBuilder) { final asset = buildStep.inputId; - final partOfUri = uriOfPartial2(library2, asset, outputId); + final partOfUri = uriOfPartial(library2, asset, outputId); contentBuffer.writeln(); if (this is PartBuilder) { contentBuffer - ..write(languageOverrideForLibrary2(library2)) + ..write(languageOverrideForLibrary(library2)) ..writeln('part of \'$partOfUri\';'); final part = computePartUrl(buildStep.inputId, outputId); @@ -358,7 +357,7 @@ Stream _generate( List generators, BuildStep buildStep, ) async* { - final libraryReader = LibraryReader.v2(library2); + final libraryReader = LibraryReader(library2); for (var i = 0; i < generators.length; i++) { final gen = generators[i]; var msg = 'Running $gen'; @@ -425,20 +424,16 @@ const partIdRegExpLiteral = r'[A-Za-z_\d-]+'; final _partIdRegExp = RegExp('^$partIdRegExpLiteral\$'); -@Deprecated('Use languageOverrideForLibrary2 instead') -String languageOverrideForLibrary(LibraryElement library) { +String languageOverrideForLibrary(LibraryElement2 library) { final override = library.languageVersion.override; return override == null ? '' : '// @dart=${override.major}.${override.minor}\n'; } -String languageOverrideForLibrary2(LibraryElement2 library) { - final override = library.languageVersion.override; - return override == null - ? '' - : '// @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. diff --git a/source_gen/lib/src/constants/reader.dart b/source_gen/lib/src/constants/reader.dart index dba2d052..6e6501c4 100644 --- a/source_gen/lib/src/constants/reader.dart +++ b/source_gen/lib/src/constants/reader.dart @@ -268,7 +268,7 @@ class _DartObjectConstant extends ConstantReader { ConstantReader read(String field) { final reader = peek(field); if (reader == null) { - assertHasField2(objectValue.type!.element3 as InterfaceElement2, field); + assertHasField(objectValue.type!.element3 as InterfaceElement2, field); return const _NullConstant(); } return reader; diff --git a/source_gen/lib/src/constants/revive.dart b/source_gen/lib/src/constants/revive.dart index ec8b770e..464650b3 100644 --- a/source_gen/lib/src/constants/revive.dart +++ b/source_gen/lib/src/constants/revive.dart @@ -33,7 +33,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) { } } origin ??= element!.library2; - var url = Uri.parse(urlOfElement2(element!)); + var url = Uri.parse(urlOfElement(element!)); if (element is TopLevelFunctionElement || element is LocalFunctionElement) { return Revivable._(source: url.removeFragment(), accessor: element.name3!); } @@ -67,8 +67,9 @@ Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) { } for (final type in origin!.classes) { - for (final e in type.fields2 - .where((f) => f.isConst && f.computeConstantValue() == object)) { + for (final e in type.fields2.where( + (f) => f.isConst && f.computeConstantValue() == object, + )) { final result = Revivable._( source: url.removeFragment(), accessor: '${type.name3}.${e.name3}', @@ -80,7 +81,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) { } final i = (object as DartObjectImpl).getInvocation(); if (i != null) { - url = Uri.parse(urlOfElement2(i.constructor2.enclosingElement2)); + url = Uri.parse(urlOfElement(i.constructor2.enclosingElement2)); final result = Revivable._( source: url, accessor: i.constructor.name, @@ -95,7 +96,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement2? origin]) { (f) => f.isConst && f.computeConstantValue() == object, )) { final result = Revivable._( - source: Uri.parse(urlOfElement2(origin)).replace(fragment: ''), + source: Uri.parse(urlOfElement(origin)).replace(fragment: ''), accessor: e.name3!, ); if (tryResult(result)) { diff --git a/source_gen/lib/src/constants/utils.dart b/source_gen/lib/src/constants/utils.dart index 56a45e60..c36cad0f 100644 --- a/source_gen/lib/src/constants/utils.dart +++ b/source_gen/lib/src/constants/utils.dart @@ -3,37 +3,12 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; -/// Throws a [FormatException] if [root] does not have a given field [name]. -/// -/// Super types [InterfaceElement.supertype] are also checked before throwing. -@Deprecated('Use assertHasField2() instead') -void assertHasField(InterfaceElement root, String name) { - InterfaceElement? element = root; - while (element != null) { - final field = element.getField(name); - if (field != null) { - return; - } - element = element.supertype?.element; - } - final allFields = { - ...root.fields, - for (var t in root.allSupertypes) ...t.element.fields, - }; - - throw FormatException( - 'Class ${root.name} does not have field "$name".', - 'Fields: \n - ${allFields.map((e) => e.name).join('\n - ')}', - ); -} - /// Throws a [FormatException] if [root] does not have a given field [name]. /// /// Super types [InterfaceElement2.supertype] are also checked before throwing. -void assertHasField2(InterfaceElement2 root, String name) { +void assertHasField(InterfaceElement2 root, String name) { InterfaceElement2? element = root; while (element != null) { final field = element.getField2(name); @@ -53,6 +28,13 @@ void assertHasField2(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 80de190e..6a6a41e9 100644 --- a/source_gen/lib/src/generator.dart +++ b/source_gen/lib/src/generator.dart @@ -5,10 +5,7 @@ import 'dart:async'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; -// ignore: implementation_imports -import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:build/build.dart'; import 'library.dart'; @@ -52,7 +49,7 @@ class InvalidGenerationSource implements Exception { /// /// May be `null` if the error had no associated element, or if the location /// was passed with [node]. - final Element2? element2; + final Element2? element; /// The AST Node associated with this error. /// @@ -60,31 +57,31 @@ class InvalidGenerationSource implements Exception { /// code, or if the location was passed with [element]. final AstNode? node; - @Deprecated('use v2 instead') InvalidGenerationSource( this.message, { this.todo = '', - Element? element, + this.element, this.node, - }) : element2 = element?.asElement2; + }); + @Deprecated('use the unnamed constructor instead') InvalidGenerationSource.v2( this.message, { this.todo = '', - Element2? element, + this.element, this.node, - }) : element2 = element; + }); - @Deprecated('use element2 instead') - Element? get element => element2?.asElement; + @Deprecated('use element instead') + Element2? get element2 => element; @override String toString() { final buffer = StringBuffer(message); - if (element2 case final element2?) { + if (element case final element2?) { try { - final span = spanForElement2(element2); + final span = spanForElement(element2); buffer ..writeln() ..writeln(span.start.toolString) diff --git a/source_gen/lib/src/generator_for_annotation.dart b/source_gen/lib/src/generator_for_annotation.dart index b3bee2fd..ff5b17c8 100644 --- a/source_gen/lib/src/generator_for_annotation.dart +++ b/source_gen/lib/src/generator_for_annotation.dart @@ -4,7 +4,6 @@ import 'dart:async'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; @@ -74,14 +73,12 @@ abstract class GeneratorForAnnotation extends Generator { typeChecker, throwOnUnresolved: throwOnUnresolved, )) { - var generatedValue = generateForAnnotatedElement2( - annotatedElement.element2, + var generatedValue = generateForAnnotatedElement( + annotatedElement.element, annotatedElement.annotation, buildStep, ); - generatedValue ??= generateForAnnotatedElement( - // Support "generateForAnnotatedElements" until it's removed. - // ignore: analyzer_use_new_elements + generatedValue ??= generateForAnnotatedElement2( annotatedElement.element, annotatedElement.annotation, buildStep, @@ -112,9 +109,8 @@ abstract class GeneratorForAnnotation extends Generator { /// /// Implementations should return `null` when no content is generated. Empty /// or whitespace-only [String] instances are also ignored. - @Deprecated('use generateForAnnotatedElement2 instead') dynamic generateForAnnotatedElement( - Element element, + Element2 element, ConstantReader annotation, BuildStep buildStep, ) {} @@ -136,6 +132,7 @@ abstract class GeneratorForAnnotation extends Generator { /// /// 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, diff --git a/source_gen/lib/src/library.dart b/source_gen/lib/src/library.dart index 93c0f8b6..52679eb4 100644 --- a/source_gen/lib/src/library.dart +++ b/source_gen/lib/src/library.dart @@ -2,10 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; -// ignore: implementation_imports -import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:build/build.dart'; import 'package:path/path.dart' as p; @@ -26,15 +23,15 @@ class AnnotatedDirective { /// Result of finding an [annotation] on [element] through [LibraryReader]. class AnnotatedElement { final ConstantReader annotation; - final Element2 element2; + final Element2 element; - const AnnotatedElement(this.annotation, this.element2); + const AnnotatedElement(this.annotation, this.element); - @Deprecated('use element2 instead') - Element get element => element2.asElement!; + @Deprecated('use element instead') + Element2 get element2 => element; Metadata? get metadata2 { - if (element2 case final Annotatable annotatable) { + if (element case final Annotatable annotatable) { return annotatable.metadata2; } return null; @@ -43,51 +40,44 @@ class AnnotatedElement { /// A high-level wrapper API with common functionality for [LibraryElement2]. class LibraryReader { - final LibraryElement2 element2; + final LibraryElement2 element; - @Deprecated('use v2 instead') - LibraryReader(LibraryElement element) : this.v2(element.asElement2); + LibraryReader(this.element); - LibraryReader.v2(this.element2); + @Deprecated('use the default constructor instead') + LibraryReader.v2(this.element); - @Deprecated('use element2 instead') - LibraryElement get element => element2.asElement; + @Deprecated('use element instead') + LibraryElement2 get element2 => element; /// All of the declarations in this library. - @Deprecated('use allElements2 instead') - Iterable get allElements => [ - element, - ...element.topLevelElements, - ...element.definingCompilationUnit.libraryImports, - ...element.definingCompilationUnit.libraryExports, - ...element.definingCompilationUnit.parts, - ]; + Iterable get allElements => [element, ...element.children2]; /// All of the declarations in this library. - Iterable get allElements2 => [element2, ...element2.children2]; + @Deprecated('use allElements instead') + Iterable get allElements2 => allElements; /// All of the elements representing classes in this library. - @Deprecated('use classes2 instead') - Iterable get classes => - element.units.expand((cu) => cu.classes); + Iterable get classes => element.classes; /// All of the elements representing classes in this library. - Iterable get classes2 => element2.classes; + @Deprecated('use classes instead') + Iterable get classes2 => classes; /// All of the elements representing enums in this library. - @Deprecated('use enums2 instead') - Iterable get enums => element.units.expand((cu) => cu.enums); + Iterable get enums => element.enums; /// All of the elements representing enums in this library. - Iterable get enums2 => element2.enums; + @Deprecated('use enums instead') + Iterable get enums3 => enums; /// All of the declarations in this library annotated with [checker]. Iterable annotatedWith( TypeChecker checker, { bool throwOnUnresolved = true, }) sync* { - for (final element in allElements2) { - final annotation = checker.firstAnnotationOf2( + for (final element in allElements) { + final annotation = checker.firstAnnotationOf( element, throwOnUnresolved: throwOnUnresolved, ); @@ -103,7 +93,7 @@ class LibraryReader { TypeChecker checker, { bool throwOnUnresolved = true, }) sync* { - final firstFragment = element2.firstFragment; + final firstFragment = element.firstFragment; final directives = [ ...firstFragment.libraryImports2, ...firstFragment.libraryExports2, @@ -111,7 +101,7 @@ class LibraryReader { ]; for (final directive in directives) { - final annotation = checker.firstAnnotationOf2( + final annotation = checker.firstAnnotationOf( directive, throwOnUnresolved: throwOnUnresolved, ); @@ -127,8 +117,8 @@ class LibraryReader { TypeChecker checker, { bool throwOnUnresolved = true, }) sync* { - for (final element in allElements2) { - final annotation = checker.firstAnnotationOfExact2( + for (final element in allElements) { + final annotation = checker.firstAnnotationOfExact( element, throwOnUnresolved: throwOnUnresolved, ); @@ -138,24 +128,21 @@ class LibraryReader { } } - /// Returns a top-level [ClassElement] publicly visible in by [name]. + /// Returns a top-level [ClassElement2] publicly visible in by [name]. /// - /// Unlike [LibraryElement.getClass], this also correctly traverses + /// Unlike [LibraryElement2.getClass2], this also correctly traverses /// identifiers that are accessible via one or more `export` directives. - @Deprecated('Use findType2() instead') - ClassElement? findType(String name) { - final type = element.exportNamespace.get(name); - return type is ClassElement ? type : null; + ClassElement2? findType(String name) { + final type = element.exportNamespace.get2(name); + 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. - ClassElement2? findType2(String name) { - final type = element2.exportNamespace.get2(name); - return type is ClassElement2 ? type : null; - } + @Deprecated('Use findType() instead') + ClassElement2? findType2(String name) => findType(name); /// Returns a [Uri] from the current library to the target [asset]. /// @@ -167,15 +154,15 @@ class LibraryReader { /// /// This is a typed convenience function for using [pathToUrl], and the same /// API restrictions hold around supported schemes and relative paths. - @Deprecated('use pathToElement2 instead') - Uri pathToElement(Element element) => pathToUrl(element.source!.uri); + 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. - Uri pathToElement2(Element2 element) => - pathToUrl(element.firstFragment.libraryFragment!.source.uri); + @Deprecated('use pathToElement instead') + Uri pathToElement2(Element2 element) => pathToElement(element); /// Returns a [Uri] from the current library to the one provided. /// @@ -212,7 +199,7 @@ class LibraryReader { if (to.pathSegments.length > 1 && to.pathSegments[1] == 'lib') { return assetToPackageUrl(to); } - var from = element2.uri; + var from = element.uri; // Normalize (convert to an asset: URL). from = normalizeUrl(from); if (_isRelative(from, to)) { diff --git a/source_gen/lib/src/span_for_element.dart b/source_gen/lib/src/span_for_element.dart index 572f89b4..386a63f8 100644 --- a/source_gen/lib/src/span_for_element.dart +++ b/source_gen/lib/src/span_for_element.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:source_span/source_span.dart'; @@ -20,47 +19,7 @@ import 'utils.dart'; /// /// 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 spanForElement2 instead') -SourceSpan spanForElement(Element element, [SourceFile? file]) { - final url = assetToPackageUrl(element.source!.uri); - if (file == null) { - final contents = element.source?.contents; - if (contents == null) { - return SourceSpan( - SourceLocation(element.nameOffset, sourceUrl: url), - SourceLocation(element.nameOffset + element.nameLength, sourceUrl: url), - element.name!, - ); - } - file = SourceFile.fromString(contents.data, url: url); - } - if (element.nameOffset < 0) { - if (element is PropertyInducingElement) { - if (element.getter != null) { - return spanForElement(element.getter!); - } - - if (element.setter != null) { - return spanForElement(element.setter!); - } - } - } - - return file.span(element.nameOffset, element.nameOffset + element.nameLength); -} - -/// 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. -SourceSpan spanForElement2(Element2 element, [SourceFile? file]) { +SourceSpan spanForElement(Element2 element, [SourceFile? file]) { final fragment = element.firstFragment; final url = assetToPackageUrl(fragment.libraryFragment!.source.uri); if (file == null) { @@ -80,11 +39,11 @@ SourceSpan spanForElement2(Element2 element, [SourceFile? file]) { if (fragment.nameOffset2 == null) { if (element is PropertyInducingElement2) { if (element.getter2 != null) { - return spanForElement2(element.getter2!); + return spanForElement(element.getter2!); } if (element.setter2 != null) { - return spanForElement2(element.setter2!); + return spanForElement(element.setter2!); } } } @@ -95,6 +54,21 @@ SourceSpan spanForElement2(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 511f6856..ac73ad8a 100644 --- a/source_gen/lib/src/type_checker.dart +++ b/source_gen/lib/src/type_checker.dart @@ -7,11 +7,8 @@ import 'dart:mirrors' hide SourceLocation; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; -// ignore: implementation_imports -import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:build/build.dart'; import 'package:source_span/source_span.dart'; @@ -64,13 +61,15 @@ abstract class TypeChecker { /// Otherwise returns `null`. /// /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. - @Deprecated('use firstAnnotationOf2 instead') DartObject? firstAnnotationOf( - Element element, { + Object element, { bool throwOnUnresolved = true, }) { - if (element.metadata.isEmpty) { - return null; + if (element case final Annotatable annotatable) { + final annotations = annotatable.metadata2.annotations; + if (annotations.isEmpty) { + return null; + } } final results = annotationsOf( element, @@ -84,60 +83,31 @@ abstract class TypeChecker { /// Otherwise returns `null`. /// /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. + @Deprecated('use firstAnnotationOf instead') DartObject? firstAnnotationOf2( Object element, { bool throwOnUnresolved = true, - }) { - if (element case final Annotatable annotatable) { - final annotations = annotatable.metadata2.annotations; - if (annotations.isEmpty) { - return null; - } - } - final results = annotationsOf2( - element, - throwOnUnresolved: throwOnUnresolved, - ); - return results.isEmpty ? null : results.first; - } + }) => + firstAnnotationOf(element, throwOnUnresolved: throwOnUnresolved); /// Returns if a constant annotating [element] is assignable to this type. /// /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. - @Deprecated('use hasAnnotationOf2 instead') - bool hasAnnotationOf(Element element, {bool throwOnUnresolved = true}) => + 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}) => - firstAnnotationOf2(element, throwOnUnresolved: throwOnUnresolved) != null; + hasAnnotationOf(element, throwOnUnresolved: throwOnUnresolved); /// 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 firstAnnotationOfExact2 instead') DartObject? firstAnnotationOfExact( - Element element, { - bool throwOnUnresolved = true, - }) { - if (element.metadata.isEmpty) { - return null; - } - final results = annotationsOfExact( - element, - throwOnUnresolved: throwOnUnresolved, - ); - return results.isEmpty ? null : results.first; - } - - /// 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`). - DartObject? firstAnnotationOfExact2( Element2 element, { bool throwOnUnresolved = true, }) { @@ -146,7 +116,7 @@ abstract class TypeChecker { if (annotations.isEmpty) { return null; } - final results = annotationsOfExact2( + final results = annotationsOfExact( element, throwOnUnresolved: throwOnUnresolved, ); @@ -155,12 +125,25 @@ 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 /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use hasAnnotationOfExact2 instead') - bool hasAnnotationOfExact(Element element, {bool throwOnUnresolved = true}) => + bool hasAnnotationOfExact( + Element2 element, { + bool throwOnUnresolved = true, + }) => firstAnnotationOfExact(element, throwOnUnresolved: throwOnUnresolved) != null; @@ -168,31 +151,14 @@ abstract class TypeChecker { /// /// 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, }) => - firstAnnotationOfExact2(element, throwOnUnresolved: throwOnUnresolved) != - null; + hasAnnotationOfExact(element, throwOnUnresolved: throwOnUnresolved); - @Deprecated('use _computeConstantValue2 instead') DartObject? _computeConstantValue( - Element element, - int annotationIndex, { - bool throwOnUnresolved = true, - }) { - final annotation = element.metadata[annotationIndex]; - final result = annotation.computeConstantValue(); - if (result == null && throwOnUnresolved) { - throw UnresolvedAnnotationException._from( - element.asElement2!, - annotationIndex, - ); - } - return result; - } - - DartObject? _computeConstantValue2( Object element, ElementAnnotation annotation, int annotationIndex, { @@ -209,9 +175,8 @@ abstract class TypeChecker { /// /// Throws [UnresolvedAnnotationException] on unresolved annotations unless /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use annotationsOf2 instead') Iterable annotationsOf( - Element element, { + Object element, { bool throwOnUnresolved = true, }) => _annotationsWhere( @@ -224,35 +189,14 @@ abstract class TypeChecker { /// /// 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, }) => - _annotationsWhere2( - element, - isAssignableFromType, - throwOnUnresolved: throwOnUnresolved, - ); + annotationsOf(element, throwOnUnresolved: throwOnUnresolved); - @Deprecated('use _annotationsWhere2 instead') Iterable _annotationsWhere( - Element element, - bool Function(DartType) predicate, { - bool throwOnUnresolved = true, - }) sync* { - for (var i = 0; i < element.metadata.length; i++) { - final value = _computeConstantValue( - element, - i, - throwOnUnresolved: throwOnUnresolved, - ); - if (value?.type != null && predicate(value!.type!)) { - yield value; - } - } - } - - Iterable _annotationsWhere2( Object element, bool Function(DartType) predicate, { bool throwOnUnresolved = true, @@ -260,7 +204,7 @@ abstract class TypeChecker { if (element case final Annotatable annotatable) { final annotations = annotatable.metadata2.annotations; for (var i = 0; i < annotations.length; i++) { - final value = _computeConstantValue2( + final value = _computeConstantValue( element, annotations[i], i, @@ -277,9 +221,8 @@ abstract class TypeChecker { /// /// Throws [UnresolvedAnnotationException] on unresolved annotations unless /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). - @Deprecated('use annotationsOfExact2 instead') Iterable annotationsOfExact( - Element element, { + Element2 element, { bool throwOnUnresolved = true, }) => _annotationsWhere( @@ -292,40 +235,35 @@ abstract class TypeChecker { /// /// 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, }) => - _annotationsWhere2( - element, - isExactlyType, - throwOnUnresolved: throwOnUnresolved, - ); + annotationsOfExact(element, throwOnUnresolved: throwOnUnresolved); /// Returns `true` if the type of [element] can be assigned to this type. - @Deprecated('use isAssignableFrom2 instead') - bool isAssignableFrom(Element element) => + bool isAssignableFrom(Element2 element) => isExactly(element) || - (element is InterfaceElement && element.allSupertypes.any(isExactlyType)); - - /// Returns `true` if the type of [element] can be assigned to this type. - bool isAssignableFrom2(Element2 element) => - isExactly2(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; - return element != null && isAssignableFrom2(element); + return element != null && isAssignableFrom(element); } /// Returns `true` if representing the exact same class as [element]. - @Deprecated('use isExactly2 instead') - bool isExactly(Element element); + bool isExactly(Element2 element); /// Returns `true` if representing the exact same class as [element]. - bool isExactly2(Element2 element); + @Deprecated('use isExactly instead') + bool isExactly2(Element2 element) => isExactly(element); /// Returns `true` if representing the exact same type as [staticType]. /// @@ -334,7 +272,7 @@ abstract class TypeChecker { bool isExactlyType(DartType staticType) { final element = staticType.element3; if (element != null) { - return isExactly2(element); + return isExactly(element); } else { return false; } @@ -344,9 +282,8 @@ abstract class TypeChecker { /// /// This check only takes into account the *extends* hierarchy. If you wish /// to check mixins and interfaces, use [isAssignableFrom]. - @Deprecated('use isSuperOf2 instead') - bool isSuperOf(Element element) { - if (element is InterfaceElement) { + bool isSuperOf(Element2 element) { + if (element is InterfaceElement2) { var theSuper = element.supertype; do { @@ -365,27 +302,14 @@ abstract class TypeChecker { /// /// This check only takes into account the *extends* hierarchy. If you wish /// to check mixins and interfaces, use [isAssignableFrom]. - bool isSuperOf2(Element2 element) { - if (element is InterfaceElement2) { - var theSuper = element.supertype; - - do { - if (isExactlyType(theSuper!)) { - return true; - } - - theSuper = theSuper.superclass; - } while (theSuper != null); - } - - return false; - } + @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 /// to check mixins and interfaces, use [isAssignableFromType]. - bool isSuperTypeOf(DartType staticType) => isSuperOf2(staticType.element3!); + bool isSuperTypeOf(DartType staticType) => isSuperOf(staticType.element3!); } // Checks a static type against another static type; @@ -394,17 +318,16 @@ class _LibraryTypeChecker extends TypeChecker { const _LibraryTypeChecker(this._type) : super._(); - @Deprecated('Use isExactly2() instead') @override - bool isExactly(Element element) => - element is InterfaceElement && element == _type.element; + bool isExactly(Element2 element) => + element is InterfaceElement2 && element == _type.element3; + @Deprecated('Use isExactly() instead') @override - bool isExactly2(Element2 element) => - element is InterfaceElement2 && element == _type.element3; + bool isExactly2(Element2 element) => isExactly(element); @override - String toString() => urlOfElement2(_type.element3!); + String toString() => urlOfElement(_type.element3!); } // Checks a runtime type against a static type. @@ -423,12 +346,12 @@ class _MirrorTypeChecker extends TypeChecker { TypeChecker get _computed => _cache[this] ??= TypeChecker.fromUrl(_uriOf(reflectClass(_type))); - @Deprecated('use isExactly2 instead') @override - bool isExactly(Element element) => _computed.isExactly(element); + bool isExactly(Element2 element) => _computed.isExactly(element); + @Deprecated('use isExactly instead') @override - bool isExactly2(Element2 element) => _computed.isExactly2(element); + bool isExactly2(Element2 element) => isExactly(element); @override String toString() => _computed.toString(); @@ -459,12 +382,12 @@ class _UriTypeChecker extends TypeChecker { uri.toString() == (url is String ? url : normalizeUrl(url as Uri).toString()); - @Deprecated('use isExactly2 instead') @override - bool isExactly(Element element) => hasSameUrl(urlOfElement(element)); + bool isExactly(Element2 element) => hasSameUrl(urlOfElement(element)); + @Deprecated('use isExactly instead') @override - bool isExactly2(Element2 element) => hasSameUrl(urlOfElement2(element)); + bool isExactly2(Element2 element) => isExactly(element); @override String toString() => '$uri'; @@ -475,13 +398,13 @@ class _AnyChecker extends TypeChecker { const _AnyChecker(this._checkers) : super._(); - @Deprecated('use isExactly2 instead') @override - bool isExactly(Element element) => _checkers.any((c) => c.isExactly(element)); + bool isExactly(Element2 element) => + _checkers.any((c) => c.isExactly(element)); + @Deprecated('use isExactly2 instead') @override - bool isExactly2(Element2 element) => - _checkers.any((c) => c.isExactly2(element)); + bool isExactly2(Element2 element) => isExactly(element); } /// Exception thrown when [TypeChecker] fails to resolve a metadata annotation. @@ -492,15 +415,15 @@ class _AnyChecker extends TypeChecker { /// defined (for build systems such as Bazel). class UnresolvedAnnotationException implements Exception { /// Element that was annotated with something we could not resolve. - final Element2 annotatedElement2; + final Element2 annotatedElement; /// Source span of the annotation that was not resolved. /// /// May be `null` if the import library was not found. final SourceSpan? annotationSource; - @Deprecated('use annotatedElement2 instead') - Element get annotatedElement => annotatedElement2.asElement!; + @Deprecated('use annotatedElement instead') + Element2 get annotatedElement2 => annotatedElement; static SourceSpan? _findSpan(Element2 annotatedElement, int annotationIndex) { try { @@ -562,13 +485,13 @@ the version of `package:source_gen`, `package:analyzer` from `pubspec.lock`. } const UnresolvedAnnotationException._( - this.annotatedElement2, + this.annotatedElement, this.annotationSource, ); @override String toString() { - final message = 'Could not resolve annotation for `$annotatedElement2`.'; + final message = 'Could not resolve annotation for `$annotatedElement`.'; if (annotationSource != null) { return annotationSource!.message(message); } diff --git a/source_gen/lib/src/utils.dart b/source_gen/lib/src/utils.dart index ebe6acf9..cf5714f7 100644 --- a/source_gen/lib/src/utils.dart +++ b/source_gen/lib/src/utils.dart @@ -5,7 +5,6 @@ import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; @@ -45,13 +44,13 @@ bool hasExpectedPartDirective(CompilationUnit unit, String part) => .any((e) => e.uri.stringValue == part); /// Returns a uri suitable for `part of "..."` when pointing to [element]. -@Deprecated('use uriOfPartial2 instead') -String uriOfPartial(LibraryElement element, AssetId source, AssetId output) { +String uriOfPartial(LibraryElement2 element, AssetId source, AssetId output) { assert(source.package == output.package); 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)); @@ -65,15 +64,15 @@ String computePartUrl(AssetId input, AssetId output) => p.url.joinAll( ); /// Returns a URL representing [element]. -@Deprecated('use urlOfElement2 instead') -String urlOfElement(Element element) => element.kind == ElementKind.DYNAMIC +String urlOfElement(Element2 element) => element.kind == ElementKind.DYNAMIC ? 'dart:core#dynamic' // using librarySource.uri – in case the element is in a part - : normalizeUrl(element.librarySource!.uri) - .replace(fragment: element.name) + : normalizeUrl(element.library2!.uri) + .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 diff --git a/source_gen/test/constants/utils_test.dart b/source_gen/test/constants/utils_test.dart index 4c3cd6df..f36bdb0b 100644 --- a/source_gen/test/constants/utils_test.dart +++ b/source_gen/test/constants/utils_test.dart @@ -36,19 +36,19 @@ void main() { test('should not throw when a class contains a field', () { final $A = testLib.getClass2('A')!; // ignore: deprecated_member_use_from_same_package - expect(() => assertHasField2($A, 'a'), returnsNormally); + expect(() => assertHasField($A, 'a'), returnsNormally); }); test('should not throw when a super class contains a field', () { final $B = testLib.getClass2('B')!; // ignore: deprecated_member_use_from_same_package - expect(() => assertHasField2($B, 'a'), returnsNormally); + expect(() => assertHasField($B, 'a'), returnsNormally); }); test('should throw when a class does not contain a field', () { final $C = testLib.getClass2('C')!; // ignore: deprecated_member_use_from_same_package - expect(() => assertHasField2($C, 'a'), throwsFormatException); + expect(() => assertHasField($C, 'a'), throwsFormatException); }); }); diff --git a/source_gen/test/external_only_type_checker_test.dart b/source_gen/test/external_only_type_checker_test.dart index 78a424cb..6ef5bde7 100644 --- a/source_gen/test/external_only_type_checker_test.dart +++ b/source_gen/test/external_only_type_checker_test.dart @@ -28,7 +28,7 @@ void main() { export 'type_checker_test.dart' show NonPublic; ''', (resolver) async { - thisTest = LibraryReader.v2( + thisTest = LibraryReader( await resolver.libraryFor2( AssetId('source_gen', 'test/external_only_type_checker_test.dart'), ), @@ -37,7 +37,7 @@ void main() { inputId: AssetId('source_gen', 'test/example.dart'), ); - staticNonPublic = thisTest.findType2('NonPublic')!.instantiate( + staticNonPublic = thisTest.findType('NonPublic')!.instantiate( typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none, ); diff --git a/source_gen/test/generator_for_annotation_test.dart b/source_gen/test/generator_for_annotation_test.dart index c140235d..598f0280 100644 --- a/source_gen/test/generator_for_annotation_test.dart +++ b/source_gen/test/generator_for_annotation_test.dart @@ -268,7 +268,7 @@ class _StubGenerator extends GeneratorForAnnotation { directiveBehavior(directive); @override - Object? generateForAnnotatedElement2( + Object? generateForAnnotatedElement( Element2 element, ConstantReader annotation, BuildStep buildStep, diff --git a/source_gen/test/library/find_type_test.dart b/source_gen/test/library/find_type_test.dart index 0cbb4918..83d9b88f 100644 --- a/source_gen/test/library/find_type_test.dart +++ b/source_gen/test/library/find_type_test.dart @@ -34,36 +34,36 @@ void main() { setUpAll(() async { library = await resolveSources( {'a|source.dart': _source, 'a|part.dart': _partSource}, - (r) async => LibraryReader.v2((await r.findLibraryByName2('test_lib'))!), + (r) async => LibraryReader((await r.findLibraryByName2('test_lib'))!), ); }); test('class count', () { - expect(library.classes2.map((c) => c.name3), ['Example', 'PartClass']); + expect(library.classes.map((c) => c.name3), ['Example', 'PartClass']); }); test('enum count', () { - expect(library.enums2.map((e) => e.name3), ['Enum', 'PartEnum']); + expect(library.enums.map((e) => e.name3), ['Enum', 'PartEnum']); }); test('should return a type not exported', () { - expect(library.findType2('Example'), _isClassElement); + expect(library.findType('Example'), _isClassElement); }); test('should return a type from a part', () { - expect(library.findType2('PartClass'), _isClassElement); + expect(library.findType('PartClass'), _isClassElement); }); test('should return a type exported from dart:', () { - expect(library.findType2('LinkedHashMap'), _isClassElement); + expect(library.findType('LinkedHashMap'), _isClassElement); }); test('should return a type exported from package:', () { - expect(library.findType2('Generator'), _isClassElement); + expect(library.findType('Generator'), _isClassElement); }); test('should not return a type imported', () { - expect(library.findType2('Stream'), isNull); + expect(library.findType('Stream'), isNull); }); } diff --git a/source_gen/test/library/path_to_url_test.dart b/source_gen/test/library/path_to_url_test.dart index 33c2b791..c94e8415 100644 --- a/source_gen/test/library/path_to_url_test.dart +++ b/source_gen/test/library/path_to_url_test.dart @@ -23,7 +23,7 @@ void main() { group('from a package URL to', () { setUpAll(() { - reader = LibraryReader.v2(_FakeLibraryElement(packageA)); + reader = LibraryReader(_FakeLibraryElement(packageA)); }); test('a dart SDK library', () { @@ -61,7 +61,7 @@ void main() { group('from an asset URL representing a package to', () { setUpAll(() { - reader = LibraryReader.v2(_FakeLibraryElement(assetPackageA)); + reader = LibraryReader(_FakeLibraryElement(assetPackageA)); }); test('a dart SDK library', () { @@ -99,7 +99,7 @@ void main() { group('from an asset URL representing a test directory to', () { setUpAll(() { - reader = LibraryReader.v2(_FakeLibraryElement(packageATestDir)); + reader = LibraryReader(_FakeLibraryElement(packageATestDir)); }); test('a dart SDK library', () { @@ -142,7 +142,7 @@ void main() { }); test('in the same package in the test directory, a shallow file', () { - reader = LibraryReader.v2(_FakeLibraryElement(packageATestDirDeepFile)); + reader = LibraryReader(_FakeLibraryElement(packageATestDirDeepFile)); expect(reader.pathToUrl(packageATestDir), Uri.parse('../../../a.dart')); }); diff --git a/source_gen/test/span_for_element_test.dart b/source_gen/test/span_for_element_test.dart index dc552daa..b088829d 100644 --- a/source_gen/test/span_for_element_test.dart +++ b/source_gen/test/span_for_element_test.dart @@ -39,7 +39,7 @@ abstract class Example implements List { test('should highlight the use of "class Example"', () async { expect( - spanForElement2(library.getClass2('Example')!).message('Here it is'), + spanForElement(library.getClass2('Example')!).message('Here it is'), r""" line 3, column 16 of package:test_lib/test_lib.dart: Here it is , @@ -51,7 +51,7 @@ line 3, column 16 of package:test_lib/test_lib.dart: Here it is test('should correctly highlight getter', () async { expect( - spanForElement2(library.getClass2('Example')!.getField2('getter')!) + spanForElement(library.getClass2('Example')!.getField2('getter')!) .message('Here it is'), r""" line 4, column 15 of package:test_lib/test_lib.dart: Here it is @@ -64,7 +64,7 @@ line 4, column 15 of package:test_lib/test_lib.dart: Here it is test('should correctly highlight setter', () async { expect( - spanForElement2(library.getClass2('Example')!.getField2('setter')!) + spanForElement(library.getClass2('Example')!.getField2('setter')!) .message('Here it is'), r""" line 5, column 7 of package:test_lib/test_lib.dart: Here it is @@ -77,7 +77,7 @@ line 5, column 7 of package:test_lib/test_lib.dart: Here it is test('should correctly highlight field', () async { expect( - spanForElement2(library.getClass2('Example')!.getField2('field')!) + spanForElement(library.getClass2('Example')!.getField2('field')!) .message('Here it is'), r""" line 6, column 7 of package:test_lib/test_lib.dart: Here it is @@ -90,7 +90,7 @@ line 6, column 7 of package:test_lib/test_lib.dart: Here it is test('highlight getter with getter/setter property', () async { expect( - spanForElement2(library.getClass2('Example')!.getField2('fieldProp')!) + spanForElement(library.getClass2('Example')!.getField2('fieldProp')!) .message('Here it is'), r""" line 7, column 11 of package:test_lib/test_lib.dart: Here it is diff --git a/source_gen/test/src/comment_generator.dart b/source_gen/test/src/comment_generator.dart index 64cffb07..987b969e 100644 --- a/source_gen/test/src/comment_generator.dart +++ b/source_gen/test/src/comment_generator.dart @@ -15,15 +15,14 @@ class CommentGenerator extends Generator { Future generate(LibraryReader library, _) async { final output = []; if (forLibrary) { - var name = library.element2.name3!; + var name = library.element.name3!; if (name.isEmpty) { - name = library.element2.uri.pathSegments.last; + name = library.element.uri.pathSegments.last; } output.add('// Code for "$name"'); } if (forClasses) { - for (var classElement - in library.allElements2.whereType()) { + for (var classElement in library.allElements.whereType()) { if (classElement.displayName.contains('GoodError')) { throw InvalidGenerationSourceError.v2( "Don't use classes with the word 'Error' in the name", @@ -42,6 +41,6 @@ class CommentGenerator extends Generator { class DeprecatedGeneratorForAnnotation extends GeneratorForAnnotation { @override - String generateForAnnotatedElement2(Element2 element, _, __) => + String generateForAnnotatedElement(Element2 element, _, __) => '// "$element" is deprecated!'; } diff --git a/source_gen/test/type_checker_test.dart b/source_gen/test/type_checker_test.dart index 481f3e48..06f1a176 100644 --- a/source_gen/test/type_checker_test.dart +++ b/source_gen/test/type_checker_test.dart @@ -57,7 +57,7 @@ void main() { (resolver) async { core = (await resolver.findLibraryByName2('dart.core'))!; collection = (await resolver.findLibraryByName2('dart.collection'))!; - sourceGen = LibraryReader.v2( + sourceGen = LibraryReader( await resolver.libraryFor2( AssetId('source_gen', 'lib/source_gen.dart'), ), @@ -131,13 +131,13 @@ void main() { nullabilitySuffix: NullabilitySuffix.none, ); - staticGenerator = sourceGen.findType2('Generator')!.instantiate( + staticGenerator = sourceGen.findType('Generator')!.instantiate( typeArguments: [], nullabilitySuffix: NullabilitySuffix.none, ); staticGeneratorChecker = TypeChecker.fromStatic(staticGenerator); staticGeneratorForAnnotation = - sourceGen.findType2('GeneratorForAnnotation')!.instantiate( + sourceGen.findType('GeneratorForAnnotation')!.instantiate( typeArguments: [core.typeProvider.dynamicType], nullabilitySuffix: NullabilitySuffix.none, ); @@ -201,7 +201,7 @@ void main() { () { test('should equal MapMixin class', () { expect(checkMapMixin().isExactlyType(staticMapMixin), isTrue); - expect(checkMapMixin().isExactly2(staticMapMixin.element3), isTrue); + expect(checkMapMixin().isExactly(staticMapMixin.element3), isTrue); }); }, onPlatform: const { @@ -371,7 +371,7 @@ void main() { const $deprecated = TypeChecker.fromRuntime(Deprecated); expect( - () => $deprecated.annotationsOf2(classX), + () => $deprecated.annotationsOf(classX), throwsA( const TypeMatcher().having( (e) => e.toString(), @@ -463,35 +463,35 @@ void main() { }); test('of a single @A', () { - expect($A.hasAnnotationOf2($ExampleOfA), isTrue); - final aAnnotation = $A.firstAnnotationOf2($ExampleOfA)!; + expect($A.hasAnnotationOf($ExampleOfA), isTrue); + final aAnnotation = $A.firstAnnotationOf($ExampleOfA)!; expect(aAnnotation.type!.element3!.name3, 'A'); - expect($B.annotationsOf2($ExampleOfA), isEmpty); - expect($C.annotationsOf2($ExampleOfA), isEmpty); + expect($B.annotationsOf($ExampleOfA), isEmpty); + expect($C.annotationsOf($ExampleOfA), isEmpty); }); test('of a multiple @A', () { - final aAnnotations = $A.annotationsOf2($ExampleOfMultiA); + final aAnnotations = $A.annotationsOf($ExampleOfMultiA); expect(aAnnotations.map((a) => a.type!.element3!.name3), ['A', 'A']); - expect($B.annotationsOf2($ExampleOfA), isEmpty); - expect($C.annotationsOf2($ExampleOfA), isEmpty); + expect($B.annotationsOf($ExampleOfA), isEmpty); + expect($C.annotationsOf($ExampleOfA), isEmpty); }); test('of a single @A + single @B', () { - final aAnnotations = $A.annotationsOf2($ExampleOfAPlusB); + final aAnnotations = $A.annotationsOf($ExampleOfAPlusB); expect(aAnnotations.map((a) => a.type!.element3!.name3), ['A']); - final bAnnotations = $B.annotationsOf2($ExampleOfAPlusB); + final bAnnotations = $B.annotationsOf($ExampleOfAPlusB); expect(bAnnotations.map((a) => a.type!.element3!.name3), ['B']); - expect($C.annotationsOf2($ExampleOfAPlusB), isEmpty); + expect($C.annotationsOf($ExampleOfAPlusB), isEmpty); }); test('of a single @B + single @C', () { - final cAnnotations = $C.annotationsOf2($ExampleOfBPlusC); + final cAnnotations = $C.annotationsOf($ExampleOfBPlusC); expect(cAnnotations.map((a) => a.type!.element3!.name3), ['C']); - final bAnnotations = $B.annotationsOf2($ExampleOfBPlusC); + final bAnnotations = $B.annotationsOf($ExampleOfBPlusC); expect(bAnnotations.map((a) => a.type!.element3!.name3), ['B', 'C']); - expect($B.hasAnnotationOfExact2($ExampleOfBPlusC), isTrue); - final bExact = $B.annotationsOfExact2($ExampleOfBPlusC); + expect($B.hasAnnotationOfExact($ExampleOfBPlusC), isTrue); + final bExact = $B.annotationsOfExact($ExampleOfBPlusC); expect(bExact.map((a) => a.type!.element3!.name3), ['B']); }); }); @@ -534,35 +534,35 @@ void main() { test('should throw by default', () { expect( - () => $A.firstAnnotationOf2($ExampleOfA), + () => $A.firstAnnotationOf($ExampleOfA), throwsUnresolvedAnnotationException, ); expect( - () => $A.annotationsOf2($ExampleOfA), + () => $A.annotationsOf($ExampleOfA), throwsUnresolvedAnnotationException, ); expect( - () => $A.firstAnnotationOfExact2($ExampleOfA), + () => $A.firstAnnotationOfExact($ExampleOfA), throwsUnresolvedAnnotationException, ); expect( - () => $A.annotationsOfExact2($ExampleOfA), + () => $A.annotationsOfExact($ExampleOfA), throwsUnresolvedAnnotationException, ); expect( - () => $A.firstAnnotationOf2($annotatedParameter), + () => $A.firstAnnotationOf($annotatedParameter), throwsUnresolvedAnnotationException, ); expect( - () => $A.annotationsOf2($annotatedParameter), + () => $A.annotationsOf($annotatedParameter), throwsUnresolvedAnnotationException, ); expect( - () => $A.firstAnnotationOfExact2($annotatedParameter), + () => $A.firstAnnotationOfExact($annotatedParameter), throwsUnresolvedAnnotationException, ); expect( - () => $A.annotationsOfExact2($annotatedParameter), + () => $A.annotationsOfExact($annotatedParameter), throwsUnresolvedAnnotationException, ); }); @@ -570,7 +570,7 @@ void main() { test('should not throw if `throwOnUnresolved` == false', () { expect( $A - .firstAnnotationOf2($ExampleOfA, throwOnUnresolved: false)! + .firstAnnotationOf($ExampleOfA, throwOnUnresolved: false)! .type! .element3! .name3, @@ -578,13 +578,13 @@ void main() { ); expect( $A - .annotationsOf2($ExampleOfA, throwOnUnresolved: false) + .annotationsOf($ExampleOfA, throwOnUnresolved: false) .map((a) => a.type!.element3!.name3), ['A'], ); expect( $A - .firstAnnotationOfExact2($ExampleOfA, throwOnUnresolved: false)! + .firstAnnotationOfExact($ExampleOfA, throwOnUnresolved: false)! .type! .element3! .name3, @@ -592,7 +592,7 @@ void main() { ); expect( $A - .annotationsOfExact2($ExampleOfA, throwOnUnresolved: false) + .annotationsOfExact($ExampleOfA, throwOnUnresolved: false) .map((a) => a.type!.element3!.name3), ['A'], );