|
|
Re: M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807180 is a reply to message #1807179] |
Fri, 24 May 2019 07:56   |
Ilja Shmelkin Messages: 5 Registered: May 2019 |
Junior Member |
|
|
Hello,
thank you for taking time to answer.
After some initial trouble I finally understood how Acceleo works within and with the EMF and that you have to use a root element of your metamodel to parse the contents of it (was the ecore-package in my case).
I created a template for Acceleo to process my specific metamodel which I want to provide if someone has the same trouble in the future. I uploaded the template as an attachment to that post.
[comment encoding = UTF-8 /]
[module generateJSON('http://www.eclipse.org/emf/2002/Ecore')]
[template public generateElement(stARSpackage : EPackage)]
[comment @main/]
[file (stARSpackage.name.concat('.json'), false, 'UTF-8')]
{
"name" : "[stARSpackage.name/]",
"nsPrefix" : "[stARSpackage.nsPrefix/]",
"nsURI" : "[stARSpackage.nsURI/]",
"classes" : [for (class : EClass | stARSpackage.eAllContents(EClass)) before ('{\n') separator(',\n') after ('\n\t}\n')]
"[class.name/]":{
[if (class.eAllSuperTypes)->notEmpty()]
"superTypes" : [for (c : EClassifier | class.eAllSuperTypes) before ('[') separator (', ') after ('],')]"[c.name/]"[/for]
[/if]
"abstract" : [class.abstract/],
"interface" : [class.interface/][if (class.eAttributes->notEmpty())],
"parameter" : [for (a : EAttribute | class.eAttributes) before ('{\n') separator(',\n') after ('\n\t\t\t}')]
"[a.name/]": {
[if (a.defaultValueLiteral)->notEmpty()]
"defaultValue": "[a.defaultValueLiteral/]",
[/if]
"parameterType" : "[a.eType.name/]",
"lowerBound" : [a.lowerBound/],
"upperBound" : [a.upperBound/]
}[/for]
[/if]
[if (class.eReferences->notEmpty())],
"references" : [for (r : EReference | class.eReferences) before ('{\n') separator(',\n') after ('\n\t\t\t}\n')]
"[r.name/]": {
"isContainment" :[r.containment/],
"lowerBound" : [r.lowerBound/],
"upperBound" : [r.upperBound/]
}[/for]
[else]
[/if]
}[/for]
}[/file]
[/template]
The template processes an ecore-package and creates well-formatted JSON at least for my .ecore file which I already provided in the original post.
Good luck!
|
|
|
|
Powered by
FUDForum. Page generated in 0.02296 seconds