Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate use of analyzer's "element model" to Element2. #3492

Open
srawlins opened this issue Mar 6, 2025 · 3 comments
Open

Migrate use of analyzer's "element model" to Element2. #3492

srawlins opened this issue Mar 6, 2025 · 3 comments
Labels
blocked Work on this is blocked by external factors package-drift_dev Affects the drift_dev package

Comments

@srawlins
Copy link

srawlins commented Mar 6, 2025

The analyzer package's "element model," (everything declared in package:analyzer/dart/element/element.dart) is migrating to a new API, found at package:analyzer/dart/element/element2.dart. The "element 1" APIs are presently being deprecated.

Consumers of the old element model need to migrate to the new element model. A few notes:

  • In order to migrate, drift_dev needs to use at least analyzer version 7.3.0.
  • In order to migrate, drift_dev also needs to use a new version of source_gen, not yet released, which also makes its APIs available with Element2 types. Follow Release version with analyzer's Element2 APIs dart-lang/source_gen#743.
  • There is a lint rule available to help migrate, analyzer_use_new_elements. Turning it on in drift_dev reveals > 700 references to classes in the "element 1" model.
@simolus3
Copy link
Owner

simolus3 commented Mar 6, 2025

This looks like a fun one :D I'll try to prepare a branch using the new element model and a dependency override for source_gen (which should be good enough to roll into your clone).

@simolus3
Copy link
Owner

simolus3 commented Mar 6, 2025

@srawlins I gave this a go on the element2 branch, but I think it's too early for client packages to make the migration. I got the >700 usages down to around 50, but the remaining ones are tricky. In addition to source_gen, I also need versions of build that support the element 2 API to complete the migration.

I also need an element2-variant of TypeSystem.instantiateInterfaceToBounds that the analyzer doesn't seem to provide (or I couldn't find it).

Is drift_dev blocking anything internally for you here? Let me know if there's more I can do.

@simolus3 simolus3 added blocked Work on this is blocked by external factors package-drift_dev Affects the drift_dev package labels Mar 6, 2025
@srawlins
Copy link
Author

srawlins commented Mar 7, 2025

Sweeet, thanks @simolus3!! If you're interested, you could try the source_gen and build branches that support Element2:

CC @scheglov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Work on this is blocked by external factors package-drift_dev Affects the drift_dev package
Projects
None yet
Development

No branches or pull requests

2 participants