Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Add support for custom annotations (useful for reflectable) #51

Closed
wienczny opened this issue Oct 12, 2015 · 4 comments
Closed

Add support for custom annotations (useful for reflectable) #51

wienczny opened this issue Oct 12, 2015 · 4 comments

Comments

@wienczny
Copy link

This bug might be the second incarnation of #29. PolymerDart 1.0 switched to reflectable to almost replace mirrors. If you want to use protobuf elements in PolymerDart templates these have to be reflectable using the JsProxy. This is done by the ReflectableTransformer that requires annotations on custom classes.
I would suggest adding support for custom annotations using the code generator.

@eernstg
Copy link

eernstg commented Oct 13, 2015

This may not matter for you because you are discussing code generation, but it might still be useful for you to know that you can use other mechanisms in reflectable than direct annotation, if it is inconvenient to put actual @jsProxyReflectable metadata annotations on a set of classes:

You can use a global quantifier to attach a reflector to a given target class "at a distance": @GlobalQuantifyCapability("MyClass", myReflector) as an annotation on an import of 'package:reflectable/reflectable.dart' (anywhere in the program, as long as myReflector is in scope) has the same effect as putting @myReflector on MyClass.

You can also use subtypeQuantifyCapability in the class of myReflector to get the same effect as putting @myReflector on all the subtypes of MyClass. With that you've obtained reflection support for an entire subtype hierarchy of a given class without editing any of the files containing the classes in that hierarchy.

@wienczny
Copy link
Author

This might solve my problem. In PolymerDart myReflector is jsProxyReflectable and subtypeQuantifyCapability is enabled by default. So I added

import 'package:polymer/init.dart';
import 'package:polymer/polymer.dart';
import 'package:reflectable/reflectable.dart';

@GlobalQuantifyCapability('protobuf.GeneratedMessage', jsProxyReflectable)
import 'messages.pb.dart';

where messages.pb.dart contains the generated classes. Now the transformer fails with messages like

'prefix5' has no member named 'reflectable_generated_main_library#_ReadonlyEnvelope'.

for every _Readonly*. This is a reflectable bug - right? I can provide you a sample project but we should move over to https://github.com/dart-lang/reflectable for that issue.

I still think it might be useful to be able to extends the code generator although I lost my example ;)

@eernstg
Copy link

eernstg commented Oct 13, 2015

Clearly, the reflectable transformer should never generate code that fails to compile, so it is a bug. It would be great if you could create such a new issue on reflectable!

Another thing is that @GlobalQuantifyCapability must be located on the import of 'reflectable.dart' in order to have any effect, so you should move it a couple of lines up.

@sigurdm
Copy link
Contributor

sigurdm commented Sep 17, 2018

I think that the use case can be covered by making an (empty) mixin, and declaring your messages to mix that in. I made a small example here: https://github.com/sigurdm/reflect_proto_mixin.

Given that I don't think we should add yet another dart-specific feature.

Please reopen if there are more examples of things we cannot do without metadata.

@sigurdm sigurdm closed this as completed Sep 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants