Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Adding EAttributes to EStructuralfeatures
Adding EAttributes to EStructuralfeatures [message #1807644] Wed, 05 June 2019 14:07
J Bouwhuis is currently offline J BouwhuisFriend
Messages: 16
Registered: April 2019
Junior Member
Hi. I'm new to QVTo and I have created a QVTo transformation model which aims to map one metamodel to another (see 1st code block below). My problem is with the 'eenum2resourcedemandVersion2' mapping and its forEach loop. I use this loop in order to map each eLiteral attribute of the source model to an eAttribute in the target model. The thing is that the EClasses in the 'eenum2resourcedemandVersion2' mapping are created in the target model once i run the transformation, but the EAttributes that should be added with the forEach loop are not created in the target model once running the transformation; the EClasses appear just as empty EClasses with no EAttributes. I am clearly missing some part, but I am not sure what my transformation misses. I run my transformation with the input Diagram (called finalDSL) as can be seen in the second code block below.

1st code block (QVTo transformation model)
modeltype finalDSL uses 'http://www.xtext.org/example/mydsl/FinalDsl'; 
modeltype ecore uses ecore('http://www.eclipse.org/emf/2002/Ecore');
modeltype target uses 'http://www.xtext.org/example/mydsl/TargetDSL'; 

transformation NewTransformation(
	in sourceModel : ecore, out targetModel : target
);

main() {

	sourceModel.objects()[EPackage]->map Package2Package();

}

mapping EPackage :: Package2Package () : EPackage  {
	
	name := self.name;
	
	result.eClassifiers += self.eClassifiers[EEnum] 
	-> select(eClassifiers | eClassifiers.name.endsWith("MethodStatementEnum")) -> map eenum2resourcedemandVersion2 ();
	
	result.eClassifiers += self.eClassifiers[EClass]-> 
	select(eClassifiers | eClassifiers.name = "StructuredStatement");
	result.eClassifiers += self.eClassifiers[EClass]->
	select(eClassifiers | eClassifiers.name = "IfElseStatements"); 
	result.eClassifiers += self.eClassifiers[EClass]->
	select(eClassifiers | eClassifiers.name = "ForLoops");
}

mapping EEnum :: eenum2resourcedemandVersion2 () : EClass {
	result.name := "ResouceDemand " + self.name;
	
	self.eLiterals->forEach(eliteral){
		
	result.eStructuralFeatures +=  eliteral.name[EAttribute];
	};
}


2nd code block (model provided as input parameter when running transformation):
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="finalDsl" nsURI="http://www.xtext.org/example/mydsl/FinalDsl"
    nsPrefix="finalDsl">
  <eClassifiers xsi:type="ecore:EClass" name="Model">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="functions" upperBound="-1"
        eType="#//FunctionElement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="FunctionElement">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="statements" upperBound="-1"
        eType="#//StatementSequence" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="StatementSequence">
    <eStructuralFeatures xsi:type="ecore:EReference" name="statement" eType="#//Statement"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Statement"/>
  <eClassifiers xsi:type="ecore:EClass" name="SimpleStatement" eSuperTypes="#//Statement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="parameterValuationSequence"
        upperBound="-1" eType="#//ParameterValuationSequence" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="StructuredStatement" eSuperTypes="#//Statement"/>
  <eClassifiers xsi:type="ecore:EClass" name="CompoundStatement" eSuperTypes="#//Statement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="statements" upperBound="-1"
        eType="#//StatementSequence" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="IfElseStatements" eSuperTypes="#//StructuredStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="ifStatements" eType="#//IfStatements"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="elseStatement" eType="#//ElseStatement"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="IfStatements">
    <eStructuralFeatures xsi:type="ecore:EReference" name="expression" eType="#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="statements" upperBound="-1"
        eType="#//Statement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ElseStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="elseStatement" upperBound="-1"
        eType="#//Statement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ForLoops" eSuperTypes="#//StructuredStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="expression" eType="#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="forStatement" upperBound="-1"
        eType="#//Statement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassOperationStatement" eSuperTypes="#//SimpleStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="classOperationName" upperBound="-1"
        eType="#//ClassOperationName" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="LibraryInterFaceMethodStatement" eSuperTypes="#//SimpleStatement">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="interfaceMethods" unique="false"
        upperBound="-1" eType="#//libraryInterFaceMethodStatementEnum"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="LibraryPersistenceMethodStatement" eSuperTypes="#//SimpleStatement">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="persistenceMethods" unique="false"
        upperBound="-1" eType="#//libraryPersistenceMethodStatementEnum"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalPerMethods" eType="#//LibraryPersistenceMethodStatement"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalBusMethods" eType="#//LibraryBusinessMethodStatement"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="LibraryBusinessMethodStatement" eSuperTypes="#//SimpleStatement">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="method" unique="false"
        upperBound="-1" eType="#//libraryBusinessMethodStatementEnum"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalPerMethods" eType="#//LibraryPersistenceMethodStatement"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalBusMethods" eType="#//LibraryBusinessMethodStatement"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ParameterValuationSequence">
    <eStructuralFeatures xsi:type="ecore:EReference" name="parameterName" eType="#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="parameterValuation" upperBound="-1"
        eType="#//ParameterValuation" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ParameterValuation">
    <eStructuralFeatures xsi:type="ecore:EReference" name="parameterName" eType="#//Expression"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassAttributeName">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassOperationName">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="OperationParameterName">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="libraryPersistenceMethodStatementEnum">
    <eLiterals name="createInstance" literal="CreateInstance"/>
    <eLiterals name="log" value="1" literal="Log"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="libraryBusinessMethodStatementEnum">
    <eLiterals name="hash" literal="Hash"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="libraryInterFaceMethodStatementEnum">
    <eLiterals name="message" literal="Message"/>
    <eLiterals name="error" value="1" literal="Error"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Expression">
    <eStructuralFeatures xsi:type="ecore:EReference" name="simpleExpression" eType="#//SimpleExpression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalExpressions"
        upperBound="-1" eType="#//AdditionalExpressions" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="SimpleExpression">
    <eStructuralFeatures xsi:type="ecore:EReference" name="term" eType="#//Term" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalExpressions"
        upperBound="-1" eType="#//AdditionalSimpleExpressions" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="AdditionalExpressions">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="operator" eType="#//RelationalOperator"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="simpleExpression" eType="#//SimpleExpression"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="AdditionalSimpleExpressions">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="additionOperator" eType="#//AdditionOperator"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="term" eType="#//Term" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Term">
    <eStructuralFeatures xsi:type="ecore:EReference" name="factorTerm" eType="#//Factor"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalTerm" upperBound="-1"
        eType="#//AdditionalTerm" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="AdditionalTerm">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="multiplicationOperator"
        unique="false" upperBound="-1" eType="#//MultiplicationOperator"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="factor" eType="#//Factor"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Factor">
    <eStructuralFeatures xsi:type="ecore:EReference" name="factor" eType="#//FactorExpression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="libraryBusinessMethod"
        eType="#//LibraryBusinessMethodStatement" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="FactorExpression">
    <eStructuralFeatures xsi:type="ecore:EReference" name="expression" eType="#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="operationParameterName"
        eType="#//OperationParameterName" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="classAttributeName" eType="#//ClassAttributeName"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="set" eType="#//Set" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Set">
    <eStructuralFeatures xsi:type="ecore:EReference" name="elementList" eType="#//ElementList"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ElementList">
    <eStructuralFeatures xsi:type="ecore:EReference" name="expression" eType="#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="additionalExpression" upperBound="-1"
        eType="#//ElementListExpression" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ElementListExpression">
    <eStructuralFeatures xsi:type="ecore:EReference" name="expression" eType="#//Expression"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="RelationalOperator">
    <eLiterals name="greaterThan" literal=">"/>
    <eLiterals name="unequalTo" value="1" literal="&lt;>"/>
    <eLiterals name="smallerThan" value="2" literal="&lt;"/>
    <eLiterals name="greaterOrEqualThan" value="3" literal="=>"/>
    <eLiterals name="smallerOrEqualThan" value="4" literal="&lt;="/>
    <eLiterals name="equalTo" value="5" literal="="/>
    <eLiterals name="contains" value="6" literal="in"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="AdditionOperator">
    <eLiterals name="addition" literal="+"/>
    <eLiterals name="minus" value="1" literal="-"/>
    <eLiterals name="orOperator" value="2" literal="OR"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="MultiplicationOperator">
    <eLiterals name="multiplication" literal="*"/>
    <eLiterals name="division" value="1" literal="/"/>
    <eLiterals name="and" value="2" literal="AND"/>
  </eClassifiers>
</ecore:EPackage>


3d code block (output model produced when running transformation, which misses the EAttributes that should appear in the three EClasses that start their names with 'ResourceDemand')
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="finalDsl">
  <eClassifiers xsi:type="ecore:EClass" name="ResouceDemand libraryPersistenceMethodStatementEnum"/>
  <eClassifiers xsi:type="ecore:EClass" name="ResouceDemand libraryBusinessMethodStatementEnum"/>
  <eClassifiers xsi:type="ecore:EClass" name="ResouceDemand libraryInterFaceMethodStatementEnum"/>
  <eClassifiers xsi:type="ecore:EClass" name="StructuredStatement" eSuperTypes="FinalDsl.ecore#//Statement"/>
  <eClassifiers xsi:type="ecore:EClass" name="IfElseStatements" eSuperTypes="#//StructuredStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="ifStatements" eType="ecore:EClass FinalDsl.ecore#//IfStatements"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="elseStatement" eType="ecore:EClass FinalDsl.ecore#//ElseStatement"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ForLoops" eSuperTypes="#//StructuredStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="expression" eType="ecore:EClass FinalDsl.ecore#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="forStatement" upperBound="-1"
        eType="ecore:EClass FinalDsl.ecore#//Statement" containment="true"/>
  </eClassifiers>
</ecore:EPackage>
Previous Topic:Could not find unit 'platform:/resource
Next Topic:UML activity diagram to Simulink
Goto Forum:
  


Current Time: Sat Jul 20 16:49:30 GMT 2019

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

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

Back to the top