M2T Xpand with existing ecore model

1.1k views Asked by At

I have an ecore model MyModel.ecore for which i want to generate code using Xpand. I dont have edit code or a runtime environment for the xpand project, i just want to create a xpand project, load MyModel.ecore, create a model.xmi using "create dynamic instance" and run. The problem is that my workflow file doesnt seems to recognize the elements from my metamodel. Here is the code from my workflow:

<?xml version="1.0"?>
  <workflow>
<property name="model" value="com.example/src/Application.xmi" />
<property name="src-gen" value="src-gen" />

<!-- set up EMF for standalone execution -->
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
    <platformUri value=".."/>
</bean>

<!-- instantiate metamodel -->
<bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>

<!-- load model and store it in slot 'model' -->
<component class="org.eclipse.emf.mwe.utils.Reader">
    <uri value="platform:/resource/${model}" />
    <modelSlot value="model" />
</component>

<!-- check model -->
<component class="org.eclipse.xtend.check.CheckComponent">
    <metaModel idRef="mm_emf"/>
    <checkFile value="metamodel::Checks" />
    <emfAllChildrenSlot value="model" />
</component>

<!--  generate code -->
<component class="org.eclipse.xpand2.Generator">
    <metaModel idRef="mm_emf"/>
    <expand
        value="template::Template::Root FOR Application" />
    <outlet path="${src-gen}" >
        <postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
    </outlet>
</component>

My template file:

«IMPORT MyModel»

  «DEFINE Root FOR Application»
 «FILE "AndroidManifest.xml"»

 «ENDFILE»

     «EXPAND ProcesaScreens FOREACH Screens»


     «ENDDEFINE»


   «DEFINE ProcesaScreens FOR Screen»
    «FILE this.name +".java"»
    «IF (this.metaType.compareTo(StartScreen.metaType) == 0)»
        «EXPAND ProcesaStartScreen FOR (StartScreen)this»
    «ENDIF»

«ENDFILE»
    «ENDDEFINE»


   «DEFINE ProcesaStartScreen FOR StartScreen»
      «FILE "FilePrueba.java"»
      «ENDFILE»

    «ENDDEFINE»

And im getting this error:

695 INFO CompositeComponent - Reader: Loading model from platform:/resource/guiamovil.xpand/src/Application.xmi 890 INFO CompositeComponent - CheckComponent: slot model check file(s): metamodel::Checks 1329 INFO CompositeComponent - Generator: generating 'template::Template::Root FOR Application' => src-gen 1340 ERROR AbstractExpressionsUsingWorkflowComponent - Error in Component of type org.eclipse.xpand2.Generator: EvaluationException : Couldn't find type or property 'Application' [59,11] on line 1 'Application' 1340 ERROR WorkflowEngine - Workflow interrupted. Reason: Couldn't find type or property 'Application' 1340 ERROR WorkflowEngine - [ERROR]: Couldn't find type or property 'Application'(Element: Application; Reported by: Generator: generating 'template::Template::Root FOR Application' => src-gen) 1341 ERROR WorkflowEngine - [ERROR]: Couldn't find type or property 'Application'(Element: EXPAND template::Template::Root FOR Application; Reported by: Generator: generating 'template::Template::Root FOR Application' => src-gen)

I imagine its something in the workflow.

Thanks

1

There are 1 answers

0
issamux On

I think you should register your models first :

 <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
 <platformUri value=".."/>  
 <registerGeneratedEPackage value="com.issamux.example"/>
  ....
  //
 </bean>
 <!-- instantiate metamodel -->
 <bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>

//your code 

let me now if this resolved your problem...