Forked from acerosalazar/IFMLCodeGenerator-Main.xtend
Created
April 27, 2017 21:24
-
-
Save magick93/6c44e50d905cf7ba6908153f445c6594 to your computer and use it in GitHub Desktop.
A template for creating an Xtend based CodeGenerator using the Ecore implementation of the IFML metamodel and a sample model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package generator | |
// This code is based on this stackoverflow answer:http://stackoverflow.com/questions/12458852/load-emf-model-instance-in-xtend | |
import org.eclipse.emf.common.util.URI | |
import org.eclipse.emf.ecore.resource.Resource | |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | |
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | |
import org.eclipse.emf.ecore.EPackage | |
class CodeGenerator { | |
def static void main(String[] args) { | |
// The model.xmi should be located at the project root. | |
new CodeGenerator().generate("model.xmi") | |
} | |
def generate(String file) { | |
doEMFSetup | |
val resourceSet = new ResourceSetImpl | |
val resource = resourceSet.getResource(URI::createURI(file), true) | |
for (content : resource.contents) { | |
// <- Entry Point | |
} | |
} | |
def doEMFSetup() { | |
// All the EPackages of the metamodel should be registered. | |
// In this example they are declared as extensions of the IFMLEditor jar [Available at: https://github.com/ifml/ifml-editor] | |
EPackage$Registry::INSTANCE.put("'http://www.omg.org/spec/20130218/core'", IFML.Core.CorePackage::eINSTANCE) | |
EPackage$Registry::INSTANCE.put("'http://www.omg.org/spec/20130218/ext'", IFML.Extensions.ExtensionsPackage::eINSTANCE) | |
EPackage$Registry::INSTANCE.put("'http://www.omg.org/spec/20130218/data'", IFML.DataTypes.DataTypesPackage::eINSTANCE) | |
Resource.Factory.Registry::INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment