eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
399 stars 62 forks source link

Provide way to reference generated annotations in Ceylon #2121

Open CeylonMigrationBot opened 9 years ago

CeylonMigrationBot commented 9 years ago

[@jvasileff] Java annotations generated by Ceylon are of the form AnnotationClass$annotation$, making them inaccessible from Ceylon code.

This was originally discussed on the dev mailing list.

@tombentley noted:

I do wonder though if there's a reason I didn't make the @interface a static member of the class. That would seem to solve the problem, though it would break compatibility.

@lucaswerkmeister suggested:

With #4311, perhaps CObjectValid$annotation$ could be written as annotation::CObjectValid?

[Migrated from ceylon/ceylon-compiler#2121]

CeylonMigrationBot commented 9 years ago

[@FroMage] Isn't that a duplicate of #2109? Reopen if not, but it looks that way to me.

CeylonMigrationBot commented 9 years ago

[@jvasileff] If I understand correctly, the other one is for synthetic Ceylon annotation classes for Java annotations, whereas this is for generated Java annotations for real Ceylon annotation classes (so, not a dup).

CeylonMigrationBot commented 9 years ago

[@FroMage] Mmm, but why do you need to differentiate CeylonAnnotation from CeylonAnnotation_class then? Presumably they're the same class, no?

CeylonMigrationBot commented 9 years ago

[@jvasileff] Well, it's that when a Ceylon annotation class is compiled, there are two outputs: the class, and a Java annotation. I'd like to use the Java annotation in Ceylon code, to, for instance, satisfy http://docs.oracle.com/javaee/7/api/javax/validation/ConstraintValidator.html in Ceylon.

CeylonMigrationBot commented 9 years ago

[@FroMage] Aw damn, right, but I guess this goes against the reasonable expectation that CeylonAnnotation would be a java.lang.Annotation… OK, so it's about the same thing as #2109 but for Ceylon annotations as well as Java annotations. It is indeed slightly different because for Ceylon annotations we can't fake it (I think) the same way we do for Java annotations and the typechecker will have to learn about them, right @tombentley?

CeylonMigrationBot commented 9 years ago

[@tombentley] This is indeed not really a dupe of #2109.

While using a static member interface would be tidier and nicer when interacting with the Ceylon annotation from Java it doesn't actually help us with this problem, which requires a way to denote the annotation type which by design isn't exposed to Ceylon code.

I can't think of a way of making this work with any kind of sane interop. Literally the only thing I can think of is to say you have to write CObjectValidator in Java.

Any thoughts @gavinking?

CeylonMigrationBot commented 9 years ago

[@FroMage] Well, we could let you access it the same way we let you access the Java annotation type, no?

CeylonMigrationBot commented 9 years ago

[@tombentley] Well, sure we could give it a denotable name and you could import it and use it, I suppose. But:

Basically it would be a departure from the annotations we have today.

CeylonMigrationBot commented 9 years ago

[@gavinking] Call it _Annotation and reference it as \I_Annotation? ;-)

CeylonMigrationBot commented 9 years ago

[@tombentley] Well fine I can do that. But it will break compatibility with 1.1. Are we still trying to keep compatibility?

CeylonMigrationBot commented 9 years ago

[@gavinking] So I now agree that this is a shit problem. To solve this, java.lang.annotation.Annotation must necessarily leak into the Ceylon view of the compiled Ceylon module. That's awful.

CeylonMigrationBot commented 9 years ago

[@gavinking] It seems to me that, whatever the solution to this issue is, it's not for 1.2.

CeylonMigrationBot commented 9 years ago

[@luolong] Forgive me if this is a stupid question, but isn't this a Java interop issue?

CeylonMigrationBot commented 9 years ago

[@FroMage] I fixed #2109 and I think that unless we make the annotation type official as a triplet of annotation declarations, we can't fix this issue. I moved it to 1.3, sorry.