Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » compile operation
compile operation [message #1734387] Tue, 07 June 2016 19:24
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
Hi,

I have developed a method for loading Xcore and create a ecore file. while I needed to generate ecore file from xcore file programatically I have used doGenerate method of a DSL which I developed in Xtext and through saving I can save ecore file. But because in generated ecore file the body of method was not saved I thought to user a xtend class and which simulate the xcore doGenerator to have the body of operation in ecore file. but I see an error.
	
	public static void Xcore2Ecore(URI sourcename, URI targetname, IFileSystemAccess fsa) {
		
		try {

			
			ResourceSet localResourceSet = new ResourceSetImpl();
			
	
			if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) {
				Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
			}
			if (!EPackage.Registry.INSTANCE.containsKey(EcorePackage.eNS_URI)){
				EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI,EcorePackage.eINSTANCE);
			}
			if (!EPackage.Registry.INSTANCE.containsKey(XbasePackage .eNS_URI)){
				EPackage.Registry.INSTANCE.put(XbasePackage.eNS_URI,XbasePackage .eINSTANCE);
			}
			if (!EPackage.Registry.INSTANCE.containsKey(XcorePackage  .eNS_URI)){
				EPackage.Registry.INSTANCE.put(XcorePackage.eNS_URI,XcorePackage .eINSTANCE);
			}
			
			
			Resource xcoreResource = localResourceSet.getResource(sourcename,true);
			
			XcoreGeneratorHelper xcoreGeneratorHelper=new XcoreGeneratorHelper();
			xcoreGeneratorHelper.doGenerate(xcoreResource, fsa);
			
			
			localResourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
			
			EcoreUtil.resolveAll(localResourceSet);
			
			Resource ecoreOutputResource = new ResourceImpl();
			ecoreOutputResource.getContents().add((EPackage) EcoreUtil.getObjectByType(	xcoreResource.getContents(),EcorePackage.Literals.EPACKAGE));
			
			Map<String, String> saveOptions = new HashMap<String, String>();
			
			Resource xmiResource = new XMIResourceImpl(targetname);
			xmiResource.getContents().add(ecoreOutputResource.getContents().get(0));
			saveOptions.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_ENCODING,"UTF-8");
			xmiResource.save(saveOptions);

			System.out.println(":) Xmi file created for ecore.");
			
		} catch (IOException e) {

			System.out.println(":( Error during creating Xmi for ecore.");
			
		}
	}


this method can generate ecore file but the operations are saved without body
    <eOperations name="getVorgaenger" unique="false" eType="//Begriff">
      <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
        <details key="body" value=""/>
      </eAnnotations>
      <eParameters name="liste" unique="false" upperBound="-1" eType="//Begriff"/>
      <eParameters name="begriff" unique="false" eType="//Begriff"/>
    </eOperations>


I have attached the MyDSl generator file. Xcore file and XcoreGenerator file.
Previous Topic:Disable terminal rule on selected parser rule?
Next Topic:Maven Layout and Eclipse plugins
Goto Forum:
  


Current Time: Wed Nov 13 10:04:31 GMT 2019

Powered by FUDForum. Page generated in 0.01617 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top