-
Notifications
You must be signed in to change notification settings - Fork 7
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
Provide access to metadata #7
Comments
cc @davidmorgan |
Note, that until the declaration phase ends we cannot resolve metadata, because at any point a new declaration could be added, and so change the resolution. import 'package:my/macro.dart' show myAnnotation, myMacro;
@myMacro
class A {
@myAnnotation
int foo;
} If import 'package:my/macro.dart' show myAnnotation, myMacro;
@myMacro
class A {
static const myAnnotation = 0;
@myAnnotation
int foo;
} |
Also if the metadata class or any constructors used in arguments come from the current library cycle then we can't construct it at all 🤔 (it isn't complete until after the definition phase) |
So one idea here is we could place some restrictions on metadata annotations:
With those restrictions, I think we should be able to provide access to metadata from any phase. EDIT: this would imply however that all phases of macros have to be ran for any class used as metadata, before running any phase of macro from the current module. Macros themselves already also have this restriction though. |
We probably cannot disallow using local declaration for all metadata. Running all phases seems reasonable, in the analyzer we usually process library cycles fully one by one. |
It is likely a reasonable restriction that macros can only access metadata for types reachable by the macro definition itself. Possibly with an api like |
The current introspection api does not provide access to metadata annotations on declarations today. You can configure macros themselves by passing info to the constructor, but you can't see any other metadata or macros.
This likely would mean we want to expose some sort of equivalent to the DartObject api for these, which is a larger undertaking.
The text was updated successfully, but these errors were encountered: