import modelicaQVTUtils.ModelicaUtils; import org.omg.eclipse.sysml.UMLUtils; modeltype UML uses 'http://www.eclipse.org/uml2/3.0.0/UML'; modeltype AlgorithmItem uses 'http://www.openmodelica.org/openmodelica.unparsed/AlgorithmItem'; modeltype AlgorithmStatement uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/AlgorithmStatement'; modeltype Annotation uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Annotation'; modeltype ArrayDim uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ArrayDim'; modeltype Class uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Class'; modeltype ClassDef uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ClassDef'; modeltype ClassPart uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ClassPart'; modeltype Comment uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Comment'; modeltype Component uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Component'; modeltype ComponentCondition uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ComponentCondition'; modeltype ComponentItem uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ComponentItem'; modeltype ComponentRef uses 'http://www.openmodelica.org/openmodelica.unparsed/ComponentRef'; modeltype ConstrainClass uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ConstrainClass'; modeltype Direction uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Direction'; modeltype Each uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Each'; modeltype Element uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Element'; modeltype ElementArg uses 'http://www.openmodelica.org/openmodelica.unparsed/ElementArg'; modeltype ElementAttributes uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ElementAttributes'; modeltype ElementItem uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ElementItem'; modeltype ElementSpec uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ElementSpec'; modeltype EnumDef uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/EnumDef'; modeltype EnumLiteral uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/EnumLiteral'; modeltype Equation uses 'http://www.openmodelica.org/openmodelica.unparsed/Equation'; modeltype EquationItem uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/EquationItem'; modeltype Exp uses 'http://www.openmodelica.org/openmodelica.unparsed/Exp'; modeltype ExternalDecl uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ExternalDecl'; modeltype FunctionArgs uses 'http://www.openmodelica.org/openmodelica.unparsed/FunctionArgs'; modeltype Import uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Import'; modeltype InnerOuter uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/InnerOuter'; modeltype Iterators uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Iterators'; modeltype Modifications uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Modifications'; modeltype NamedArg uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/NamedArg'; modeltype Operator uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Operator'; modeltype Path uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Path'; modeltype Program uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Program'; modeltype RedeclareKeywords uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/RedeclareKeywords'; modeltype Restriction uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Restriction'; modeltype Subscript uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Subscript'; modeltype TypeSpec uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/TypeSpec'; modeltype Variability uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Variability'; modeltype Within uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Within'; transformation ModelicaUnparsed2ModelicaMO(in modelicaModel:Program); main() { var program : Program::PROGRAM = modelicaModel.rootObjects()![Program::PROGRAM]; // create Model createNewFile(program.classes![Class::CLASS].name + "AfterRT.mo"); // write to Model program.map toModelicaProgram(); // save Model closeFile(); log("Transformation ModelicaUnparsed2ModelicaMO finished"); // or use transformation.succedded() - creation of transformation instance } mapping Program::PROGRAM::toModelicaProgram() { self.classes[Class::CLASS]->map toSysML$ModelicaSpecializedClass(); } // *********************************** CLASS DEFINITION *********************************** // ****** Mapping Rule 16.1 ****** mapping Class::uClass::toSysML$ModelicaSpecializedClass() disjuncts Class::CLASS::toModelicaClass, // Mapping Rule 16.1.2 Class::CLASS::toModelicaModel, // Mapping Rule 16.1.3 Class::CLASS::toModelicaRecord, // Mapping Rule 16.1.4 Class::CLASS::toModelicaBlock, // Mapping Rule 16.1.5 Class::CLASS::toModelicaConnector, // Mapping Rule 16.1.6 Class::CLASS::toModelicaType, // Mapping Rule 16.1.7 Class::CLASS::toModelicaPackage, // Mapping Rule 16.1.8 Class::CLASS::toModelicaFunction{} // Mapping Rule 16.1.9 // ****** Mapping Rule 16.2 ****** mapping Class::CLASS::toModelicaClass() // Mapping Rule 16.2.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.2.3 when{self.restriction.oclIsKindOf(Restriction::R_CLASS);} { append2FileJava("class " + self.name + "\r\n"); // Mapping Rule 16.2.2 } // ****** Mapping Rule 16.3 ****** mapping Class::CLASS::toModelicaModel() // Mapping Rule 16.3.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.3.3 when{self.restriction.oclIsKindOf(Restriction::R_MODEL);} { append2FileJava("model " + self.name + "\r\n"); // Mapping rule 16.3.2 } // ****** Mapping Rule 16.4 ****** mapping Class::CLASS::toModelicaRecord() // Mapping Rule 16.4.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.4.3 when{self.restriction.oclIsKindOf(Restriction::R_RECORD);} { append2FileJava("record " + self.name + "\r\n"); // Mapping Rule 16.4.2 } // ****** Mapping Rule 16.5 ****** mapping Class::CLASS::toModelicaBlock() // Mapping Rule 16.5.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.5.3 when{self.restriction.oclIsKindOf(Restriction::R_BLOCK);} { append2FileJava("block " + self.name + "\r\n"); // Mapping Rule 16.5.2 } // ****** Mapping Rule 16.6 ****** mapping Class::CLASS::toModelicaConnector() // Mapping Rule 16.6.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.6.4 when{self.restriction.oclIsKindOf(Restriction::R_CONNECTOR) or self.restriction.oclIsKindOf(Restriction::R_EXP_CONNECTOR);} { if(self.restriction.oclIsKindOf(Restriction::R_EXP_CONNECTOR)) then{ append2FileJava("expandable "); // Mapping Rule 16.6.3 } endif; append2FileJava("connector " + self.name + "\r\n"); } // ****** Mapping Rule 16.7 ****** mapping Class::CLASS::toModelicaType() // Mapping Rule 16.7.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.7.3 when{self.restriction.oclIsKindOf(Restriction::R_TYPE);} { append2FileJava("type " + self.name + "\r\n"); // Mapping Rule 16.7.2 } // ****** Mapping Rule 16.8 ****** mapping Class::CLASS::toModelicaPackage() // Mapping Rule 16.8.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.8.3 when{self.restriction.oclIsKindOf(Restriction::R_PACKAGE);} { append2FileJava("package " + self.name + "\r\n"); // Mapping Rule 16.8.2 } // ****** Mapping Rule 16.9 ****** mapping Class::CLASS::toModelicaFunction() // Mapping Rule 16.9.1 inherits Class::CLASS::setClassDefinitionPrefix merges Class::CLASS::setClassDefinition // Mapping Rule 16.9.9 //Class::CLASS::setModelicaAlgorithms when{self.restriction.oclIsKindOf(Restriction::R_FUNCTION);} { append2FileJava("function " + self.name + "\r\n"); // input ... // output ... // protected ... // algorithm ... // externalLanguage var language : String = self.body![ClassDef::PARTS] // Mapping Rule 16.9.3 .classParts![ClassPart::EXTERNAL] // Mapping Rule 16.9.4 .externalDecl![ExternalDecl::EXTERNALDECL].lang; // Mapping Rule 16.9.7: externalLibrary attribute - to be implemented } // ****** Mapping Rule 16.1.10 ****** mapping Class::CLASS::setClassDefinitionPrefix() { init{ if(self.finalPrefix)then{ append2FileJava("final "); }endif; if(self.encapsulatedPrefix)then{ append2FileJava("encapsulated "); }endif; if(self.partialPrefix)then{ append2FileJava("partial "); }endif; } } // ****** Mapping Rule 16.1.10 ****** mapping Class::CLASS::setClassDefinition() { init{ self.body[ClassDef::PARTS] -> forEach (body){ var classParts : OrderedSet(ClassPart::PUBLIC) := body.classParts[ClassPart::PUBLIC]; var elementItems : Sequence(ElementItem::ELEMENTITEM) := classParts.contents[ElementItem::ELEMENTITEM]; elementItems-> forEach (elementItem){ elementItem.element[Element::ELEMENT].specification[ElementSpec::EXTENDS]->map toGeneralization(); } ; elementItems-> forEach (elementItem){ elementItem.element[Element::ELEMENT].specification[ElementSpec::IMPORT]->map toPackageImport(); } ; elementItems-> forEach (elementItem){ elementItem.element[Element::ELEMENT].specification[ElementSpec::COMPONENTS].map toModelicaComponent(); } ; } ; if(self.name.equalsIgnoreCase("TypeInteger"))then{ //log("stop"); }endif; var endStatementExists := true; self.body[ClassDef::DERIVED] -> forEach (derived_){ derived_->map toGeneralization2(); endStatementExists := false; } ; var isEnumeration : Boolean := false; var enumerationBody : ClassDef::ENUMERATION := self.body![ClassDef::ENUMERATION]; if(enumerationBody != null)then{ isEnumeration := true; }endif; if(self.restriction.oclIsKindOf(Restriction::R_TYPE))then{ if(enumerationBody != null)then{ append2FileJava(" = enumeration(\r\n"); self.body![ClassDef::ENUMERATION].enumLiterals![EnumDef::ENUMLITERALS].enumLiterals[EnumLiteral::ENUMLITERAL]-> forEach (enumerationLiteral){ var index :Integer = 1; var enumStringLiteral : String := enumerationLiteral._literal; if(enumStringLiteral != null)then{ append2FileJava(enumStringLiteral); index := index + 1; if(not self.body![ClassDef::ENUMERATION].enumLiterals![EnumDef::ENUMLITERALS].enumLiterals[EnumLiteral::ENUMLITERAL]->at(index).oclIsInvalid())then{ append2FileJava(",\r\n"); }endif; }endif; //enumerationLiteral.map toModelicaEnumLiteral(); }; }endif; }endif; // equations self.map setModelicaEquations(); // algorithms self.map setModelicaAlgorithms(); // connections self.map setModelicaConnections(); // go through subclasses var isFirst : Boolean := true; self.body![ClassDef::PARTS].classParts[ClassPart::PUBLIC] .contents[ElementItem::ELEMENTITEM] .element[Element::ELEMENT]->forEach ( elem ){ if(elem.specification.oclIsKindOf(ElementSpec::CLASSDEF))then{ if(isFirst) then{ append2FileJava("\r\n"); isFirst := false; }endif; }endif; elem.specification[ElementSpec::CLASSDEF] .class_[Class::CLASS]->map toSysML$ModelicaSpecializedClass(); }; // annotation self.body![ClassDef::PARTS].classParts[ClassPart::PUBLIC] .contents[ElementItem::ANNOTATIONITEM]-> forEach (annotationItem){ //log(annotations->at(2).repr()); append2FileJava(" annotation ("); var index :Integer = 1; var modifications := annotationItem.annotation_![Annotation::ANNOTATION].elementArgs[ElementArg::MODIFICATION]; modifications->forEach(modification){ var commentString : String := modification.unparsedElementArg->any(true); append2FileJava(commentString); index := index + 1; if(not modifications->at(index).oclIsInvalid())then{ append2FileJava(",\r\n"); }endif; }; append2FileJava(");\r\n"); } ; if(endStatementExists)then{ if(isEnumeration = true)then{ append2FileJava(")" + ";\r\n\r\n"); }else{ append2FileJava("end " + self.name + ";\r\n\r\n"); }endif; }endif; } } mapping ElementSpec::IMPORT::toPackageImport() // Mapping Rule 16.10.1 { var importStatement : String := self.import_![Import::NAMED_IMPORT].name; append2FileJava(importStatement); append2FileJava(";\r\n"); } // ****** Mapping Rule 16.10 ****** mapping ElementSpec::EXTENDS::toGeneralization() // Mapping Rule 16.10.1 { var upperClassName : String = getPathLastName(self.path); append2FileJava("extends " + upperClassName); // modification // Mapping Rule 16.10.4 var hasModifications : Boolean = false; if(self.elementArg[ElementArg::MODIFICATION]->size() > 0)then{ hasModifications := true; append2FileJava("("); }endif; var index : Integer = 1; self.elementArg[ElementArg::MODIFICATION]->forEach(modification){ append2FileJava(modification.unparsedElementArg); index := index + 1; if(not self.elementArg[ElementArg::MODIFICATION]->at(index).oclIsInvalid())then{ append2FileJava(", "); }endif; }; if(hasModifications = true)then{ append2FileJava(")"); }endif; append2FileJava(";\r\n"); // annotation... // Mapping Rule 16.10.5: visibility attribute - to be implemented // Mapping Rule 16.10.6: arraysize attribute - to be implemented } mapping ClassDef::DERIVED::toGeneralization2() // Mapping Rule 16.10.1 { var upperClassName : String = getPathLastName(self.typeSpec![TypeSpec::TPATH].path); append2FileJava("= " + upperClassName); // arraySize // Mapping Rule 16.10.4 var hasArraySize : Boolean = false; if(self.typeSpec[TypeSpec::TPATH].arrayDim[ArrayDim::ArrayDim].subscripts[Subscript::SUBSCRIPT].subScript->size() > 0)then{ hasArraySize := true; append2FileJava("["); }endif; var ArraySizeIndex : Integer = 1; self.typeSpec[TypeSpec::TPATH].arrayDim[ArrayDim::ArrayDim].subscripts[Subscript::SUBSCRIPT].subScript->forEach(expression){ if(ArraySizeIndex > 1)then{ append2FileJava(" "); }endif; append2FileJava(expression.unparsedExp); ArraySizeIndex := ArraySizeIndex + 1; }; if(hasArraySize = true)then{ append2FileJava("]"); }endif; // modification // Mapping Rule 16.10.4 var hasModifications : Boolean = false; if(self.arguments[ElementArg::MODIFICATION]->size() > 0)then{ hasModifications := true; append2FileJava("("); }endif; var index : Integer = 1; self.arguments[ElementArg::MODIFICATION]->forEach(modification){ append2FileJava(modification.unparsedElementArg); index := index + 1; if(not self.arguments[ElementArg::MODIFICATION]->at(index).oclIsInvalid())then{ append2FileJava(", "); }endif; }; if(hasModifications = true)then{ append2FileJava(")"); }endif; append2FileJava(";\r\n"); // annotation... // Mapping Rule 16.10.5: visibility attribute - to be implemented // Mapping Rule 16.10.6: arraysize attribute - to be implemented } // ****** Mapping Rule 16.11 ****** : ModelicaDer - to be implemented // ****** Mapping Rule 16.12 ****** : ConstrainedBy - to be implemented // ******************************** COMPONENT DECLARATIONS ******************************** mapping ElementSpec::COMPONENTS::toModelicaComponent() { //types prefixes // flow/stream var flowPrefix : Boolean = self .attributes![ElementAttributes::ATTR].flowPrefix; if(not flowPrefix.oclIsInvalid())then{ if(flowPrefix) then{ append2FileJava("flow "); }endif; }endif; var streamPrefix : Boolean = self .attributes![ElementAttributes::ATTR].streamPrefix; if(not flowPrefix.oclIsInvalid())then{ if(streamPrefix) then{ append2FileJava("stream "); }endif; }endif; // discrete/parameter/constant var variability : Variability::uVariability = self .attributes![ElementAttributes::ATTR].variability; if((not variability.oclIsInvalid()) and (not (variability = null)))then{ if(variability.oclIsKindOf(Variability::CONST)) then{ append2FileJava("constant "); } endif; if(variability.oclIsKindOf(Variability::DISCRETE)) then{ append2FileJava("discrete "); } endif; if(variability.oclIsKindOf(Variability::PARAM)) then{ append2FileJava("parameter "); } endif; }endif; // input/output var direction : Direction::uDirection = self .attributes![ElementAttributes::ATTR].direction; if((not direction.oclIsInvalid()) and (not (direction = null)))then{ if(direction.oclIsKindOf(Direction::INPUT)) then{ append2FileJava("input "); } endif; if(direction.oclIsKindOf(Direction::OUTPUT)) then{ append2FileJava("output "); } endif; }endif; //type specifier var componentTypeName : String := self.typeSpec![TypeSpec::TPATH] .path![Path::IDENT].name; append2FileJava(componentTypeName + " "); // component name var componentName : String := self .components![ComponentItem::COMPONENTITEM].component![Component::COMPONENT].name; append2FileJava(componentName); // modification var hasModifications : Boolean = false; if(self .components![ComponentItem::COMPONENTITEM] .component![Component::COMPONENT] .modification![Modifications::CLASSMOD].elementArgLst[ElementArg::MODIFICATION]->size() > 0)then{ hasModifications := true; append2FileJava("("); }endif; var index : Integer := 1; self .components![ComponentItem::COMPONENTITEM] .component![Component::COMPONENT] .modification![Modifications::CLASSMOD].elementArgLst[ElementArg::MODIFICATION]->forEach(modification){ append2FileJava(modification.unparsedElementArg); index := index + 1; if(not self .components![ComponentItem::COMPONENTITEM] .component![Component::COMPONENT] .modification![Modifications::CLASSMOD].elementArgLst[ElementArg::MODIFICATION]->at(index).oclIsInvalid())then{ append2FileJava(", "); }endif; }; if(hasModifications = true)then{ append2FileJava(")"); }endif; // component declaration equation var expression : Exp::uExp = self .components![ComponentItem::COMPONENTITEM].component![Component::COMPONENT] .modification![Modifications::CLASSMOD].expOption; if((not (expression = null)) and ( not expression.oclIsInvalid()))then{ if(not (expression.unparsedExp = null))then{ append2FileJava(" = " + expression.unparsedExp); }endif; }endif; // annotation self.components![ComponentItem::COMPONENTITEM].comment[Comment::COMMENT]-> forEach (comment){ append2FileJava(" annotation ("); var commentString : String := comment.annotation_[Annotation::ANNOTATION].elementArgs[ElementArg::MODIFICATION].unparsedElementArg->any(true); append2FileJava(commentString); append2FileJava(")"); }; append2FileJava(";\r\n"); } mapping Element::ELEMENT::toModelicaComponent2() { //types prefixes // flow/stream var flowPrefix : Boolean = self.specification![ElementSpec::COMPONENTS] .attributes![ElementAttributes::ATTR].flowPrefix; if(not flowPrefix.oclIsInvalid())then{ if(flowPrefix) then{ append2FileJava("flow "); }endif; }endif; var streamPrefix : Boolean = self.specification![ElementSpec::COMPONENTS] .attributes![ElementAttributes::ATTR].streamPrefix; if(not flowPrefix.oclIsInvalid())then{ if(streamPrefix) then{ append2FileJava("stream "); }endif; }endif; // discrete/parameter/constant var variability : Variability::uVariability = self.specification![ElementSpec::COMPONENTS] .attributes![ElementAttributes::ATTR].variability; if((not variability.oclIsInvalid()) and (not (variability = null)))then{ if(variability.oclIsKindOf(Variability::CONST)) then{ append2FileJava("constant "); } endif; if(variability.oclIsKindOf(Variability::DISCRETE)) then{ append2FileJava("discrete "); } endif; if(variability.oclIsKindOf(Variability::PARAM)) then{ append2FileJava("parameter "); } endif; }endif; // input/output var direction : Direction::uDirection = self.specification![ElementSpec::COMPONENTS] .attributes![ElementAttributes::ATTR].direction; if((not direction.oclIsInvalid()) and (not (direction = null)))then{ if(direction.oclIsKindOf(Direction::INPUT)) then{ append2FileJava("input "); } endif; if(direction.oclIsKindOf(Direction::OUTPUT)) then{ append2FileJava("output "); } endif; }endif; //type specifier var componentTypeName : String := self.specification![ElementSpec::COMPONENTS].typeSpec![TypeSpec::TPATH] .path![Path::IDENT].name; append2FileJava(componentTypeName + " "); // component name var componentName : String := self.specification![ElementSpec::COMPONENTS] .components![ComponentItem::COMPONENTITEM].component![Component::COMPONENT].name; append2FileJava(componentName); // modification var hasModifications : Boolean = false; if(self.specification![ElementSpec::COMPONENTS] .components![ComponentItem::COMPONENTITEM] .component![Component::COMPONENT] .modification![Modifications::CLASSMOD].elementArgLst[ElementArg::MODIFICATION]->size() > 0)then{ hasModifications := true; append2FileJava("("); }endif; var index : Integer = 1; self.specification![ElementSpec::COMPONENTS] .components![ComponentItem::COMPONENTITEM] .component![Component::COMPONENT] .modification![Modifications::CLASSMOD].elementArgLst[ElementArg::MODIFICATION]->forEach(modification){ var uComponentRef_ : uComponentRef= modification.componentRef; var componentRef : String = uComponentRef_.unparsedComponentRef; var value : String = modification .modification![Modifications::CLASSMOD].expOption.unparsedExp; var modificationStr : String := componentRef + "=" + value; append2FileJava(modificationStr); index := index + 1; if(not self.specification![ElementSpec::COMPONENTS] .components![ComponentItem::COMPONENTITEM] .component![Component::COMPONENT] .modification![Modifications::CLASSMOD].elementArgLst[ElementArg::MODIFICATION]->at(index).oclIsInvalid())then{ append2FileJava(", "); }endif; }; if(hasModifications = true)then{ append2FileJava(")"); }endif; // component declaration equation var expression : Exp::uExp = self.specification![ElementSpec::COMPONENTS] .components![ComponentItem::COMPONENTITEM].component![Component::COMPONENT] .modification![Modifications::CLASSMOD].expOption; if((not (expression = null)) and ( not expression.oclIsInvalid()))then{ if(not (expression.unparsedExp = null))then{ append2FileJava(" = " + expression.unparsedExp); }endif; }endif; append2FileJava(";\r\n"); } // **************************** EQUATION AND ALGORITHM SECTION **************************** // ****** Mapping Rule 19.2 ****** mapping Class::CLASS::setModelicaEquations() // Mapping Rule 19.2.1 { // mapping to constraints var equations : Integer := self.body[ClassDef::PARTS].classParts[ClassPart::EQUATIONS] // Mapping Rule 19.2.3 .contents[EquationItem::EQUATIONITEM].equation_ ->select(e : Equation::uEquation | e.oclIsKindOf(Equation::EQ_CONNECT) = false)->size() + self.body[ClassDef::PARTS].classParts[ClassPart::INITIALEQUATIONS] .contents[EquationItem::EQUATIONITEM].equation_ // Mapping Rule 19.2.4 ->select(e : Equation::uEquation | e.oclIsKindOf(Equation::EQ_CONNECT) = false)->size(); if(equations > 0 )then{ append2FileJava("equation\r\n"); self.body[ClassDef::PARTS].classParts[ClassPart::EQUATIONS] // Mapping Rule 19.2.3 .contents[EquationItem::EQUATIONITEM].equation_ ->select(e : Equation::uEquation | e.oclIsKindOf(Equation::EQ_CONNECT) = false) -> map toModelicaEquation(); self.body[ClassDef::PARTS].classParts[ClassPart::INITIALEQUATIONS] .contents[EquationItem::EQUATIONITEM].equation_ // Mapping Rule 19.2.4 ->select(e : Equation::uEquation | e.oclIsKindOf(Equation::EQ_CONNECT) = false) -> map toModelicaEquation(); }endif; } mapping Equation::uEquation::toModelicaEquation() { if(self.unparsedEquation != null)then{ append2FileJava(self.unparsedEquation); // is equal to null sometimes if(not self.unparsedEquation.endsWith(";"))then{ append2FileJava(";"); }endif; append2FileJava("\r\n"); }endif; } // ****** Mapping Rule 19.3 ****** mapping Class::CLASS::setModelicaAlgorithms() // Mapping Rule 19.3.1 { var algorithms : Integer := self.body[ClassDef::PARTS].classParts[ClassPart::ALGORITHMS] // Mapping Rule 19.3.3 .contents->size() + self.body[ClassDef::PARTS] // Mapping Rule 19.3.4 .classParts[ClassPart::INITIALALGORITHMS] .contents->size(); if(algorithms > 0 )then{ append2FileJava("algorithm\r\n"); // mapping to behaviors self.body[ClassDef::PARTS].classParts[ClassPart::ALGORITHMS] // Mapping Rule 19.3.3 .contents-> map toModelicaAlgorithm(false); self.body[ClassDef::PARTS] // Mapping Rule 19.3.4 .classParts[ClassPart::INITIALALGORITHMS] .contents-> map toModelicaAlgorithm(true); }endif; } mapping AlgorithmItem::uAlgorithmItem::toModelicaAlgorithm(in isInitial : Boolean) { if(self.unparsedAlgorithmItem != null)then{ append2FileJava(self.unparsedAlgorithmItem); // is sometimes equal to null! if(not self.unparsedAlgorithmItem.endsWith(";"))then{ append2FileJava(";"); }endif; append2FileJava("\r\n"); } else{ //log("check"); }endif; //safeStereotypeSetValue(result, ModelicaAlgorithm_stereotype, "isInitial", isInitial); // java.lang.reflect.InvocationTargetException // Caused by: java.lang.ClassCastException: The value of type 'class java.lang.Boolean' // must be of type 'org.eclipse.emf.ecore.impl.EDataTypeImpl@2487b1 (name: Blocks_Boolean) (instanceClassName: Blocks_Boolean) (serializable: true)' // BUG // java.StackOverflowError. } // ****** Mapping Rule 19.4 ****** mapping Class::CLASS::setModelicaConnections() // Mapping Rule 19.4.1 { var connections : Integer := self.body[ClassDef::PARTS].classParts[ClassPart::EQUATIONS] .contents[EquationItem::EQUATIONITEM].equation_[Equation::EQ_CONNECT] ->size(); if(connections > 0)then{ append2FileJava("equation\r\n"); // mapping to connectors self.body[ClassDef::PARTS].classParts[ClassPart::EQUATIONS] .contents[EquationItem::EQUATIONITEM].equation_[Equation::EQ_CONNECT] -> map toModelicaConnection(); }endif; } mapping Equation::EQ_CONNECT::toModelicaConnection() { append2FileJava(self.unparsedEquation); if(not self.unparsedEquation.endsWith(";"))then{ append2FileJava(";"); }endif; append2FileJava("\r\n"); } // *********************************** HELPER FUNCTIONS *********************************** -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper loadComponentRef(in componentReference : ComponentRef::uComponentRef) : String -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper loadExpression(in expression : Exp::uExp) : String; -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper loadFunctionArgs(in functionArgs : FunctionArgs::uFunctionArguments) : String -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper loadEquation(in equation : Equation::uEquation) : String -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper loadAlgorithmItem(in algorithmItem : AlgorithmItem::uAlgorithmItem) : String -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper createFile(in fileName : string) -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. helper append2FileJava(in content : String) { if(content != null)then{ append2File(content); }else{ //log("check"); }endif; } -- black-box helper defined in modelicaQVTUtils.ModelicaUtils. -- helper closeFile() helper loadElementArg(in elementArg : ElementArg::uElementArg) : String { // invoke Java black-box method return "TBD"; } helper getModelicaComponentTypeName (in element : Element::ELEMENT) : String { return element.specification![ElementSpec::COMPONENTS].typeSpec![TypeSpec::TPATH] .path![Path::IDENT].name; } helper getModelicaComponentName (in element : Element::ELEMENT) : String { return element.specification![ElementSpec::COMPONENTS] .components![ComponentItem::COMPONENTITEM].component![Component::COMPONENT].name; } helper getPathLastName(in path : Path::uPath ) : String { if(path.oclIsKindOf(Path::IDENT))then{ return path.oclAsType(Path::IDENT).name; }endif; if(path.oclIsKindOf(Path::QUALIFIED))then{ // name + path //var path2 := path.oclAsType(Path::QUALIFIED).path; return getPathLastName(path.oclAsType(Path::QUALIFIED).path); }endif; if(path.oclIsKindOf(Path::FULLYQUALIFIED))then{ // just path return getPathLastName(path.oclAsType(Path::FULLYQUALIFIED).path); }endif; return null; }