Question about Anno__GETTER and __SETTER

26 views
Skip to first unread message

Tako Schotanus

unread,
Jul 26, 2015, 10:18:49 AM7/26/15
to ceylon-dev
Just a question: why do we *force* people to choose here?
Aren't there (many?) situations where we couldn't care less if the annotation was put on the getter or setter and we could just put them on both without any problem?

It just makes annotating fields very ugly IMO, for example implementing a Ceylon tool plugin now looks like:

    description__SETTER("A simple string option, use `--string-option=foobar`")
    optionArgument__SETTER shared variable String? stringOption = null;

    description__SETTER("A simple flag, use `--simple-flag`")
    option__SETTER shared variable Boolean simpleFlag = false;


-Tako

Gavin King

unread,
Jul 26, 2015, 11:12:26 AM7/26/15
to ceylo...@googlegroups.com
Well for example:

- JPA annotations have to be applied to getters or fields, and
- CDI injection annotations have to be applied to setters or fields.

And the Java annotation metadata doesn't tell us which of these cases we have.
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-dev+...@googlegroups.com.
> To post to this group, send email to ceylo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ceylon-dev.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-dev/CAOJRyvpsa%2BN8UksiiLE-kB_DSmBiVrSKDPQvdwtAcNPctsQL7w%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gavin King
ga...@ceylon-lang.org
http://profiles.google.com/gavin.king
http://ceylon-lang.org
http://hibernate.org
http://seamframework.org

Tako Schotanus

unread,
Jul 26, 2015, 6:46:49 PM7/26/15
to ceylon-dev
Sure, I understand why we have the "_GETTER" and "_SETTER" forms, but why not allow the normal form as well, instead of forbidding it, and make the programmer responsible for choosing the correct one?


-Tako

John Vasileff

unread,
Jul 26, 2015, 6:58:27 PM7/26/15
to ceylo...@googlegroups.com
I think resolving the ambiguity by duplicating the annotation will lead to confusion with runtime errors when a framework tries to “inject” a getter, so I’d rather it be flagged at compile time. I really wish they weren’t so ugly, but in practice import aliases have worked for me.

Tako Schotanus

unread,
Jul 26, 2015, 7:03:58 PM7/26/15
to ceylon-dev
Yeah you're probably right about that John. Thx


-Tako

Reply all
Reply to author
Forward
0 new messages