Guest User

Untitled

a guest
Apr 27th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. package com.xtextatl.example;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.util.Collections;
  6.  
  7. import org.eclipse.core.runtime.NullProgressMonitor;
  8. import org.eclipse.emf.common.util.URI;
  9. import org.eclipse.emf.ecore.resource.Resource;
  10. import org.eclipse.m2m.atl.core.ATLCoreException;
  11. import org.eclipse.m2m.atl.core.emf.EMFInjector;
  12. import org.eclipse.m2m.atl.core.emf.EMFModel;
  13. import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
  14. import org.eclipse.m2m.atl.core.emf.EMFReferenceModel;
  15. import org.eclipse.m2m.atl.core.launch.ILauncher;
  16. import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
  17. import org.eclipse.xtext.resource.XtextResource;
  18. import org.eclipse.xtext.resource.XtextResourceSet;
  19. import com.dsl.DSLStandaloneSetup;
  20.  
  21. import com.google.inject.Injector;
  22.  
  23. public class Main {
  24.  
  25. /**
  26. * @param args
  27. * @throws ATLCoreException
  28. * @throws IOException
  29. */
  30. public static void main(String[] args) throws ATLCoreException, IOException {
  31. // Replace DSL by your Language name
  32. DSLStandaloneSetup dsl = new DSLStandaloneSetup();
  33. Injector injector = dsl.createInjectorAndDoEMFRegistration();
  34. XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
  35. resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
  36. Resource resource = resourceSet.getResource(URI.createURI("URI to your dsl file"), true);
  37.  
  38. // Create factory and injector
  39. EMFModelFactory factory = new EMFModelFactory();
  40. EMFInjector emfinjector = new EMFInjector();
  41. // Load the DSL metamodel
  42. EMFReferenceModel dslMetamodel = (EMFReferenceModel) factory.newReferenceModel();
  43. emfinjector.inject(dslMetamodel, "DSL Metamodel Path");
  44. // Load the XtextResource as an EMFModel
  45. EMFModel model = (EMFModel) factory.newModel(dslMetamodel);
  46. emfinjector.inject(model, resource);
  47.  
  48. EMFReferenceModel outMetamodel = (EMFReferenceModel) factory.newReferenceModel();
  49. emfinjector.inject(outMetamodel, "OUT Metamodel Path");
  50. EMFModel outModel = (EMFModel) factory.newModel(outMetamodel);
  51.  
  52. EMFVMLauncher launcher = new EMFVMLauncher();
  53. launcher.initialize(Collections.<String, Object> emptyMap());
  54.  
  55. launcher.addInModel(model, "IN", "DSL");
  56. launcher.addOutModel(outModel, "OUT", "OUTMM");
  57.  
  58. InputStream asm = Main.class.getResourceAsStream("transformation.asm path");
  59.  
  60. launcher.launch(
  61. ILauncher.RUN_MODE,
  62. new NullProgressMonitor(),
  63. Collections.<String, Object> emptyMap(),
  64. new Object[] {asm} );
  65.  
  66. outModel.getResource().setURI(URI.createURI("URI to store out model"));
  67. outModel.getResource().save(Collections.EMPTY_MAP);
  68. }
  69.  
  70. }
Add Comment
Please, Sign In to add comment