Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Extending EMF Code Generator(New Action in EMF GenModel Editor to create new classes)
Extending EMF Code Generator [message #489160] Thu, 01 October 2009 16:30 Go to next message
Ranjith Chungath is currently offline Ranjith ChungathFriend
Messages: 15
Registered: July 2009
Junior Member
The EMF editor(GenModel editor) currently has following generation actions


  1. Generate Model Code
  2. Generate Edit Code
  3. Generate Editor Code
  4. Generate Test Code


I want to add another action say "Generate Custom Code" to create new Classes and interfaces in a "custom" package the project. I am able to extend GenModel to add an EAttribute "Custom Package" where the developer can specify the package where the custom Class and interface will be created.

I am looking for examples which hooks up similar actions to the code generation.

Also, I have a requirement that new methods need to be added to the Model Implementation class if "Generate Custom Code" action is executed. Basically the Model Implementation class needs to be created/merged on two actions("Generate Model Code" and "Generate Custom Code"). What is the best way of handling this?
Re: Extending EMF Code Generator [message #489275 is a reply to message #489160] Fri, 02 October 2009 08:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Ranjith,

Comments below.

ranjith wrote:
> The EMF editor(GenModel editor) currently has following generation
> actions
>
>
> Generate Model Code
> Generate Edit Code
> Generate Editor Code
> Generate Test Code
>
>
> I want to add another action say "Generate Custom Code" to create new
> Classes and interfaces in a "custom" package the project. I am able to
> extend GenModel to add an EAttribute "Custom Package" where the
> developer can specify the package where the custom Class and interface
> will be created.
You might be better off using an GenAnnotation so you can work directly
with any GenModel, not just your extended one.
>
> I am looking for examples which hooks up similar actions to the code
> generation.
>
> Also, I have a requirement that new methods need to be added to the
> Model Implementation class if "Generate Custom Code" action is
> executed. Basically the Model Implementation class needs to be
> created/merged on two actions("Generate Model Code" and "Generate
> Custom Code"). What is the best way of handling this?
Have a look at org.eclipse.emf.examples.generator.validator as an
example of how to extend the generator without extending the GenModel
itself. Dynamic templates can be used for changing what's generated.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extending EMF Code Generator [message #489608 is a reply to message #489275] Mon, 05 October 2009 10:30 Go to previous messageGo to next message
Ranjith Chungath is currently offline Ranjith ChungathFriend
Messages: 15
Registered: July 2009
Junior Member
Thanks Ed,

I looked at the org.eclipse.emf.examples.generator.validator example.

In org.eclipse.emf.examples.generator.validator.ValidatorGenera torUtil,

public static String getValidationPackageName(GenPackage genPackage)
{
String basePackage = genPackage.getInterfacePackageName();
return basePackage.length() > 0 ? basePackage + ".validation" : "validation";

}

This basically creates a "$CLASSNAME"Validator.java in the "$basepackage".validation package.

My requirement is to create the class in a package which can be specified in the GenModel by the developer. Like the current packages for interface,Impl,provider etc I want add a validator in the property page for GenPackage.

Can I do that without extending GenModel(or GenPackage)?
Re: Extending EMF Code Generator [message #489614 is a reply to message #489608] Mon, 05 October 2009 10:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
The GenModel supports annotations. In the editor you can use
Generator->Show Annotations and then on any object you can use Annotate
from the popup to create an annotation and you can use Add Detail on the
popup for that to create key/value pairs; it works much like
EAnnotations. Later you can use getGenAnnotation(<source>).get(<key>)
to retrieve a <value>. In this way you could add the additional
information your extension needs using an annotation rather than needing
an extended GenModel...


ranjith wrote:
> Thanks Ed,
>
> I looked at the org.eclipse.emf.examples.generator.validator example.
> In org.eclipse.emf.examples.generator.validator.ValidatorGenera torUtil,
> public static String getValidationPackageName(GenPackage genPackage)
> {
> String basePackage = genPackage.getInterfacePackageName();
> return basePackage.length() > 0 ? basePackage + ".validation" :
> "validation";
> }
>
> This basically creates a "$CLASSNAME"Validator.java in the
> "$basepackage".validation package.
>
> My requirement is to create the class in a package which can be
> specified in the GenModel by the developer. Like the current packages
> for interface,Impl,provider etc I want add a validator in the property
> page for GenPackage.
>
> Can I do that without extending GenModel(or GenPackage)?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Suppressing document root but loosing name of top element.
Next Topic:Date handling
Goto Forum:
  


Current Time: Fri Mar 29 11:30:31 GMT 2024

Powered by FUDForum. Page generated in 0.03263 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top