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 Go to next message
J Bouwhuis is currently offline J BouwhuisFriend
Messages: 17
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>
Re: Adding EAttributes to EStructuralfeatures [message #1814612 is a reply to message #1807644] Fri, 13 September 2019 20:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6934
Registered: July 2009
Senior Member
Hi

Apologies for the very slow response.; the Thunderbird RSS feed only notified me an hour ago.

Unfortunately you provide numerous snippets of embedded text. My tools expect to see files, so you should provide your content as a zipped repro project including a launch configuration saved into the project. Use the Common Tab.

A superficial skim shows no forEach.

Regards

Ed Willink
Re: Adding EAttributes to EStructuralfeatures [message #1831369 is a reply to message #1807644] Tue, 18 August 2020 11:18 Go to previous message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 63
Registered: April 2011
Member
J Bouwhuis wrote on Wed, 05 June 2019 10:07

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

Hi, the for loop doesn't make sense. The square brackets are syntactic sugar representing an xselect expression (see 8.2.2.7 ImperativeIterateExp of the QVT specification). Essentially, your code translates into the following:

result.eStructuralFeatures += Set{eliteral.name}->xselect(oclIsKindOf(EAttribute));

As you can see, you are creating a singleton set comprising only the literal's name, which is a String. From this singleton set, you attempt to select only those elements that are of type EAttribute, which gives an empty set. This is why there are no attributes created. Try something like

result.eStructuralFeatures += object EAttribute {
        name := eliteral.name;
}

Or better, create an additional mapping from EEnumLiteral to EAttribute:

mapping EEnum :: eenum2resourcedemandVersion2 () : EClass {
	name := "ResouceDemand " + self.name;
	
        eStructuralFeatures += self.eLiterals->map eliteral2eattribute();
};

mapping EEnumLiteral :: eliteral2eattribute () : EAttribute {
	name := self.name;
};
Previous Topic:[QVTo] No constructor defined, using implicit constructor
Next Topic:Could not find unit 'platform:/resource
Goto Forum:
  


Current Time: Tue Dec 01 09:41:10 GMT 2020

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

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

Back to the top