|
|
|
|
|
Re: Saving model in DSL format [message #922220 is a reply to message #922151] |
Mon, 24 September 2012 21:10 |
|
Here a greeting example
package org.xtext.example.mydsl;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.xtext.example.mydsl.myDsl.Greeting;
import org.xtext.example.mydsl.myDsl.Model;
import org.xtext.example.mydsl.myDsl.MyDslFactory;
import com.google.inject.Injector;
public class Main {
public static void main(String[] args) {
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = injector.getInstance(ResourceSet.class);
Resource r = rs.createResource(URI.createURI("test.mydsl"));
Model m = MyDslFactory.eINSTANCE.createModel();
Greeting g1 = MyDslFactory.eINSTANCE.createGreeting();
g1.setName("g1");
Greeting g2 = MyDslFactory.eINSTANCE.createGreeting();
g2.setName("g2");
m.getGreetings().add(g1);
m.getGreetings().add(g2);
r.getContents().add(m);
try {
r.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.04037 seconds