Skip to content

Conversation

scheglov
Copy link
Contributor

See https://docs.google.com/presentation/d/1Vxr-y5ljuo0Os78R4tKZg8cc0In984EQcLs06HOqS28/edit#slide=id.p for the new element model details. It is possible that you will not able access it, unless you work for Google.

@scheglov scheglov changed the base branch from master to analyzer-element2 December 16, 2024 21:58
@scheglov scheglov requested review from jakemac53 and kevmoo and removed request for kevmoo December 16, 2024 21:59
);
});

test('applies to annotated directives', () async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the story here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directives in the element model are no longer elements, so we cannot support annotations on them. Or at least the way it used to work. This so far did not cause any breakage in google3, but I have not yet migrated external packages, only a lot of internal generators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codegen for checks (not released) will rely on reading metadata from LibraryImportElement. Internal link: http://google3/third_party/dart/checks_codegen/lib/src/builder.dart;l=32-34;rcl=634834855

Is there an alternative way to read them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked in our chat.

dart_flutter_team_lints: ^3.1.0
term_glyph: ^1.2.0
test: ^1.16.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just published these! we can drop 'em

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are actually needed, they expose a different API to get at the new element models, but its only to help with the internal migration.

export 'src/generator_for_annotation.dart' show GeneratorForAnnotation;
export 'src/library.dart' show AnnotatedElement, LibraryReader;
export 'src/span_for_element.dart' show spanForElement;
export 'src/span_for_element.dart' show spanForElement, spanForElement2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a changelog update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will never be published, we will restore the name with different types.

///
/// Implementations should return `null` when no content is generated. Empty
/// or whitespace-only [String] instances are also ignored.
dynamic generateForAnnotatedElement2(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, so which version is going to be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both, but any specific generator will override only one.
So, both migrated and not-yet-migrated generators will work.

@scheglov scheglov merged commit 117ab26 into dart-lang:analyzer-element2 Dec 16, 2024
12 checks passed
@scheglov scheglov mentioned this pull request Jan 1, 2025
jakemac53 pushed a commit that referenced this pull request Mar 17, 2025
Continue #735

Note that it restores applies to annotated directives test, as discussed in the previous PR.
This functionality is indeed used, by package:checks generator.

The first version uses analyzer dependency override, because I want want you to look at the code before I publish analyzer .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants