Bug 375701 - [Xtend] Proposal for adding annotation @Dispatch to dispatch method definition in generated Java code
Summary: [Xtend] Proposal for adding annotation @Dispatch to dispatch method definitio...
Status: UNCONFIRMED
Alias: None
Product: Xtend
Classification: Tools
Component: Backlog (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-30 06:05 EDT by Evermind CLA
Modified: 2012-11-09 02:41 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Evermind CLA 2012-03-30 06:05:18 EDT
Build Identifier: Version: 3.7.1 Build id: 20110909-1335

Proposal for adding annotation @Dispatch(or something similar) to dispatch method definition in generated Java code, so that Java code reader can distinguish them from normal non-multi-dispatchable methods, since they are different from the view point of caller.


Reproducible: Always
Comment 1 Sven Efftinge CLA 2012-11-08 05:38:18 EST
They start with an underscore isn't that suffcient?
Comment 2 Sebastian Zarnekow CLA 2012-11-08 05:40:40 EST
Other elements that are generated also start with an underscore. @Dispatch would be more descriptive in addition to the mandatory underscore prefix.

+1
Comment 3 Jan Koehnlein CLA 2012-11-08 06:09:10 EST
Currently we automatically pick up operations from Java superclasses that have the right signature (start with '_', have correct # of args) when assemblying the dispatch case methods.

Adding a @Dispatch annotation suggests that these are no longer taken into account. This could break existing clients.
Comment 4 Sebastian Zarnekow CLA 2012-11-08 06:11:34 EST
I don't propose to change the semantics of the _underscore methods but just to add the annotation for documentation purpose. Alternatively we could append that information to the JavaDoc.
Comment 5 Evermind CLA 2012-11-09 01:26:46 EST
It has been a while so I cannot remember the exact scenario this ticket was brought up. The gross motivation was that I wanted to reflect on some Java classes (yes, including Xtend generated ones) and list their members, including fields and methods. And I found that Xtend dispatch method generates a group of methods which should be non-exist from the view of programmer, so I want to hide these "phantom" methods from the user of my module. However I found this difficult, because there is no ensured way to tell if an _underscore leaded method is a generated dispatch method, or it is just a hand-written private method.
I know that this "_privateThings" style is becoming obsolete, however in our code base it exists. And there is no requirement defined in Xtend that require user to abandon _privateElement style. And even if it do, I don't think this requirement reasonable. So it makes the above objective impossible. There is a principle saying: make easy things easy and hard things possible. Thus, may I go a step further and suggest that everything "virtually" generated by Xtend(that is, not exist in Xtend source code, meaning that they shall be invisible to programmers in conception) be tagged with @XtendGen annotation, in which an enum value used to distinguish concrete cases.

    enum XtendGenType {
        METHOD, FIELD, ...
        // Could be more specific, e.g. DISPATCH_METHOD
    }

And in generated java code:
    @XtendGen(XtendGenType.METHOD)
    _dispatchMethodImpl() {...

IMHO it costs almost nothing and don't get in the way when it isn't needed. And there is no difficulty in implementation. And though the case is rare, it may make some runtime reflection problems possible.
Comment 6 Sebastian Zarnekow CLA 2012-11-09 02:41:19 EST
In addition to the mentioned use cases for Java reflection, I see the following advantage for a dedicated @Dispatch annotation:

Iff we annotate the cases / all synthetic members properly, this information will be displaced in the JavaDoc, e.g. @Dispatch _caseSomething instead of _caseSomething. Furthermore I expect findbugs to be able to suppress certain validations if a specific annotation is present. One could even go a step further and provide a JavaDoc template that is aware of a @Dispatch Javadoc tag and highlights / groups these methods correctly.