|
|
|
|
|
|
|
|
Re: Transforming Xtext DSL to XMI [message #1735676 is a reply to message #1735672] |
Tue, 21 June 2016 21:00 |
|
Hi,
i just have it a try and atl seems to work file with xtext models as input
(i started a new runtime workspace, created dsl files and atl stuff there)
(i am no atl guru and have no idea what i am doing)
demo.atl
-- @nsURI MM1=http://www.xtext.org/example/dsl/Trace
-- @nsURI MM=http://www.xtext.org/example/mydsl/MyDsl
-- @nsURI MM2=http://www.xtext.org/example/mapping/Mapping
module demo;
create OUT: MM from IN1: MM1, IN: MM2;
rule name {
from
fr: MM1!FormalResult
to
g: MM!Greeting (
name <- fr.name
),
g2: MM!Greeting (
name <- 'x'+fr.formalElements.at(1).formalElement.name
),
output_name: MM!Model (
greetings <- g,
greetings <- g2
)
}
rule FE2G {
from
fe: MM1!FormalElement
to
g: MM!Greeting (
)
}
demo.asm
<?xml version = '1.0' encoding = 'ISO-8859-1' ?>
<asm version="1.0" name="0">
<cp>
<constant value="demo"/>
<constant value="links"/>
<constant value="NTransientLinkSet;"/>
<constant value="col"/>
<constant value="J"/>
<constant value="main"/>
<constant value="A"/>
<constant value="OclParametrizedType"/>
<constant value="#native"/>
<constant value="Collection"/>
<constant value="J.setName(S):V"/>
<constant value="OclSimpleType"/>
<constant value="OclAny"/>
<constant value="J.setElementType(J):V"/>
<constant value="TransientLinkSet"/>
<constant value="A.__matcher__():V"/>
<constant value="A.__exec__():V"/>
<constant value="self"/>
<constant value="__resolve__"/>
<constant value="1"/>
<constant value="J.oclIsKindOf(J):B"/>
<constant value="18"/>
<constant value="NTransientLinkSet;.getLinkBySourceElement(S):QNTransientLink;"/>
<constant value="J.oclIsUndefined():B"/>
<constant value="15"/>
<constant value="NTransientLink;.getTargetFromSource(J):J"/>
<constant value="17"/>
<constant value="30"/>
<constant value="Sequence"/>
<constant value="2"/>
<constant value="A.__resolve__(J):J"/>
<constant value="QJ.including(J):QJ"/>
<constant value="QJ.flatten():QJ"/>
<constant value="e"/>
<constant value="value"/>
<constant value="resolveTemp"/>
<constant value="S"/>
<constant value="NTransientLink;.getNamedTargetFromSource(JS):J"/>
<constant value="name"/>
<constant value="__matcher__"/>
<constant value="A.__matchname():V"/>
<constant value="A.__matchFE2G():V"/>
<constant value="__exec__"/>
<constant value="NTransientLinkSet;.getLinksByRule(S):QNTransientLink;"/>
<constant value="A.__applyname(NTransientLink;):V"/>
<constant value="FE2G"/>
<constant value="A.__applyFE2G(NTransientLink;):V"/>
<constant value="__matchname"/>
<constant value="FormalResult"/>
<constant value="MM1"/>
<constant value="IN1"/>
<constant value="MMOF!Classifier;.allInstancesFrom(S):QJ"/>
<constant value="TransientLink"/>
<constant value="NTransientLink;.setRule(MATL!Rule;):V"/>
<constant value="fr"/>
<constant value="NTransientLink;.addSourceElement(SJ):V"/>
<constant value="g"/>
<constant value="Greeting"/>
<constant value="MM"/>
<constant value="NTransientLink;.addTargetElement(SJ):V"/>
<constant value="g2"/>
<constant value="output_name"/>
<constant value="Model"/>
<constant value="NTransientLinkSet;.addLink2(NTransientLink;B):V"/>
<constant value="13:3-15:4"/>
<constant value="16:3-18:4"/>
<constant value="19:3-22:4"/>
<constant value="__applyname"/>
<constant value="NTransientLink;"/>
<constant value="NTransientLink;.getSourceElement(S):J"/>
<constant value="NTransientLink;.getTargetElement(S):J"/>
<constant value="3"/>
<constant value="4"/>
<constant value="5"/>
<constant value="x"/>
<constant value="formalElements"/>
<constant value="J.at(J):J"/>
<constant value="formalElement"/>
<constant value="J.+(J):J"/>
<constant value="greetings"/>
<constant value="14:12-14:14"/>
<constant value="14:12-14:19"/>
<constant value="14:4-14:19"/>
<constant value="17:12-17:15"/>
<constant value="17:16-17:18"/>
<constant value="17:16-17:33"/>
<constant value="17:37-17:38"/>
<constant value="17:16-17:39"/>
<constant value="17:16-17:53"/>
<constant value="17:16-17:58"/>
<constant value="17:12-17:58"/>
<constant value="17:4-17:58"/>
<constant value="20:17-20:18"/>
<constant value="20:4-20:18"/>
<constant value="21:17-21:19"/>
<constant value="21:4-21:19"/>
<constant value="link"/>
<constant value="__matchFE2G"/>
<constant value="FormalElement"/>
<constant value="fe"/>
<constant value="29:3-30:4"/>
<constant value="__applyFE2G"/>
</cp>
<field name="1" type="2"/>
<field name="3" type="4"/>
<operation name="5">
<context type="6"/>
<parameters>
</parameters>
<code>
<getasm/>
<push arg="7"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="9"/>
<pcall arg="10"/>
<dup/>
<push arg="11"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="12"/>
<pcall arg="10"/>
<pcall arg="13"/>
<set arg="3"/>
<getasm/>
<push arg="14"/>
<push arg="8"/>
<new/>
<set arg="1"/>
<getasm/>
<pcall arg="15"/>
<getasm/>
<pcall arg="16"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="0" name="17" begin="0" end="24"/>
</localvariabletable>
</operation>
<operation name="18">
<context type="6"/>
<parameters>
<parameter name="19" type="4"/>
</parameters>
<code>
<load arg="19"/>
<getasm/>
<get arg="3"/>
<call arg="20"/>
<if arg="21"/>
<getasm/>
<get arg="1"/>
<load arg="19"/>
<call arg="22"/>
<dup/>
<call arg="23"/>
<if arg="24"/>
<load arg="19"/>
<call arg="25"/>
<goto arg="26"/>
<pop/>
<load arg="19"/>
<goto arg="27"/>
<push arg="28"/>
<push arg="8"/>
<new/>
<load arg="19"/>
<iterate/>
<store arg="29"/>
<getasm/>
<load arg="29"/>
<call arg="30"/>
<call arg="31"/>
<enditerate/>
<call arg="32"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="2" name="33" begin="23" end="27"/>
<lve slot="0" name="17" begin="0" end="29"/>
<lve slot="1" name="34" begin="0" end="29"/>
</localvariabletable>
</operation>
<operation name="35">
<context type="6"/>
<parameters>
<parameter name="19" type="4"/>
<parameter name="29" type="36"/>
</parameters>
<code>
<getasm/>
<get arg="1"/>
<load arg="19"/>
<call arg="22"/>
<load arg="19"/>
<load arg="29"/>
<call arg="37"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="0" name="17" begin="0" end="6"/>
<lve slot="1" name="34" begin="0" end="6"/>
<lve slot="2" name="38" begin="0" end="6"/>
</localvariabletable>
</operation>
<operation name="39">
<context type="6"/>
<parameters>
</parameters>
<code>
<getasm/>
<pcall arg="40"/>
<getasm/>
<pcall arg="41"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="0" name="17" begin="0" end="3"/>
</localvariabletable>
</operation>
<operation name="42">
<context type="6"/>
<parameters>
</parameters>
<code>
<getasm/>
<get arg="1"/>
<push arg="38"/>
<call arg="43"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="44"/>
<enditerate/>
<getasm/>
<get arg="1"/>
<push arg="45"/>
<call arg="43"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="46"/>
<enditerate/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="33" begin="5" end="8"/>
<lve slot="1" name="33" begin="15" end="18"/>
<lve slot="0" name="17" begin="0" end="19"/>
</localvariabletable>
</operation>
<operation name="47">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="48"/>
<push arg="49"/>
<findme/>
<push arg="50"/>
<call arg="51"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="52"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="38"/>
<pcall arg="53"/>
<dup/>
<push arg="54"/>
<load arg="19"/>
<pcall arg="55"/>
<dup/>
<push arg="56"/>
<push arg="57"/>
<push arg="58"/>
<new/>
<pcall arg="59"/>
<dup/>
<push arg="60"/>
<push arg="57"/>
<push arg="58"/>
<new/>
<pcall arg="59"/>
<dup/>
<push arg="61"/>
<push arg="62"/>
<push arg="58"/>
<new/>
<pcall arg="59"/>
<pusht/>
<pcall arg="63"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="64" begin="19" end="24"/>
<lne id="65" begin="25" end="30"/>
<lne id="66" begin="31" end="36"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="54" begin="6" end="38"/>
<lve slot="0" name="17" begin="0" end="39"/>
</localvariabletable>
</operation>
<operation name="67">
<context type="6"/>
<parameters>
<parameter name="19" type="68"/>
</parameters>
<code>
<load arg="19"/>
<push arg="54"/>
<call arg="69"/>
<store arg="29"/>
<load arg="19"/>
<push arg="56"/>
<call arg="70"/>
<store arg="71"/>
<load arg="19"/>
<push arg="60"/>
<call arg="70"/>
<store arg="72"/>
<load arg="19"/>
<push arg="61"/>
<call arg="70"/>
<store arg="73"/>
<load arg="71"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="38"/>
<call arg="30"/>
<set arg="38"/>
<pop/>
<load arg="72"/>
<dup/>
<getasm/>
<push arg="74"/>
<load arg="29"/>
<get arg="75"/>
<pushi arg="19"/>
<call arg="76"/>
<get arg="77"/>
<get arg="38"/>
<call arg="78"/>
<call arg="30"/>
<set arg="38"/>
<pop/>
<load arg="73"/>
<dup/>
<getasm/>
<load arg="71"/>
<call arg="30"/>
<set arg="79"/>
<dup/>
<getasm/>
<load arg="72"/>
<call arg="30"/>
<set arg="79"/>
<pop/>
</code>
<linenumbertable>
<lne id="80" begin="19" end="19"/>
<lne id="81" begin="19" end="20"/>
<lne id="82" begin="17" end="22"/>
<lne id="64" begin="16" end="23"/>
<lne id="83" begin="27" end="27"/>
<lne id="84" begin="28" end="28"/>
<lne id="85" begin="28" end="29"/>
<lne id="86" begin="30" end="30"/>
<lne id="87" begin="28" end="31"/>
<lne id="88" begin="28" end="32"/>
<lne id="89" begin="28" end="33"/>
<lne id="90" begin="27" end="34"/>
<lne id="91" begin="25" end="36"/>
<lne id="65" begin="24" end="37"/>
<lne id="92" begin="41" end="41"/>
<lne id="93" begin="39" end="43"/>
<lne id="94" begin="46" end="46"/>
<lne id="95" begin="44" end="48"/>
<lne id="66" begin="38" end="49"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="56" begin="7" end="49"/>
<lve slot="4" name="60" begin="11" end="49"/>
<lve slot="5" name="61" begin="15" end="49"/>
<lve slot="2" name="54" begin="3" end="49"/>
<lve slot="0" name="17" begin="0" end="49"/>
<lve slot="1" name="96" begin="0" end="49"/>
</localvariabletable>
</operation>
<operation name="97">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="98"/>
<push arg="49"/>
<findme/>
<push arg="50"/>
<call arg="51"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="52"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="45"/>
<pcall arg="53"/>
<dup/>
<push arg="99"/>
<load arg="19"/>
<pcall arg="55"/>
<dup/>
<push arg="56"/>
<push arg="57"/>
<push arg="58"/>
<new/>
<pcall arg="59"/>
<pusht/>
<pcall arg="63"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="100" begin="19" end="24"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="99" begin="6" end="26"/>
<lve slot="0" name="17" begin="0" end="27"/>
</localvariabletable>
</operation>
<operation name="101">
<context type="6"/>
<parameters>
<parameter name="19" type="68"/>
</parameters>
<code>
<load arg="19"/>
<push arg="99"/>
<call arg="69"/>
<store arg="29"/>
<load arg="19"/>
<push arg="56"/>
<call arg="70"/>
<store arg="71"/>
<load arg="71"/>
<pop/>
</code>
<linenumbertable>
<lne id="100" begin="8" end="9"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="56" begin="7" end="9"/>
<lve slot="2" name="99" begin="3" end="9"/>
<lve slot="0" name="17" begin="0" end="9"/>
<lve slot="1" name="96" begin="0" end="9"/>
</localvariabletable>
</operation>
</asm>
xxx.launch
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2m.atl.adt.launching.atlTransformation">
<stringAttribute key="ATL File Name" value="/demo.atl/demo.atl"/>
<stringAttribute key="ATL VM" value="EMF-specific VM"/>
<stringAttribute key="ATL_COMPILER" value="atl2006"/>
<booleanAttribute key="IS_REFINING" value="false"/>
<mapAttribute key="Input">
<mapEntry key="IN" value="MM2"/>
<mapEntry key="IN1" value="MM1"/>
</mapAttribute>
<mapAttribute key="Libs"/>
<mapAttribute key="Model Handler">
<mapEntry key="MM" value="EMF"/>
<mapEntry key="MM1" value="EMF"/>
<mapEntry key="MM2" value="EMF"/>
</mapAttribute>
<mapAttribute key="ModelType">
<mapEntry key="IN" value="MODELINPUT"/>
<mapEntry key="IN1" value="MODELINPUT"/>
<mapEntry key="MM" value="METAMODELOUTPUT"/>
<mapEntry key="MM1" value="METAMODELINPUT"/>
<mapEntry key="MM2" value="METAMODELINPUT"/>
<mapEntry key="OUT" value="MODELOUTPUT"/>
</mapAttribute>
<mapAttribute key="Options">
<mapEntry key="OPTION_CLEAR" value="false"/>
<mapEntry key="OPTION_CONTENT_TYPE" value="false"/>
<mapEntry key="OPTION_DERIVED" value="true"/>
<mapEntry key="allowInterModelReferences" value="false"/>
<mapEntry key="printExecutionTime" value="false"/>
<mapEntry key="step" value="false"/>
<mapEntry key="supportUML2Stereotypes" value="false"/>
</mapAttribute>
<listAttribute key="OrderedInput">
<listEntry value="IN1"/>
<listEntry value="IN"/>
</listAttribute>
<listAttribute key="OrderedOutput">
<listEntry value="OUT"/>
</listAttribute>
<mapAttribute key="Output">
<mapEntry key="OUT" value="MM"/>
</mapAttribute>
<mapAttribute key="Path">
<mapEntry key="IN" value="/demo.atl/b.mapping"/>
<mapEntry key="IN1" value="/demo.atl/a.trace"/>
<mapEntry key="MM" value="uri:http://www.xtext.org/example/mydsl/MyDsl"/>
<mapEntry key="MM1" value="uri:http://www.xtext.org/example/dsl/Trace"/>
<mapEntry key="MM2" value="uri:http://www.xtext.org/example/mapping/Mapping"/>
<mapEntry key="OUT" value="/demo.atl/result.mydsl"/>
</mapAttribute>
<listAttribute key="Superimpose"/>
<stringAttribute key="bad_container_name" value="/demo.atlx"/>
</launchConfiguration>
if you need xmi anyway? do you want to have a xmi for both inputs or only for one?
in your code you attempt to transform only one
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Transforming Xtext DSL to XMI [message #1735678 is a reply to message #1735677] |
Tue, 21 June 2016 21:19 |
|
here some extremely dirty code for xmi
package org.xtext.example.plugin.popup.actions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
import com.google.common.collect.Lists;
public class DSLReader {
public static void transformXTextToXMI(String catalogueRefactoringDslFileToBeRead,
String applicationDslFileToBeRead, Shell shell) {
IResourceSetProvider rsp = IResourceServiceProvider.Registry.INSTANCE
.getResourceServiceProvider(URI.createURI("dummy.trace")).get(IResourceSetProvider.class);
ResourceSet resourceSet = rsp.get(ResourcesPlugin.getWorkspace().getRoot().getProject("DSLExample"));
Resource xtextResource = resourceSet.getResource(URI.createURI("platform:/resource/DSLExample/sample.trace"),
true);
EcoreUtil.resolveAll(resourceSet);
List<Resource> xmiResources = new ArrayList<>();
for (Resource r : Lists.newArrayList(resourceSet.getResources())) {
Resource xmiResource = resourceSet
.createResource(URI.createURI("platform:/resource/DSLExample/"+r.getURI().trimFileExtension().lastSegment()+".xmi"));
// FormalResult model = (FormalResult)
// xtextResource.getContents().get(0);
xmiResource.getContents().add(r.getContents().get(0));
xmiResources.add(xmiResource);
}
for (Resource xmiResource : xmiResources) {
try {
xmiResource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.02537 seconds