[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: Integrate with EMF code generation

Hi Ed,
Here it is:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217220

gr. Martin

Ed Merks wrote:
Martin,

Please open a new bugzilla feature request for this proposal. The existing bug I mentioned would be best to implement using the same extension mechanism so that there are no first and second class citizens for this type of generated annotation support. The extension might even help specify the merge rules that would apply to these annotations...


Martin Taal wrote:
Hi Ed,
Hmmm yes I would also prefer to work without dynamic templates. Genmodel property is fine, or an extension point, which one is easier to in your opinion?


The annotator class (which can then be specified in the genmodel or the extension point) could have an interface like this (just thinking out loud here):

interface EMFAnnotator {

/** is called once before the generation step, maybe other context classes can be passed also/instead? */
initialize(GenModel genModel);
/** Returns an annotation for a specific GenClass */
String getAnnotations(GenClass genClass);


    /** Returns an annotation for a property */
    String getMemberAnnotations(GenFeature genFeature);

    /** Returns an annotation for a getter */
    String getGetterAnnotations(GenFeature genFeature);

    /** Returns an annotation for a setter */
    String getSetterAnnotations(GenFeature genFeature);
}

In the emf templates there should then be calls made to a EMFAnnotatorController (or something similar) which calls the registered EMFAnnotators and returns the string to be placed in the source code.
The annotations also need to be added to the importmanager, this should be done by the EMFAnnotator implementations so they should also have access to the importmanager.


gr. Martin

Ed Merks wrote:
Martin,

Comments below.

Martin Taal wrote:
Hi Ed (and others),
I would like users of Teneo to be able to generate jpa annotations in their model code. My thought is that people install the Teneo plugins and EMF plugins and then with minimal additions/configurations in their genmodel or project be able to generate jpa annotations in their emf-generated code (using the standard EMF code generation menu options). Teneo generates the jpa annotations but now I need to get them into the model code.
I see.

For this I can use dynamic templates (and provide these templates in a Teneo plugin), but more importantly I need to prepare a separate model which is used by the templates, related to this I have a classloading question.
It would seem nicer if we had some type of extensibility mechanism. This bugzilla hints about that

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=176726

For example I would like to add the following code to the templates (before the getter in the template):
jpaAnnotator.getAnnotations(EStructuralFeature eFeature)


however for this to work the EMF code generation plugin needs to know which class/instance jpaAnnotator is (i.e. which plugin provides it and how to create it).
In addition it would be nice if the jpaAnnotator could get hold of the actual location of the ecore or model files in the workspace so that it can read additional property/xml files. Is this something which can be retrieved from the genmodel instance?
GenModel does support GenAnnotations, so it's definitely possible to associate additional information with the GenModel (at any level) without actually extending the model.

Are there specific extension points which I can use for this? Or is there a standard approach I can follow?
Not yet, but I'd certainly be interested in working with you to arrange for that to be possible.

I looked through previous posts on this topic but my main remaining question is especially the classloading issue (how are the teneo plugins 'dynamically' added to the classpath of the emf plugins) and how to inject an jpaAnnotator instance in the EMF code generation environment.
I'd like to arrive at some type of mechanism whereby you'd not need dynamic templates nor a derived GenModel to achieve this goal. Obviously we'd need some type of APIs in the GenModel that would allow the generator templates to fetch the annotations needed for the class and for the generated methods (operations and feature accessors). I think you already have annotations on the Ecore model that you could interpret to produce the Java 5.0 annotations, so perhaps what's needed is some type of registry that allows folks to plugin such interpreters or maybe there's a GenModel property that lists the interpreters that should be invoked for the model; it could specify both the plugin ID and the class name.

As I said, ideally I'd like to come up with something that does not require dynamic templates nor a derived GenModel because that seems heavy weight and it makes combining different extensions impossible.





--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxxxxxxxx - mtaal@xxxxxxxxx
Web: www.springsite.com - www.elver.org