|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
| 
| Re: generate a model .xmi xtext eclipse [message #1726163 is a reply to message #1726103] | Thu, 10 March 2016 04:13  |  | 
| Eclipse User  |  |  |  |  | Some newbies like me may find this code with just a little bit of comment helpful to reproduce: 
 
// file: /org.xtext.example.mydsl/src/org/xtext/example/mydsl/Main.java
//
// This example is done using the
// eclipse-dsl-mars-1 distribution with the 
// xtext_2.8.4.v201508050135
//
// we use the standards for a new xtext project which creates a project as: org.xtext.example.mydsl
// and we generate the xtext artifacts running the GenerateMyDsl.mwe2
//
// under the project, we create a new folder "models_xmi" for DSL files as well as the generated xmi files
// in that directory, we create DSL file testMYDSL.mydsl as:
/*
Hello PAUL!
Hello Peter!
Hello Martin!
*/
// in src/org.xtext.example.mydsl we create a new Java Class with name "Main" 
// and check "public static void main(String[] args)" in the wizard
// and this is the code in this Main.java file (note the "throws Exception")
// 
package org.xtext.example.mydsl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import com.google.inject.Injector;
public class Main {
	public static void main(String[] args) throws Exception{
		Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet resourceSet = injector.getInstance(ResourceSet.class);
		// this is our source DSL file "testMYDSL.mydsl" in folder "models_xmi"
		/*
		Hello PAUL!
		Hello Peter!
		Hello Martin!
		 */
		Resource resource = resourceSet.getResource(URI.createURI("models_xmi/testMYDSL.mydsl"), true);
		resource.load(null);
		EcoreUtil.resolveAll(resourceSet);
		// and this is the corresponding xmi file "testMYDSL.xmi" in folder "models_xmi":
		/*
		<?xml version="1.0" encoding="ASCII"?>
		<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:myDsl="http://www.xtext.org/example/mydsl/MyDsl">
  		<greetings name="PAUL"/>
  		<greetings name="Peter"/>
  		<greetings name="Martin"/>
		</myDsl:Model>
 		 */
		Resource xmiResource = resourceSet.createResource(URI.createURI("models_xmi/testMYDSL.xmi"));
		xmiResource.getContents().add(resource.getContents().get(0));
		xmiResource.save(null);
	}
}
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.12122 seconds