From 947a0e2631110dc13ae95e450acb58ab1ea13f71 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 17 Dec 2024 10:52:28 -0600 Subject: [PATCH 01/13] Support latest analyzer and dart_style, prepare v2 release (#736) --- example/pubspec.yaml | 2 +- source_gen/CHANGELOG.md | 7 ++++--- source_gen/pubspec.yaml | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6a92438d..b0e39913 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -6,7 +6,7 @@ environment: sdk: ^3.6.0 dependencies: - analyzer: '>=5.2.0 <7.0.0' + analyzer: '>=6.9.0 <8.0.0' build: ^2.0.0 source_gen: any diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index 14b39d41..f299d63a 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0-wip +## 2.0.0 - **Breaking Change**: Change `formatOutput` function to accept a language version parameter. @@ -8,13 +8,14 @@ - Document deduplication behavior for the output of `GeneratorForAnnotation.generateForAnnotatedElement`. - Support all the glob quotes. -- Require `analyzer: ^6.9.0` -- Require Dart 3.6.0 +- Require `analyzer: '>=6.9.0 <8.0.0'` +- Support the latest `package:dart_style` - `LibraryBuilder`, `PartBuilder`, and `SharedPartBuilder` now take an optional `writeDescriptions` boolean. When set to `false`, headers and generator descriptions for the files will not be included in the builder output. - Include `//dart format width=80` comments in files generated by a `LibraryBuilder` or `PartBuilder` and formatted with the default callback. +- Require Dart 3.6.0 ## 1.5.0 diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index 7d72a226..d650bb5c 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -1,5 +1,5 @@ name: source_gen -version: 2.0.0-wip +version: 2.0.0 description: >- Source code generation builders and utilities for the Dart build system repository: https://github.com/dart-lang/source_gen/tree/master/source_gen @@ -9,10 +9,10 @@ environment: sdk: ^3.6.0 dependencies: - analyzer: ^6.9.0 + analyzer: '>=6.9.0 <8.0.0' async: ^2.5.0 build: ^2.1.0 - dart_style: ^2.3.7 + dart_style: '>=2.3.7 <4.0.0' glob: ^2.0.0 path: ^1.8.0 pub_semver: ^2.1.4 From 0aa4656d433ea9525d7039f008f9483ce585ebe8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 17 Dec 2024 10:52:28 -0600 Subject: [PATCH 02/13] Support latest analyzer and dart_style, prepare v2 release (#736) --- example/pubspec.yaml | 2 +- source_gen/CHANGELOG.md | 7 ++++--- source_gen/pubspec.yaml | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6a92438d..b0e39913 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -6,7 +6,7 @@ environment: sdk: ^3.6.0 dependencies: - analyzer: '>=5.2.0 <7.0.0' + analyzer: '>=6.9.0 <8.0.0' build: ^2.0.0 source_gen: any diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index 14b39d41..f299d63a 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0-wip +## 2.0.0 - **Breaking Change**: Change `formatOutput` function to accept a language version parameter. @@ -8,13 +8,14 @@ - Document deduplication behavior for the output of `GeneratorForAnnotation.generateForAnnotatedElement`. - Support all the glob quotes. -- Require `analyzer: ^6.9.0` -- Require Dart 3.6.0 +- Require `analyzer: '>=6.9.0 <8.0.0'` +- Support the latest `package:dart_style` - `LibraryBuilder`, `PartBuilder`, and `SharedPartBuilder` now take an optional `writeDescriptions` boolean. When set to `false`, headers and generator descriptions for the files will not be included in the builder output. - Include `//dart format width=80` comments in files generated by a `LibraryBuilder` or `PartBuilder` and formatted with the default callback. +- Require Dart 3.6.0 ## 1.5.0 diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index 0487df05..c24723e5 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -1,5 +1,5 @@ name: source_gen -version: 2.0.0-wip +version: 2.0.0 description: >- Source code generation builders and utilities for the Dart build system repository: https://github.com/dart-lang/source_gen/tree/master/source_gen @@ -10,10 +10,10 @@ environment: sdk: ^3.6.0 dependencies: - analyzer: ^6.9.0 + analyzer: '>=6.9.0 <8.0.0' async: ^2.5.0 build: ^2.1.0 - dart_style: ^2.3.7 + dart_style: '>=2.3.7 <4.0.0' glob: ^2.0.0 path: ^1.8.0 pub_semver: ^2.1.4 From 2650de3556685cbf423eb1e22f6b954b9328cdaa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Jan 2025 14:49:30 +0000 Subject: [PATCH 03/13] Bump actions/cache from 4.1.2 to 4.2.0 in the github-actions group (#737) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 1 update: [actions/cache](https://github.com/actions/cache). Updates `actions/cache` from 4.1.2 to 4.2.0
Release notes

Sourced from actions/cache's releases.

v4.2.0

⚠️ Important Changes

The cache backend service has been rewritten from the ground up for improved performance and reliability. actions/cache now integrates with the new cache service (v2) APIs.

The new service will gradually roll out as of February 1st, 2025. The legacy service will also be sunset on the same date. Changes in these release are fully backward compatible.

We are deprecating some versions of this action. We recommend upgrading to version v4 or v3 as soon as possible before February 1st, 2025. (Upgrade instructions below).

If you are using pinned SHAs, please use the SHAs of versions v4.2.0 or v3.4.0

If you do not upgrade, all workflow runs using any of the deprecated actions/cache will fail.

Upgrading to the recommended versions will not break your workflows.

Read more about the change & access the migration guide: reference to the announcement.

Minor changes

Minor and patch version updates for these dependencies:

  • @​actions/core: 1.11.1
  • @​actions/io: 1.1.3
  • @​vercel/ncc: 0.38.3

Full Changelog: https://github.com/actions/cache/compare/v4...v4.2.0

Changelog

Sourced from actions/cache's changelog.

Releases

4.2.0

TLDR; The cache backend service has been rewritten from the ground up for improved performance and reliability. actions/cache now integrates with the new cache service (v2) APIs.

The new service will gradually roll out as of February 1st, 2025. The legacy service will also be sunset on the same date. Changes in these release are fully backward compatible.

We are deprecating some versions of this action. We recommend upgrading to version v4 or v3 as soon as possible before February 1st, 2025. (Upgrade instructions below).

If you are using pinned SHAs, please use the SHAs of versions v4.2.0 or v3.4.0

If you do not upgrade, all workflow runs using any of the deprecated actions/cache will fail.

Upgrading to the recommended versions will not break your workflows.

4.1.2

  • Add GitHub Enterprise Cloud instances hostname filters to inform API endpoint choices - #1474
  • Security fix: Bump braces from 3.0.2 to 3.0.3 - #1475

4.1.1

  • Restore original behavior of cache-hit output - #1467

4.1.0

  • Ensure cache-hit output is set when a cache is missed - #1404
  • Deprecate save-always input - #1452

4.0.2

  • Fixed restore fail-on-cache-miss not working.

4.0.1

  • Updated isGhes check

4.0.0

  • Updated minimum runner version support from node 12 -> node 20

3.4.0

  • Integrated with the new cache service (v2) APIs

3.3.3

  • Updates @​actions/cache to v3.2.3 to fix accidental mutated path arguments to getCacheVersion actions/toolkit#1378
  • Additional audit fixes of npm package(s)

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/cache&package-manager=github_actions&previous-version=4.1.2&new-version=4.2.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- .github/workflows/dart.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 2e2ed302..ba55608a 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen;commands:analyze_1" @@ -74,7 +74,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_annotations-example-example_usage-source_gen;commands:format-analyze_0" @@ -147,7 +147,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:example_usage;commands:test_0" @@ -181,7 +181,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen;commands:test_1" @@ -215,7 +215,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:example_usage;commands:test_0" @@ -249,7 +249,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:source_gen;commands:test_1" From c6f1dfbb4181ad412c84a243e5b4dd8fcdc2a0ad Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 1 Jan 2025 11:38:08 -0800 Subject: [PATCH 04/13] Elements. Support for generateForAnnotatedDirective() and related. --- source_gen/lib/source_gen.dart | 3 +- .../lib/src/generator_for_annotation.dart | 38 ++++++ source_gen/lib/src/library.dart | 34 +++++ source_gen/lib/src/type_checker.dart | 10 +- source_gen/pubspec.yaml | 3 +- .../test/generator_for_annotation_test.dart | 116 ++++++++++++++---- 6 files changed, 176 insertions(+), 28 deletions(-) diff --git a/source_gen/lib/source_gen.dart b/source_gen/lib/source_gen.dart index 7e4acae8..57010a22 100644 --- a/source_gen/lib/source_gen.dart +++ b/source_gen/lib/source_gen.dart @@ -9,7 +9,8 @@ export 'src/constants/revive.dart' show Revivable; export 'src/generator.dart' show Generator, InvalidGenerationSource, InvalidGenerationSourceError; export 'src/generator_for_annotation.dart' show GeneratorForAnnotation; -export 'src/library.dart' show AnnotatedElement, LibraryReader; +export 'src/library.dart' + show AnnotatedDirective, AnnotatedElement, LibraryReader; export 'src/span_for_element.dart' show spanForElement, spanForElement2; export 'src/type_checker.dart' show TypeChecker, UnresolvedAnnotationException; export 'src/utils.dart' show typeNameOf; diff --git a/source_gen/lib/src/generator_for_annotation.dart b/source_gen/lib/src/generator_for_annotation.dart index 5a4bb715..f2a94092 100644 --- a/source_gen/lib/src/generator_for_annotation.dart +++ b/source_gen/lib/src/generator_for_annotation.dart @@ -55,6 +55,21 @@ abstract class GeneratorForAnnotation extends Generator { FutureOr generate(LibraryReader library, BuildStep buildStep) async { final values = {}; + for (var annotatedDirective in library.libraryDirectivesAnnotatedWith( + typeChecker, + throwOnUnresolved: throwOnUnresolved, + )) { + final generatedValue = generateForAnnotatedDirective( + annotatedDirective.directive, + annotatedDirective.annotation, + buildStep, + ); + await for (var value in normalizeGeneratorOutput(generatedValue)) { + assert(value.length == value.trim().length); + values.add(value); + } + } + for (var annotatedElement in library.annotatedWith( typeChecker, throwOnUnresolved: throwOnUnresolved, @@ -123,4 +138,27 @@ abstract class GeneratorForAnnotation extends Generator { ConstantReader annotation, BuildStep buildStep, ) {} + + /// Implement to return source code to generate for [directive]. + /// + /// This method is invoked based on finding directives 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. + dynamic generateForAnnotatedDirective( + ElementDirective directive, + ConstantReader annotation, + BuildStep buildStep, + ) {} } diff --git a/source_gen/lib/src/library.dart b/source_gen/lib/src/library.dart index f2d03577..8e447851 100644 --- a/source_gen/lib/src/library.dart +++ b/source_gen/lib/src/library.dart @@ -13,6 +13,16 @@ import 'constants/reader.dart'; import 'type_checker.dart'; import 'utils.dart'; +/// Result of finding an [annotation] on [directive] through [LibraryReader]. +class AnnotatedDirective { + final ConstantReader annotation; + final ElementDirective directive; + + const AnnotatedDirective(this.annotation, this.directive); + + Metadata? get metadata2 => directive.metadata2; +} + /// Result of finding an [annotation] on [element] through [LibraryReader]. class AnnotatedElement { final ConstantReader annotation; @@ -87,6 +97,30 @@ class LibraryReader { } } + /// All of the directives in this library annotated with [checker]. + Iterable libraryDirectivesAnnotatedWith( + TypeChecker checker, { + bool throwOnUnresolved = true, + }) sync* { + final firstFragment = element2.firstFragment; + final directives = [ + ...firstFragment.libraryImports2, + ...firstFragment.libraryExports2, + ...firstFragment.partIncludes, + ]; + + for (final directive in directives) { + final annotation = checker.firstAnnotationOf2( + directive, + throwOnUnresolved: throwOnUnresolved, + ); + + if (annotation != null) { + yield AnnotatedDirective(ConstantReader(annotation), directive); + } + } + } + /// All of the declarations in this library annotated with exactly [checker]. Iterable annotatedWithExact( TypeChecker checker, { diff --git a/source_gen/lib/src/type_checker.dart b/source_gen/lib/src/type_checker.dart index b504d1c6..eda074ed 100644 --- a/source_gen/lib/src/type_checker.dart +++ b/source_gen/lib/src/type_checker.dart @@ -84,7 +84,7 @@ abstract class TypeChecker { /// /// Throws on unresolved annotations unless [throwOnUnresolved] is `false`. DartObject? firstAnnotationOf2( - Element2 element, { + Object element, { bool throwOnUnresolved = true, }) { if (element case final Annotatable annotatable) { @@ -188,13 +188,13 @@ abstract class TypeChecker { } DartObject? _computeConstantValue2( - Element2 element, + Object element, ElementAnnotation annotation, int annotationIndex, { bool throwOnUnresolved = true, }) { final result = annotation.computeConstantValue(); - if (result == null && throwOnUnresolved) { + if (result == null && throwOnUnresolved && element is Element2) { throw UnresolvedAnnotationException._from(element, annotationIndex); } return result; @@ -219,7 +219,7 @@ abstract class TypeChecker { /// Throws [UnresolvedAnnotationException] on unresolved annotations unless /// [throwOnUnresolved] is explicitly set to `false` (default is `true`). Iterable annotationsOf2( - Element2 element, { + Object element, { bool throwOnUnresolved = true, }) => _annotationsWhere2( @@ -246,7 +246,7 @@ abstract class TypeChecker { } Iterable _annotationsWhere2( - Element2 element, + Object element, bool Function(DartType) predicate, { bool throwOnUnresolved = true, }) sync* { diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index c24723e5..b2bfde5b 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -29,7 +29,8 @@ dev_dependencies: test: ^1.16.0 dependency_overrides: - analyzer: ^7.1.0 + analyzer: + path: /Users/scheglov/Source/Dart/sdk.git/sdk/pkg/analyzer build: git: url: https://github.com/dart-lang/build.git diff --git a/source_gen/test/generator_for_annotation_test.dart b/source_gen/test/generator_for_annotation_test.dart index 5bf4f137..1245f7ea 100644 --- a/source_gen/test/generator_for_annotation_test.dart +++ b/source_gen/test/generator_for_annotation_test.dart @@ -9,6 +9,7 @@ library; import 'package:analyzer/dart/analysis/utilities.dart'; 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:build_test/build_test.dart'; import 'package:source_gen/source_gen.dart'; @@ -25,8 +26,10 @@ void main() { 'list with null, empty, and whitespace items': [null, '', '\n \t'], }.entries) { test(entry.key, () async { - final generator = - _StubGenerator('Value', (_) => entry.value); + final generator = _StubGenerator( + 'Value', + elementBehavior: (_) => entry.value, + ); final builder = LibraryBuilder(generator); await testBuilder(builder, _inputMap, outputs: {}); }); @@ -34,10 +37,13 @@ void main() { }); test('Supports and dedupes multiple return values', () async { - final generator = _StubGenerator('Repeating', (element) sync* { - yield '// There are deprecated values in this library!'; - yield '// ${element.name}'; - }); + final generator = _StubGenerator( + 'Repeating', + elementBehavior: (element) sync* { + yield '// There are deprecated values in this library!'; + yield '// ${element.name}'; + }, + ); final builder = LibraryBuilder(generator); await testBuilder( builder, @@ -65,13 +71,19 @@ $dartFormatWidth group('handles errors correctly', () { for (var entry in { - 'sync errors': _StubGenerator('Failing', (_) { - throw StateError('not supported!'); - }), - 'from iterable': _StubGenerator('FailingIterable', (_) sync* { - yield '// There are deprecated values in this library!'; - throw StateError('not supported!'); - }), + 'sync errors': _StubGenerator( + 'Failing', + elementBehavior: (_) { + throw StateError('not supported!'); + }, + ), + 'from iterable': _StubGenerator( + 'FailingIterable', + elementBehavior: (_) sync* { + yield '// There are deprecated values in this library!'; + throw StateError('not supported!'); + }, + ), }.entries) { test(entry.key, () async { final builder = LibraryBuilder(entry.value); @@ -92,8 +104,12 @@ $dartFormatWidth test('Does not resolve the library if there are no top level annotations', () async { - final builder = - LibraryBuilder(_StubGenerator('Deprecated', (_) => null)); + final builder = LibraryBuilder( + _StubGenerator( + 'Deprecated', + elementBehavior: (_) => null, + ), + ); final input = AssetId('a', 'lib/a.dart'); final assets = {input: 'main() {}'}; @@ -116,7 +132,7 @@ $dartFormatWidth final builder = LibraryBuilder( _StubGenerator( 'Deprecated', - (element) => '// ${element.displayName}', + elementBehavior: (element) => '// ${element.displayName}', ), ); await testBuilder( @@ -142,12 +158,54 @@ $dartFormatWidth ); }); + test('applies to annotated directives', () async { + final builder = LibraryBuilder( + _StubGenerator( + 'Deprecated', + directiveBehavior: (element) => '// ${element.runtimeType}', + elementBehavior: (element) => '// ${element.runtimeType}', + ), + ); + await testBuilder( + builder, + { + 'a|lib/imported.dart': '', + 'a|lib/part.dart': 'part of \'file.dart\';', + 'a|lib/file.dart': ''' + library; + @deprecated + import 'imported.dart'; + @deprecated + export 'imported.dart'; + @deprecated + part 'part.dart'; + ''', + }, + outputs: { + 'a|lib/file.g.dart': ''' +$dartFormatWidth +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ************************************************************************** +// Generator: Deprecated +// ************************************************************************** + +// LibraryImportElementImpl + +// LibraryExportElementImpl + +// PartElementImpl +''', + }, + ); + }); + group('Unresolved annotations', () { test('cause an error by default', () async { final builder = LibraryBuilder( _StubGenerator( 'Deprecated', - (element) => '// ${element.displayName}', + elementBehavior: (element) => '// ${element.displayName}', ), ); expect( @@ -169,7 +227,7 @@ $dartFormatWidth final builder = LibraryBuilder( _StubGenerator( 'Deprecated', - (element) => '// ${element.displayName}', + elementBehavior: (element) => '// ${element.displayName}', throwOnUnresolved: false, ), ); @@ -192,9 +250,23 @@ $dartFormatWidth class _StubGenerator extends GeneratorForAnnotation { final String _name; - final Object? Function(Element) _behavior; + final Object? Function(ElementDirective) directiveBehavior; + final Object? Function(Element) elementBehavior; + + const _StubGenerator( + this._name, { + this.directiveBehavior = _returnNull, + required this.elementBehavior, + super.throwOnUnresolved, + }); - const _StubGenerator(this._name, this._behavior, {super.throwOnUnresolved}); + @override + Object? generateForAnnotatedDirective( + ElementDirective directive, + ConstantReader annotation, + BuildStep buildStep, + ) => + directiveBehavior(directive); @override Object? generateForAnnotatedElement( @@ -202,10 +274,12 @@ class _StubGenerator extends GeneratorForAnnotation { ConstantReader annotation, BuildStep buildStep, ) => - _behavior(element); + elementBehavior(element); @override String toString() => _name; + + static Null _returnNull(Object _) => null; } const _inputMap = { From 508c6c65a715606dbc0781ab08276cffa62aac49 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 27 Jan 2025 07:41:05 -0800 Subject: [PATCH 05/13] tweak --- source_gen/CHANGELOG.md | 4 +++- source_gen/pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index f299d63a..e36da4f3 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -1,5 +1,7 @@ ## 2.0.0 +- **DO NOT PUBLISH**: Only land into `analyzer-element2` branch. + When all clients migrate, replace all APIs. - **Breaking Change**: Change `formatOutput` function to accept a language version parameter. - **Formatting Change**: Generated code will no longer apply any fixes by @@ -8,7 +10,7 @@ - Document deduplication behavior for the output of `GeneratorForAnnotation.generateForAnnotatedElement`. - Support all the glob quotes. -- Require `analyzer: '>=6.9.0 <8.0.0'` +- Require `analyzer: '>=7.2.0 <8.0.0'` - Support the latest `package:dart_style` - `LibraryBuilder`, `PartBuilder`, and `SharedPartBuilder` now take an optional `writeDescriptions` boolean. When set to `false`, headers and generator diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index b2bfde5b..c4354d47 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -10,7 +10,7 @@ environment: sdk: ^3.6.0 dependencies: - analyzer: '>=6.9.0 <8.0.0' + analyzer: '>=7.2.0 <8.0.0' async: ^2.5.0 build: ^2.1.0 dart_style: '>=2.3.7 <4.0.0' From 65e26f4a85d2cc28ae58cc54ec5cebb3229816cb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Feb 2025 14:37:03 +0000 Subject: [PATCH 06/13] Bump actions/stale from 9.0.0 to 9.1.0 in the github-actions group (#741) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 1 update: [actions/stale](https://github.com/actions/stale). Updates `actions/stale` from 9.0.0 to 9.1.0
Release notes

Sourced from actions/stale's releases.

v9.1.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/stale/compare/v9...v9.1.0

Commits
  • 5bef64f build(deps): bump @​actions/cache from 3.2.2 to 4.0.0 (#1194)
  • fa77dfd build(deps-dev): bump @​types/jest from 29.5.11 to 29.5.14 (#1193)
  • f04443d build(deps): bump @​actions/core from 1.10.1 to 1.11.1 (#1191)
  • 5c715b0 build(deps-dev): bump ts-jest from 29.1.1 to 29.2.5 (#1175)
  • f691222 build(deps): bump actions/publish-action from 0.2.2 to 0.3.0 (#1147)
  • df990c2 build(deps): bump actions/checkout from 3 to 4 (#1091)
  • 6e472ce Merge pull request #1179 from actions/Jcambass-patch-1
  • d10ba64 Merge pull request #1150 from actions/dependabot/npm_and_yarn/undici-5.28.4
  • bbf3da5 resolve check failures
  • 6a2e61d Add workflow file for publishing releases to immutable action package
  • Additional commits viewable in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/stale&package-manager=github_actions&previous-version=9.0.0&new-version=9.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- .github/workflows/no-response.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index ab1ac498..1f33ec62 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.repository_owner == 'dart-lang' }} steps: - - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e + - uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 with: # Don't automatically mark inactive issues+PRs as stale. days-before-stale: -1 From 34f9264a926453c36013c79834121763c0145044 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Mar 2025 14:44:22 +0000 Subject: [PATCH 07/13] Bump the github-actions group with 2 updates (#742) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 2 updates: [actions/cache](https://github.com/actions/cache) and [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart). Updates `actions/cache` from 4.2.0 to 4.2.2
Release notes

Sourced from actions/cache's releases.

v4.2.2

What's Changed

[!IMPORTANT] As a reminder, there were important backend changes to release v4.2.0, see those release notes and the announcement for more details.

Full Changelog: https://github.com/actions/cache/compare/v4.2.1...v4.2.2

v4.2.1

What's Changed

[!IMPORTANT] As a reminder, there were important backend changes to release v4.2.0, see those release notes and the announcement for more details.

New Contributors

Full Changelog: https://github.com/actions/cache/compare/v4.2.0...v4.2.1

Changelog

Sourced from actions/cache's changelog.

Releases

4.2.2

  • Bump @actions/cache to v4.0.2

4.2.1

  • Bump @actions/cache to v4.0.1

4.2.0

TLDR; The cache backend service has been rewritten from the ground up for improved performance and reliability. actions/cache now integrates with the new cache service (v2) APIs.

The new service will gradually roll out as of February 1st, 2025. The legacy service will also be sunset on the same date. Changes in these release are fully backward compatible.

We are deprecating some versions of this action. We recommend upgrading to version v4 or v3 as soon as possible before February 1st, 2025. (Upgrade instructions below).

If you are using pinned SHAs, please use the SHAs of versions v4.2.0 or v3.4.0

If you do not upgrade, all workflow runs using any of the deprecated actions/cache will fail.

Upgrading to the recommended versions will not break your workflows.

4.1.2

  • Add GitHub Enterprise Cloud instances hostname filters to inform API endpoint choices - #1474
  • Security fix: Bump braces from 3.0.2 to 3.0.3 - #1475

4.1.1

  • Restore original behavior of cache-hit output - #1467

4.1.0

  • Ensure cache-hit output is set when a cache is missed - #1404
  • Deprecate save-always input - #1452

4.0.2

  • Fixed restore fail-on-cache-miss not working.

4.0.1

  • Updated isGhes check

4.0.0

  • Updated minimum runner version support from node 12 -> node 20

... (truncated)

Commits
  • d4323d4 Merge pull request #1560 from actions/robherley/v4.2.2
  • da26677 bump @​actions/cache to v4.0.2, prep for v4.2.2 release
  • 7921ae2 Merge pull request #1557 from actions/robherley/ia-workflow-released
  • 3937731 Update publish-immutable-actions.yml
  • 0c907a7 Merge pull request #1554 from actions/robherley/v4.2.1
  • 710893c bump @​actions/cache to v4.0.1
  • 9fa7e61 Update force deletion docs due a recent deprecation (#1500)
  • 36f1e14 docs: Make the "always save prime numbers" example more clear (#1525)
  • 53aa38c Correct GitHub Spelling in caching-strategies.md (#1526)
  • See full diff in compare view

Updates `dart-lang/setup-dart` from 1.7.0 to 1.7.1
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.7.1

  • Roll undici dependency to address CVE-2025-22150.
  • Update to the latest npm dependencies.
  • Recompile the action using the new Dart / JavaScript interop.
Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.7.1

  • Roll undici dependency to address CVE-2025-22150.
  • Update to the latest npm dependencies.
  • Recompile the action using the new Dart / JavaScript interop.

v1.7.0

v1.6.5

  • Fix zip path handling on Windows 11 (#118[])

#118: dart-lang/setup-dart#118

v1.6.4

  • Rebuild JS code.

v1.6.3

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

... (truncated)

Commits

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- .github/workflows/dart.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ba55608a..d152bb05 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable" @@ -29,7 +29,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: stable - id: checkout @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen;commands:analyze_1" @@ -54,7 +54,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -74,7 +74,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:_test_annotations-example-example_usage-source_gen;commands:format-analyze_0" @@ -84,7 +84,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -147,7 +147,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:example_usage;commands:test_0" @@ -157,7 +157,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -181,7 +181,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen;commands:test_1" @@ -191,7 +191,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -215,7 +215,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:example_usage;commands:test_0" @@ -225,7 +225,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -249,7 +249,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf with: path: "~/.pub-cache/hosted" key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:source_gen;commands:test_1" @@ -259,7 +259,7 @@ jobs: os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout @@ -283,7 +283,7 @@ jobs: runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: "3.6.0" - id: checkout @@ -307,7 +307,7 @@ jobs: runs-on: windows-latest steps: - name: Setup Dart SDK - uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c with: sdk: dev - id: checkout From f8cac87d8dea9aa53c06c75a6a472ed6010da2b5 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 11 Mar 2025 17:15:37 -0700 Subject: [PATCH 08/13] tweak --- source_gen/CHANGELOG.md | 2 ++ source_gen/lib/src/generator_for_annotation.dart | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index e36da4f3..e9a2b437 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -12,6 +12,8 @@ - Support all the glob quotes. - Require `analyzer: '>=7.2.0 <8.0.0'` - Support the latest `package:dart_style` +- Add `generateForAnnotatedDirective` in addition to `generateForAnnotatedElement2` + because in the analyzer element model V2 directives are not elements. - `LibraryBuilder`, `PartBuilder`, and `SharedPartBuilder` now take an optional `writeDescriptions` boolean. When set to `false`, headers and generator descriptions for the files will not be included in the builder output. diff --git a/source_gen/lib/src/generator_for_annotation.dart b/source_gen/lib/src/generator_for_annotation.dart index f2a94092..f8300514 100644 --- a/source_gen/lib/src/generator_for_annotation.dart +++ b/source_gen/lib/src/generator_for_annotation.dart @@ -139,7 +139,10 @@ abstract class GeneratorForAnnotation extends Generator { BuildStep buildStep, ) {} - /// Implement to return source code to generate for [directive]. + /// Implement to return source code to generate for [directive]: + /// - [LibraryImport] + /// - [LibraryExport] + /// - [PartInclude] /// /// This method is invoked based on finding directives annotated with an /// instance of [T]. The [annotation] is provided as a [ConstantReader]. From 8e9138f669a8cf26db3f5ddd4a9f0042f2e97713 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 12 Mar 2025 10:48:44 -0700 Subject: [PATCH 09/13] tweak --- source_gen/CHANGELOG.md | 5 +++-- source_gen/test/generator_for_annotation_test.dart | 11 +++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index e9a2b437..44514898 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -12,8 +12,9 @@ - Support all the glob quotes. - Require `analyzer: '>=7.2.0 <8.0.0'` - Support the latest `package:dart_style` -- Add `generateForAnnotatedDirective` in addition to `generateForAnnotatedElement2` - because in the analyzer element model V2 directives are not elements. +- Add `generateForAnnotatedDirective`, which now must be used instead of + `generateForAnnotatedElement` in order to support annotations on directives + (imports, exports, parts). - `LibraryBuilder`, `PartBuilder`, and `SharedPartBuilder` now take an optional `writeDescriptions` boolean. When set to `false`, headers and generator descriptions for the files will not be included in the builder output. diff --git a/source_gen/test/generator_for_annotation_test.dart b/source_gen/test/generator_for_annotation_test.dart index 1245f7ea..c140235d 100644 --- a/source_gen/test/generator_for_annotation_test.dart +++ b/source_gen/test/generator_for_annotation_test.dart @@ -8,7 +8,6 @@ library; import 'package:analyzer/dart/analysis/utilities.dart'; 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:build_test/build_test.dart'; @@ -41,7 +40,7 @@ void main() { 'Repeating', elementBehavior: (element) sync* { yield '// There are deprecated values in this library!'; - yield '// ${element.name}'; + yield '// ${element.name3}'; }, ); final builder = LibraryBuilder(generator); @@ -251,7 +250,7 @@ $dartFormatWidth class _StubGenerator extends GeneratorForAnnotation { final String _name; final Object? Function(ElementDirective) directiveBehavior; - final Object? Function(Element) elementBehavior; + final Object? Function(Element2) elementBehavior; const _StubGenerator( this._name, { @@ -269,8 +268,8 @@ class _StubGenerator extends GeneratorForAnnotation { directiveBehavior(directive); @override - Object? generateForAnnotatedElement( - Element element, + Object? generateForAnnotatedElement2( + Element2 element, ConstantReader annotation, BuildStep buildStep, ) => @@ -318,7 +317,7 @@ class _TestingResolver implements ReleasableResolver { } @override - Future libraryFor( + Future libraryFor2( AssetId assetId, { bool allowSyntaxErrors = false, }) async { From 98edcac2ff59788afd3580b2b4c6a896a9074f94 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 12 Mar 2025 12:40:28 -0700 Subject: [PATCH 10/13] Use git dependency override for analyzer. --- source_gen/pubspec.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index c4354d47..182e3787 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -29,8 +29,14 @@ dev_dependencies: test: ^1.16.0 dependency_overrides: + _fe_analyzer_shared: + git: + url: https://github.com/dart-lang/sdk.git + path: pkg/_fe_analyzer_shared analyzer: - path: /Users/scheglov/Source/Dart/sdk.git/sdk/pkg/analyzer + git: + url: https://github.com/dart-lang/sdk.git + path: pkg/analyzer build: git: url: https://github.com/dart-lang/build.git From 589ccf5cab229d8aa1c946ba69acae9c29dbcd97 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 13 Mar 2025 10:31:44 -0700 Subject: [PATCH 11/13] Disable analyzer_use_new_elements for now. --- analysis_options.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index e9ca8840..edbe4ba2 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -8,7 +8,6 @@ analyzer: linter: rules: - - analyzer_use_new_elements - avoid_bool_literals_in_conditional_expressions - avoid_classes_with_only_static_members - avoid_private_typedef_functions From 39075e994319692d6f9abe3a9e3153cbad91d3c3 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Sat, 15 Mar 2025 09:22:23 -0700 Subject: [PATCH 12/13] deprecations --- source_gen/lib/src/constants/reader.dart | 4 +- source_gen/lib/src/constants/utils.dart | 25 ++++++++++++ source_gen/lib/src/span_for_element.dart | 6 +-- source_gen/lib/src/type_checker.dart | 35 ++++++++++++---- source_gen/lib/src/utils.dart | 19 ++++++--- source_gen/test/constants/utils_test.dart | 3 ++ source_gen/test/constants_test.dart | 2 +- .../test/external_only_type_checker_test.dart | 4 +- source_gen/test/type_checker_test.dart | 40 +++++++++---------- 9 files changed, 98 insertions(+), 40 deletions(-) diff --git a/source_gen/lib/src/constants/reader.dart b/source_gen/lib/src/constants/reader.dart index bf53938c..dba2d052 100644 --- a/source_gen/lib/src/constants/reader.dart +++ b/source_gen/lib/src/constants/reader.dart @@ -3,7 +3,7 @@ // 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'; import 'package:analyzer/dart/element/type.dart'; import '../type_checker.dart'; @@ -268,7 +268,7 @@ class _DartObjectConstant extends ConstantReader { ConstantReader read(String field) { final reader = peek(field); if (reader == null) { - assertHasField(objectValue.type!.element as InterfaceElement, field); + assertHasField2(objectValue.type!.element3 as InterfaceElement2, field); return const _NullConstant(); } return reader; diff --git a/source_gen/lib/src/constants/utils.dart b/source_gen/lib/src/constants/utils.dart index e1846fe4..669664f9 100644 --- a/source_gen/lib/src/constants/utils.dart +++ b/source_gen/lib/src/constants/utils.dart @@ -4,10 +4,12 @@ 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) { @@ -28,6 +30,29 @@ void assertHasField(InterfaceElement root, String name) { ); } +/// Throws a [FormatException] if [root] does not have a given field [name]. +/// +/// Super types [InterfaceElement.supertype] are also checked before throwing. +void assertHasField2(InterfaceElement2 root, String name) { + InterfaceElement2? element = root; + while (element != null) { + final field = element.getField2(name); + if (field != null) { + return; + } + element = element.supertype?.element3; + } + final allFields = { + ...root.fields2, + for (var t in root.allSupertypes) ...t.element3.fields2, + }; + + throw FormatException( + 'Class ${root.name3} does not have field "$name".', + 'Fields: \n - ${allFields.map((e) => e.name3).join('\n - ')}', + ); +} + /// 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/span_for_element.dart b/source_gen/lib/src/span_for_element.dart index 6be36f2e..53246d6a 100644 --- a/source_gen/lib/src/span_for_element.dart +++ b/source_gen/lib/src/span_for_element.dart @@ -97,9 +97,9 @@ SourceSpan spanForElement2(Element2 element, [SourceFile? file]) { /// Returns a source span that spans the location where [node] is written. SourceSpan spanForNode(AstNode node) { final unit = node.thisOrAncestorOfType()!; - final element = unit.declaredElement!; - final contents = element.source.contents.data; - final url = assetToPackageUrl(element.source.uri); + final unitFragment = unit.declaredFragment!; + final contents = unitFragment.source.contents.data; + final url = assetToPackageUrl(unitFragment.source.uri); final file = SourceFile.fromString(contents, url: url); return file.span(node.offset, node.offset + node.length); } diff --git a/source_gen/lib/src/type_checker.dart b/source_gen/lib/src/type_checker.dart index eda074ed..5f5d4083 100644 --- a/source_gen/lib/src/type_checker.dart +++ b/source_gen/lib/src/type_checker.dart @@ -307,8 +307,8 @@ abstract class TypeChecker { /// Returns `true` if [staticType] can be assigned to this type. bool isAssignableFromType(DartType staticType) { - final element = staticType.element; - return element != null && isAssignableFrom(element); + final element = staticType.element3; + return element != null && isAssignableFrom2(element); } /// Returns `true` if representing the exact same class as [element]. @@ -322,9 +322,9 @@ abstract class TypeChecker { /// This will always return false for types without a backingclass such as /// `void` or function types. bool isExactlyType(DartType staticType) { - final element = staticType.element; + final element = staticType.element3; if (element != null) { - return isExactly(element); + return isExactly2(element); } else { return false; } @@ -350,11 +350,31 @@ 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]. + 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; + } + /// 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) => isSuperOf(staticType.element!); + bool isSuperTypeOf(DartType staticType) => isSuperOf2(staticType.element3!); } // Checks a static type against another static type; @@ -363,6 +383,7 @@ class _LibraryTypeChecker extends TypeChecker { const _LibraryTypeChecker(this._type) : super._(); + @Deprecated('Use isExactly2() instead') @override bool isExactly(Element element) => element is InterfaceElement && element == _type.element; @@ -372,7 +393,7 @@ class _LibraryTypeChecker extends TypeChecker { element is InterfaceElement2 && element == _type.element3; @override - String toString() => urlOfElement(_type.element!); + String toString() => urlOfElement2(_type.element3!); } // Checks a runtime type against a static type. @@ -473,7 +494,7 @@ class UnresolvedAnnotationException implements Exception { annotatedElement.session!.getParsedLibraryByElement2( annotatedElement.library2!, ) as ParsedLibraryResult; - final declaration = parsedLibrary.getElementDeclaration2( + final declaration = parsedLibrary.getFragmentDeclaration( annotatedElement.firstFragment, ); if (declaration == null) { diff --git a/source_gen/lib/src/utils.dart b/source_gen/lib/src/utils.dart index 0f258e60..c01a8616 100644 --- a/source_gen/lib/src/utils.dart +++ b/source_gen/lib/src/utils.dart @@ -6,6 +6,7 @@ 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'; import 'package:path/path.dart' as p; @@ -20,20 +21,20 @@ import 'package:yaml/yaml.dart'; /// typedef VoidFunc = void Function(); /// ``` /// -/// This function will return `'VoidFunc'`, unlike [DartType.element]`.name`. +/// This function will return `'VoidFunc'`, unlike [DartType.element3]`.name3`. String typeNameOf(DartType type) { - final aliasElement = type.alias?.element; + final aliasElement = type.alias?.element2; if (aliasElement != null) { - return aliasElement.name; + return aliasElement.name3!; } if (type is DynamicType) { return 'dynamic'; } if (type is InterfaceType) { - return type.element.name; + return type.element3.name3!; } if (type is TypeParameterType) { - return type.element.name; + return type.element3.name3!; } throw UnimplementedError('(${type.runtimeType}) $type'); } @@ -64,6 +65,14 @@ String urlOfElement(Element element) => element.kind == ElementKind.DYNAMIC .replace(fragment: element.name) .toString(); +/// Returns a URL representing [element]. +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 24220a1b..d1d96e81 100644 --- a/source_gen/test/constants/utils_test.dart +++ b/source_gen/test/constants/utils_test.dart @@ -35,16 +35,19 @@ void main() { test('should not throw when a class contains a field', () { final $A = testLib.getClass('A')!; + // ignore: deprecated_member_use_from_same_package expect(() => assertHasField($A, 'a'), returnsNormally); }); test('should not throw when a super class contains a field', () { final $B = testLib.getClass('B')!; + // ignore: deprecated_member_use_from_same_package expect(() => assertHasField($B, 'a'), returnsNormally); }); test('should throw when a class does not contain a field', () { final $C = testLib.getClass('C')!; + // ignore: deprecated_member_use_from_same_package expect(() => assertHasField($C, 'a'), throwsFormatException); }); }); diff --git a/source_gen/test/constants_test.dart b/source_gen/test/constants_test.dart index fe97e07c..2e5dbe5b 100644 --- a/source_gen/test/constants_test.dart +++ b/source_gen/test/constants_test.dart @@ -155,7 +155,7 @@ void main() { test('should read a Type', () { expect(constants[11].isType, isTrue); - expect(constants[11].typeValue.element!.name, 'DateTime'); + expect(constants[11].typeValue.element3!.name3, 'DateTime'); expect(constants[11].isLiteral, isFalse); expect(() => constants[11].literalValue, throwsFormatException); }); diff --git a/source_gen/test/external_only_type_checker_test.dart b/source_gen/test/external_only_type_checker_test.dart index 76ca1cb3..ee14cd76 100644 --- a/source_gen/test/external_only_type_checker_test.dart +++ b/source_gen/test/external_only_type_checker_test.dart @@ -53,7 +53,7 @@ void main() { expect( checkNonPublic().isExactlyType(staticNonPublic), isTrue, - reason: '${checkNonPublic()} != ${staticNonPublic.element.name}', + reason: '${checkNonPublic()} != ${staticNonPublic.element3.name3}', ); }); @@ -62,7 +62,7 @@ void main() { checkNonPublic().isAssignableFromType(staticNonPublic), isTrue, reason: '${checkNonPublic()} is not assignable from ' - '${staticNonPublic.element.name}', + '${staticNonPublic.element3.name3}', ); }); }); diff --git a/source_gen/test/type_checker_test.dart b/source_gen/test/type_checker_test.dart index c6901030..f86deca1 100644 --- a/source_gen/test/type_checker_test.dart +++ b/source_gen/test/type_checker_test.dart @@ -201,7 +201,7 @@ void main() { () { test('should equal MapMixin class', () { expect(checkMapMixin().isExactlyType(staticMapMixin), isTrue); - expect(checkMapMixin().isExactly(staticMapMixin.element), isTrue); + expect(checkMapMixin().isExactly2(staticMapMixin.element3), isTrue); }); }, onPlatform: const { @@ -214,7 +214,7 @@ void main() { expect( checkMap().isExactlyType(staticMap), isTrue, - reason: '${checkMap()} != ${staticMap.element.name}', + reason: '${checkMap()} != ${staticMap.element3.name3}', ); }); @@ -246,7 +246,7 @@ void main() { test('should be assignable from Map', () { // Using Uri.queryParameters to get a Map final stringStringMapType = - staticUri.getGetter('queryParameters')!.returnType; + staticUri.getGetter2('queryParameters')!.returnType; expect(checkMap().isAssignableFromType(stringStringMapType), isTrue); expect(checkMap().isExactlyType(stringStringMapType), isTrue); @@ -276,7 +276,7 @@ void main() { expect( checkGenerator().isExactlyType(staticGenerator), isTrue, - reason: '${checkGenerator()} != ${staticGenerator.element.name}', + reason: '${checkGenerator()} != ${staticGenerator.element3.name3}', ); }); @@ -285,7 +285,7 @@ void main() { checkGenerator().isSuperTypeOf(staticGenerator), isFalse, reason: '${checkGenerator()} is super of ' - '${staticGenerator.element.name}', + '${staticGenerator.element3.name3}', ); }); @@ -294,7 +294,7 @@ void main() { checkGenerator().isSuperTypeOf(staticGeneratorForAnnotation), isTrue, reason: '${checkGenerator()} is not super of ' - '${staticGeneratorForAnnotation.element.name}', + '${staticGeneratorForAnnotation.element3.name3}', ); }); @@ -303,7 +303,7 @@ void main() { checkGenerator().isAssignableFromType(staticGeneratorForAnnotation), isTrue, reason: '${checkGenerator()} is not assignable from ' - '${staticGeneratorForAnnotation.element.name}', + '${staticGeneratorForAnnotation.element3.name3}', ); }); }); @@ -465,34 +465,34 @@ void main() { test('of a single @A', () { expect($A.hasAnnotationOf($ExampleOfA), isTrue); final aAnnotation = $A.firstAnnotationOf($ExampleOfA)!; - expect(aAnnotation.type!.element!.name, 'A'); + expect(aAnnotation.type!.element3!.name3, 'A'); expect($B.annotationsOf($ExampleOfA), isEmpty); expect($C.annotationsOf($ExampleOfA), isEmpty); }); test('of a multiple @A', () { final aAnnotations = $A.annotationsOf($ExampleOfMultiA); - expect(aAnnotations.map((a) => a.type!.element!.name), ['A', 'A']); + expect(aAnnotations.map((a) => a.type!.element3!.name3), ['A', 'A']); expect($B.annotationsOf($ExampleOfA), isEmpty); expect($C.annotationsOf($ExampleOfA), isEmpty); }); test('of a single @A + single @B', () { final aAnnotations = $A.annotationsOf($ExampleOfAPlusB); - expect(aAnnotations.map((a) => a.type!.element!.name), ['A']); + expect(aAnnotations.map((a) => a.type!.element3!.name3), ['A']); final bAnnotations = $B.annotationsOf($ExampleOfAPlusB); - expect(bAnnotations.map((a) => a.type!.element!.name), ['B']); + expect(bAnnotations.map((a) => a.type!.element3!.name3), ['B']); expect($C.annotationsOf($ExampleOfAPlusB), isEmpty); }); test('of a single @B + single @C', () { final cAnnotations = $C.annotationsOf($ExampleOfBPlusC); - expect(cAnnotations.map((a) => a.type!.element!.name), ['C']); + expect(cAnnotations.map((a) => a.type!.element3!.name3), ['C']); final bAnnotations = $B.annotationsOf($ExampleOfBPlusC); - expect(bAnnotations.map((a) => a.type!.element!.name), ['B', 'C']); + expect(bAnnotations.map((a) => a.type!.element3!.name3), ['B', 'C']); expect($B.hasAnnotationOfExact($ExampleOfBPlusC), isTrue); final bExact = $B.annotationsOfExact($ExampleOfBPlusC); - expect(bExact.map((a) => a.type!.element!.name), ['B']); + expect(bExact.map((a) => a.type!.element3!.name3), ['B']); }); }); @@ -573,28 +573,28 @@ void main() { $A .firstAnnotationOf($ExampleOfA, throwOnUnresolved: false)! .type! - .element! - .name, + .element3! + .name3, 'A', ); expect( $A .annotationsOf($ExampleOfA, throwOnUnresolved: false) - .map((a) => a.type!.element!.name), + .map((a) => a.type!.element3!.name3), ['A'], ); expect( $A .firstAnnotationOfExact($ExampleOfA, throwOnUnresolved: false)! .type! - .element! - .name, + .element3! + .name3, 'A', ); expect( $A .annotationsOfExact($ExampleOfA, throwOnUnresolved: false) - .map((a) => a.type!.element!.name), + .map((a) => a.type!.element3!.name3), ['A'], ); }); From 51348990433668c3c8b135b1c3cc387205097028 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Sat, 15 Mar 2025 09:31:28 -0700 Subject: [PATCH 13/13] lints --- example_usage/test/ensure_build_test.dart | 2 +- source_gen/lib/src/library.dart | 10 ++++++++++ source_gen/lib/src/output_helpers.dart | 1 + source_gen/test/builder_test.dart | 4 ++-- .../test/external_only_type_checker_test.dart | 2 +- source_gen/test/library/find_type_test.dart | 14 +++++++------- source_gen/test/type_checker_test.dart | 17 +++++++++-------- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/example_usage/test/ensure_build_test.dart b/example_usage/test/ensure_build_test.dart index c324e985..fc659599 100644 --- a/example_usage/test/ensure_build_test.dart +++ b/example_usage/test/ensure_build_test.dart @@ -13,6 +13,6 @@ import 'package:test/test.dart'; void main() { test( 'ensure_build', - () => expectBuildClean(packageRelativeDirectory: 'example_usage'), + () async => expectBuildClean(packageRelativeDirectory: 'example_usage'), ); } diff --git a/source_gen/lib/src/library.dart b/source_gen/lib/src/library.dart index 8e447851..33a8958f 100644 --- a/source_gen/lib/src/library.dart +++ b/source_gen/lib/src/library.dart @@ -141,11 +141,21 @@ class LibraryReader { /// /// Unlike [LibraryElement.getClass], 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; } + /// Returns a top-level [ClassElement] publicly visible in by [name]. + /// + /// Unlike [LibraryElement.getClass], this also correctly traverses + /// identifiers that are accessible via one or more `export` directives. + ClassElement2? findType2(String name) { + final type = element.exportNamespace.get2(name); + return type is ClassElement2 ? type : null; + } + /// Returns a [Uri] from the current library to the target [asset]. /// /// This is a typed convenience function for using [pathToUrl], and the same diff --git a/source_gen/lib/src/output_helpers.dart b/source_gen/lib/src/output_helpers.dart index 2e028b40..082a65da 100644 --- a/source_gen/lib/src/output_helpers.dart +++ b/source_gen/lib/src/output_helpers.dart @@ -11,6 +11,7 @@ Stream normalizeGeneratorOutput(Object? value) { if (value == null) { return const Stream.empty(); } else if (value is Future) { + // ignore:discarded_futures return StreamCompleter.fromFuture(value.then(normalizeGeneratorOutput)); } else if (value is String) { value = [value]; diff --git a/source_gen/test/builder_test.dart b/source_gen/test/builder_test.dart index 87261476..70ac3dc9 100644 --- a/source_gen/test/builder_test.dart +++ b/source_gen/test/builder_test.dart @@ -174,7 +174,7 @@ $dartFormatWidth test( 'Simple Generator test for library', - () => _generateTest( + () async => _generateTest( const CommentGenerator(forClasses: false, forLibrary: true), _testGenPartContentForLibrary, ), @@ -182,7 +182,7 @@ $dartFormatWidth test( 'Simple Generator test for classes and library', - () => _generateTest( + () async => _generateTest( const CommentGenerator(forLibrary: true), _testGenPartContentForClassesAndLibrary, ), diff --git a/source_gen/test/external_only_type_checker_test.dart b/source_gen/test/external_only_type_checker_test.dart index ee14cd76..78a424cb 100644 --- a/source_gen/test/external_only_type_checker_test.dart +++ b/source_gen/test/external_only_type_checker_test.dart @@ -37,7 +37,7 @@ void main() { inputId: AssetId('source_gen', 'test/example.dart'), ); - staticNonPublic = thisTest.findType('NonPublic')!.instantiate( + staticNonPublic = thisTest.findType2('NonPublic')!.instantiate( typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none, ); diff --git a/source_gen/test/library/find_type_test.dart b/source_gen/test/library/find_type_test.dart index 354140e4..fcbc79cb 100644 --- a/source_gen/test/library/find_type_test.dart +++ b/source_gen/test/library/find_type_test.dart @@ -2,7 +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'; import 'package:build_test/build_test.dart'; import 'package:source_gen/source_gen.dart'; import 'package:test/test.dart'; @@ -47,24 +47,24 @@ void main() { }); test('should return a type not exported', () { - expect(library.findType('Example'), _isClassElement); + expect(library.findType2('Example'), _isClassElement); }); test('should return a type from a part', () { - expect(library.findType('PartClass'), _isClassElement); + expect(library.findType2('PartClass'), _isClassElement); }); test('should return a type exported from dart:', () { - expect(library.findType('LinkedHashMap'), _isClassElement); + expect(library.findType2('LinkedHashMap'), _isClassElement); }); test('should return a type exported from package:', () { - expect(library.findType('Generator'), _isClassElement); + expect(library.findType2('Generator'), _isClassElement); }); test('should not return a type imported', () { - expect(library.findType('Stream'), isNull); + expect(library.findType2('Stream'), isNull); }); } -const _isClassElement = TypeMatcher(); +const _isClassElement = TypeMatcher(); diff --git a/source_gen/test/type_checker_test.dart b/source_gen/test/type_checker_test.dart index f86deca1..82a3eb63 100644 --- a/source_gen/test/type_checker_test.dart +++ b/source_gen/test/type_checker_test.dart @@ -11,6 +11,7 @@ library; import 'dart:collection'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; @@ -91,28 +92,28 @@ void main() { ); staticEnumChecker = TypeChecker.fromStatic(staticEnum); staticEnumMixin = - (testSource.exportNamespace.get('MyEnumMixin')! as InterfaceElement) + (testSource.exportNamespace.get2('MyEnumMixin')! as InterfaceElement2) .instantiate( typeArguments: [], nullabilitySuffix: NullabilitySuffix.none, ); staticEnumMixinChecker = TypeChecker.fromStatic(staticEnumMixin); staticMapMixin = - (testSource.exportNamespace.get('MyMapMixin')! as InterfaceElement) + (testSource.exportNamespace.get2('MyMapMixin')! as InterfaceElement2) .instantiate( typeArguments: [], nullabilitySuffix: NullabilitySuffix.none, ); staticMapMixinChecker = TypeChecker.fromStatic(staticMapMixin); staticMyEnum = - (testSource.exportNamespace.get('MyEnum')! as InterfaceElement) + (testSource.exportNamespace.get2('MyEnum')! as InterfaceElement2) .instantiate( typeArguments: [], nullabilitySuffix: NullabilitySuffix.none, ); - staticMyEnumWithMixin = - (testSource.exportNamespace.get('MyEnumWithMixin')! as InterfaceElement) - .instantiate( + staticMyEnumWithMixin = (testSource.exportNamespace.get2('MyEnumWithMixin')! + as InterfaceElement2) + .instantiate( typeArguments: [], nullabilitySuffix: NullabilitySuffix.none, ); @@ -131,13 +132,13 @@ void main() { nullabilitySuffix: NullabilitySuffix.none, ); - staticGenerator = sourceGen.findType('Generator')!.instantiate( + staticGenerator = sourceGen.findType2('Generator')!.instantiate( typeArguments: [], nullabilitySuffix: NullabilitySuffix.none, ); staticGeneratorChecker = TypeChecker.fromStatic(staticGenerator); staticGeneratorForAnnotation = - sourceGen.findType('GeneratorForAnnotation')!.instantiate( + sourceGen.findType2('GeneratorForAnnotation')!.instantiate( typeArguments: [core.typeProvider.dynamicType], nullabilitySuffix: NullabilitySuffix.none, );