Skip to content

reflective access to metadata #6614

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

Closed
DartBot opened this issue Nov 8, 2012 · 19 comments
Closed

reflective access to metadata #6614

DartBot opened this issue Nov 8, 2012 · 19 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@DartBot
Copy link

DartBot commented Nov 8, 2012

This issue was originally filed by [email protected]


From the language specification (0.12) :

"Metadata can be retrieved at runtime via a reflective call, provided the annotated program construct p is accessible via reflection.

Reflective access to metadata is not yet implemented as of the M1 release."

I am opening this issue so that we have something to track regarding this feature.

thanks a bunch!

@madsager
Copy link
Contributor

madsager commented Nov 8, 2012

Added Area-Language, Triaged labels.

@justinfagnani
Copy link
Contributor

Added C1 label.

@jmesserly
Copy link

this is library-mirrors right?
(@­Gilad feel free to correct this if I'm wrong!)


cc @gbracha.
Removed Area-Language label.
Added Area-Library, Library-Mirrors labels.

@DartBot
Copy link
Author

DartBot commented Apr 10, 2013

This comment was originally written by [email protected]


I think https://code.google.com/p/dart/issues/detail?id=8493 is a duplicate?

@gbracha
Copy link
Contributor

gbracha commented Apr 10, 2013

Issue #8493 has been merged into this issue.

@jmesserly
Copy link

Removed Priority-Medium label.
Added Priority-High label.

@gbracha
Copy link
Contributor

gbracha commented Apr 22, 2013

In reality this requires VM support (and dart2js will have its own story in time). I'll see what can be done.


Set owner to @gbracha.
Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Apr 22, 2013

This comment was originally written by [email protected]


I understand that this requires support from VM, is that a problem ?
Annotations are totally useless, unless we can read them through reflection ;-)

@gbracha
Copy link
Contributor

gbracha commented Apr 22, 2013

It's not a problem. I'm just trying to communicate the steps this requires. Whether annotations are useful when they are not available at runtime depends on the usage scenario, but I appreciate that you need them at runtime.

@DartBot
Copy link
Author

DartBot commented Apr 22, 2013

This comment was originally written by [email protected]


How can I use them other than in runtime ?

@gbracha
Copy link
Contributor

gbracha commented Apr 22, 2013

There are people who want to use them at compile time, and they can use dart2js to parse the code and collect the relevant data. It isn't your use case, but it is not uncommon.

@DartBot
Copy link
Author

DartBot commented Apr 22, 2013

This comment was originally written by [email protected]


for an example of compile time annotation usage see the use of web-ui's @­observable

also, thanks for the work on this. im really looking forward to runtime access!!

@gbracha
Copy link
Contributor

gbracha commented Apr 22, 2013

cc @iposva-google.
cc @mhausner.
Added Area-VM label.

@gbracha
Copy link
Contributor

gbracha commented May 13, 2013

So the proposed API for this would be to add the following to DeclarationMirror

/**
  * A list of the metadata associated with this declaration.
*/
List<InstanceMirror> get metadata;

A map would be nice, but metadata does not have a unique name. We could have a map if each entry was a list., i.e.,
Map<Symbol, List<InstanceMirror>> get metadata;

The key would be the symbol for name of the constructor or variable used as metadata.
Typically, the list returned would only have one member.

@DartBot
Copy link
Author

DartBot commented May 14, 2013

This comment was originally written by [email protected]


  • Will we be able to add new InstanceMirror(s) to the metadata List or Map, or will it throw errors in this case?
  • TypeDescriptor allows us to introspect / manipulate metadata on a per-instance basis (in addition to the Type); any chance we could also get metadata on InstanceMirror to cover those use cases?

@gbracha
Copy link
Contributor

gbracha commented May 14, 2013

Responding two comment 15:

This is an extension to the introspection API. It does not allow programs to be modified, only to be observed. So the answer to the first question is that the list (or map) will be immutable.

As for the second item (which I may have misunderstood): metadata appears on source code, and is associated with declarations. So it makes no sense to query instances. If you want data on instances, put it in them; it's not meta data, just data.

@DartBot
Copy link
Author

DartBot commented May 14, 2013

This comment was originally written by [email protected]


Thanks for the response(s).

If this is purely introspection than the second item is inherently ruled out, but FWIW I was referring to 'attribute redirection' as described here:
http://msdn.microsoft.com/en-us/library/ms171819.aspx

@DartBot
Copy link
Author

DartBot commented May 14, 2013

This comment was originally written by [email protected]


Or 'metadata substitution', I'm not up to snuff with their terminology. But this particular method has key uses in designers / property grids:

http://msdn.microsoft.com/en-us/library/8xazd050.aspx

@gbracha
Copy link
Contributor

gbracha commented May 14, 2013

Ross,

When we have mirror builders, one will be able to change the metadata on existing declarations. Mirror builders will probably not be a universally available though, because supporting them on dart2js is likely to be much too costly.

@DartBot DartBot added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors labels May 14, 2013
@DartBot DartBot added this to the 1.6 milestone May 14, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

6 participants