Skip to content

dart2js should provide reflective access to metadata #10905

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
peter-ahe-google opened this issue May 28, 2013 · 19 comments
Closed

dart2js should provide reflective access to metadata #10905

peter-ahe-google opened this issue May 28, 2013 · 19 comments
Assignees
Labels
library-mirrors P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Milestone

Comments

@peter-ahe-google
Copy link
Contributor

dart2js should support this getter on DeclarationMirror:

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

See issue #6614.

@peter-ahe-google
Copy link
Contributor Author

Removed this from the M5 milestone.
Added this to the M6 milestone.

@justinfagnani
Copy link
Contributor

How will this work for compile-time mirrors? Will hasReflectee on the InstanceMirrors return true? If so, what type will it be and will there be a way visit the value?

@peter-ahe-google
Copy link
Contributor Author

This bug is for runtime support, dart2js already supports metadata for source mirrors.

Some source-InstanceMirrors have a reflectee, but only simple values such as bool, int, String, etc. For lists and maps, Johnni added some convenience methods for accessing their elements. For more complex constants, you have to look at their fields. Take a look at dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart. Feel free to ask additional questions about source mirrors at [email protected].

@peter-ahe-google
Copy link
Contributor Author

https://codereview.chromium.org/16101007/ implements LibraryMirror.metadata.

@peter-ahe-google
Copy link
Contributor Author

CL 16101007 landed in r23406.

@peter-ahe-google
Copy link
Contributor Author

https://codereview.chromium.org/15821011/ implements ClassMirror.metadata.

@peter-ahe-google
Copy link
Contributor Author

CL 15821011 landed in r23457.

@peter-ahe-google
Copy link
Contributor Author

https://codereview.chromium.org/15861028/ implements MethodMirror.metadata.

@peter-ahe-google
Copy link
Contributor Author

CL 15861028 landed in r23529.

@peter-ahe-google
Copy link
Contributor Author

https://codereview.chromium.org/16156013/ implements metadata on instance fields.

@peter-ahe-google
Copy link
Contributor Author

CL 16156013 landed in r23580.

@sethladd
Copy link
Contributor

Thanks Peter. Just tried a simple case and it worked!

import 'dart:mirrors';

const awesome = const Awesome('way cool');

class Awesome {
  final String msg;
  const Awesome(this.msg);
  
  String toString() => msg;
}

@awesome('it works!')
class Cool {
  
}

void main() {
  var classMirror = reflectClass(Cool);
  var metadata = classMirror.metadata;
  var obj = metadata.first.reflectee;
  print(metadata);
  print(obj);
}

Do you have an easy list of things you expect to work at this point?

@peter-ahe-google
Copy link
Contributor Author

See this test for what works in both dart2js and the VM:
https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/tests/lib/mirrors/metadata_test.dart

@peter-ahe-google
Copy link
Contributor Author

Added Library-Mirrors label.

@peter-ahe-google
Copy link
Contributor Author

Marked this as blocking #6490.

@gbracha
Copy link
Contributor

gbracha commented Aug 23, 2013

Marked this as blocking #6614.

@larsbak
Copy link

larsbak commented Aug 28, 2013

Removed this from the M6 milestone.
Added this to the M7 milestone.

@kasperl
Copy link

kasperl commented Oct 2, 2013

Removed this from the M7 milestone.
Added this to the M8 milestone.

@kasperl
Copy link

kasperl commented Jun 4, 2014

Removed this from the M8 milestone.
Added this to the 1.6 milestone.

@peter-ahe-google peter-ahe-google added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js library-mirrors labels Jun 4, 2014
@peter-ahe-google peter-ahe-google self-assigned this Jun 4, 2014
@peter-ahe-google peter-ahe-google added this to the 1.6 milestone Jun 4, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library-mirrors P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Projects
None yet
Development

No branches or pull requests

6 participants