|
|
Re: M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807180 is a reply to message #1807179] |
Fri, 24 May 2019 03:56   |
Eclipse User |
|
|
|
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!
|
|
|
Re: M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807186 is a reply to message #1807180] |
Fri, 24 May 2019 05:47  |
Eclipse User |
|
|
|
Hi
Wow, that was quick. Thak you for sharing. If you really want to be helpful to others you can provide a zipped project, or link to GitHub project. The project should contain an example input file and a launch configuration saved into the project using the Common Tab of the launch configuration. Then newbies can just load the project, run launch configuration, (read a readme), and see it working. There is probably an Acceleo Wiki page where you can publicize your facility.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.06204 seconds