EMF: How to create model instance programmatically without using eclipse instance - serialization

With EMF I can import an ecore file (metamodel), generate the code then debug the project as a new eclipse instance to play with my model instance. My purpose is to create my instance without loading a new eclipse instance, for example I would like to create a new Java project that use my generated code to create the instance assuming that I'll do some validation/OCL to have an instance that I can serialize to an XMI file.
I was thinking about export the generated code (Model, Edit, Editor) to a JAR file or as a plugin, but it didn't work perfectly. Do you have any suggestion or HowTo?

I am not sure what you mean by "without loading a new eclipse instance", but if you want to get rid of the EMF and Eclipse-dependencies you can achieve this by editing your genmodel. This recipe explains the steps in detail: http://wiki.eclipse.org/EMF/Recipes#Recipe:_Generating_Pure_API_With_No_Visible_EMF_Dependencies
Not everything EMF has to offer will work with this solution, but it might be sufficient for what you want.

Related

How to listen for "Example EMF Model Creation Wizards"?

I am developing a plugin for Eclipse Mars.2. I want to know if it is possible to create Example EMF Model Creation Wizards file programmatically and add data to the generated model file. Is it possible ?
EDIT
I have defined an ecore model that I use to create an Example EMF Model Creation Wizards file but I would like to do that automatically. My problem is that when I generate a file with all the correct data in it, I can't use it and navigate through the data. I have to copy the text data into a file created with the Eclipse wizard to make it work. This file is then interpreted by a Sirius diagram/table definition to create a graphical view.
Not sure what the question actually is, so taking it literally I say you can use the EMF APIs to create models programmatically. This has nothing to do with the wizards though.

Android studio generating new DaggerComponet.java file

I have defined my Dagger2 component file in a class named LpComponent.java so I need to instantiate things using DaggerLpComponent class reference.
However when I update LpComponent.java file DaggerLpComponent is not getting recreated , only way I can get this is to clean the whole project, and rebuild it.
Is there good old make style dependency I can specify DaggerLpComponent.java depends on LpComponent.java?
Also its not clear to be what rule generates DaggerLpComponent.java file. I have tried ./gradlew tasks to see if there is some dagger specific task that generates the file, but didn't see anything..
Dagger 2 works via annotation processing, which happens at compile time. A simple compilation of your project should trigger the Dagger 2 annotation processor to run and generate new sources. With Android, that should be minimally one of the tasks starting with "compile" that has your build type and flavor in the name.

Auto Generate code in java based on templates

I have a eclipse plugin and I want to add a capability to generate java code blocks based on simple template or anything simple. Something like generate source for constructors or getters and setters that java editor provides.
I have seen the JET articles : https://eclipse.org/articles/Article-JET2/jet_tutorial2.html but I want something simpler.
Eclipse already some has it built in:
1. Highlight your field
2. Right Click -> Source -> Generate Getters and Setters
Also you can use the wizards to create a basic java class.
1. File -> New -> Class
etc.
You can also look up this related question:
A Java API to generate Java source files

Create a simple Java Class in IntelliJ 13

When I am using Eclipse I just configure a project in seconds and create classes in seconds. In intelliJ however, I have to be looking all over the place on how ro create a simple Java class. I swear it is not in the new drop down list. Its giving me options for html and leaves out the class for a Java project! Anything would be accepted.
You just right click on the package you want to create a Java Class in, then select New->Java Class
You need to make sure you have your source tree marked as a sources root (IntelliJ usually does a good job detecting this on its own for existing sources). If not you will need to mark it as a sources root before you are able to create a Java class. Right click on the sources root then Mark Directory As->Sources Root
It depends on the kind of project you're doing. For example, if you're in a maven project, creating a file should be done in src/main/java. If you right click on this folder, you'll have the possibility to create a java class.
In general, the context menu depends on the context you're calling it.
Hope it helps

Integrate JET Templates to an EMF-GMF plugin

I created an plugin that lets me model JSF Applications. I created it using Emfatic, Ecore, EMF, GMF.
So now i have 5 projects in my workspace:
myapp
myapp.diagram
myapp.edit
myapp.editor
myapp.tests
If i run myapp as a Eclipse Application i can draw/design a .myapp_diagram based on the meta-model.
Now I want to know how can i integrate JET Templates with what i have here.
I have the diagram, i know how to build JET Templates, i just want to know how can i feed the diagram as input to the JET temples so that code will be generated.
What i have done until now is convert the "myapp" project to JET Project and wrote the template files. But if i now run "myapp" and draw a diagram, theres nowhere a GENERATE CODE button/option.
Unfortunately none of the Eclipse-based modelling projects provide a "generate code" button. There are a wide range of possible model sources and code generation platforms (JET, OAW, Xpand), so you will have to implement the button and the relevant source code yourself. However, the process is fairly straightforward.
One approach is to implement an org.eclipse.ui.popupMenus extension point, which then calls the Java class necessary to generate the code.
As an example, you can check out the plugin.xml used in the IAML project to generate PHP/Javascript source code, using openArchitectureWare (OAW) templates. The relevant Eclipse Action is GenerateCodeAction - check out the method doExecute(). Hope this helps :)