SysML Exporter: encoding of atomic data types
The SysML currently has two some shortcomings in the handling of atomic data types
-
Atomic data-types used for input/output ports of logical components (Component "AtomicTest") in the attached example SysML_Type_Test.af3_23 are not traced to SysML data types. Example for int"
<packagedElement xmi:type="uml:Class" xmi:id="_E-xCE53GEe6BbL6kUh0ULg" name="lvClass_AtomicTest" visibility="public">
<ownedAttribute xmi:type="uml:Port" xmi:id="_E-xCFJ3GEe6BbL6kUh0ULg" name="lvPort_inInt" visibility="public" aggregation="composite"/>
-
For annotations, the tracing of data types seems inconsistent, e.g. for tasks: - WCET: BigDecimal annotation of Task, mapped to a dataType_packagedElement_Integer, default value with uml:LiteralInteger
- RamRequirement: Long annotation of Task, mapped to a dataType_packagedElement_Complex, default value with uml:LiteralReal
- FlashRequirement: Long annotation of Task, mapped to a dataType_packagedElement_Integer, default value with uml:LiteralReal
<packagedElement xmi:type="uml:Class" xmi:id="_E-xCRJ3GEe6BbL6kUh0ULg" name="taClass_Task" visibility="public">
<ownedAttribute xmi:id="_E-xCRZ3GEe6BbL6kUh0ULg" name="FlashRequirement">
<type xmi:type="uml:DataType" href="platform:/plugin/org.eclipse.papyrus.sysml16/resources/library/SysML-Standard-Library.uml#SysML.package_packagedElement_Libraries.package_packagedElement_PrimitiveValueTypes.dataType_packagedElement_Integer"/>
<defaultValue xmi:type="uml:LiteralReal" xmi:id="_E-xCRp3GEe6BbL6kUh0ULg" value="100.0"/>
</ownedAttribute>
<ownedAttribute xmi:id="_E-xCR53GEe6BbL6kUh0ULg" name="RamRequirement">
<type xmi:type="uml:DataType" href="platform:/plugin/org.eclipse.papyrus.sysml16/resources/library/SysML-Standard-Library.uml#SysML.package_packagedElement_Libraries.package_packagedElement_PrimitiveValueTypes.dataType_packagedElement_Complex"/>
<defaultValue xmi:type="uml:LiteralReal" xmi:id="_E-xCSJ3GEe6BbL6kUh0ULg" value="200.0"/>
</ownedAttribute>
<ownedAttribute xmi:id="_E-xCSZ3GEe6BbL6kUh0ULg" name="WCET">
<type xmi:type="uml:DataType" href="platform:/plugin/org.eclipse.papyrus.sysml16/resources/library/SysML-Standard-Library.uml#SysML.package_packagedElement_Libraries.package_packagedElement_PrimitiveValueTypes.dataType_packagedElement_Integer"/>
<defaultValue xmi:type="uml:LiteralInteger" xmi:id="_E-xCSp3GEe6BbL6kUh0ULg" value="300"/>
</ownedAttribute>
</packagedElement>
-
Quite a lot of code duplications and magic constants in AF3SysMLToEMFMapping::addAnnotations*(), e.g. the following
FlashRequirement flashReq = getAnnotation(task, FlashRequirement.class);
if(flashReq != null && flashReq.getValue() != 0) {
Property flashReqProp = createUMLProperty("FlashRequirement", false, false);
flashReqProp.setRealDefaultValue(flashReq.getValue());
flashReqProp.setType((DataType)sysMLDataTypes.get(2));
taskClass.getOwnedAttributes().add(flashReqProp);
}
could be replaced by this, and further siblings of addLongAnnotation should be implemented (see branch 4355 https://git.fortiss.org/af3/af3/-/commits/4355)
/**
* Adds annotations for tasks, including {@link Comment}, {@link FlashSize}, {@link RamSize} and
* {@link Wcet} values.
*/
private void addAnnotationsTasks(Task task, Class taskClass) {
addComment(task, taskClass);
addLongAnnotation(task, taskClass, FlashRequirement.class, "FlashRequirement");
RamRequirement ramReq = getAnnotation(task, RamRequirement.class);
if(ramReq != null && ramReq.getValue() != 0) {
Property ramSizeProp = createUMLProperty("RamRequirement", false, false);
ramSizeProp.setRealDefaultValue(ramReq.getBytes());
ramSizeProp.setType((DataType)sysMLDataTypes.get(1));
taskClass.getOwnedAttributes().add(ramSizeProp);
}
Wcet wcet = getAnnotation(task, Wcet.class);
if(wcet != null && wcet.getValue() != null && !(wcet.getValue().toString().equals("0"))) {
Property wcetProp = createUMLProperty("WCET", false, false);
wcetProp.setIntegerDefaultValue(wcet.getValue().intValue());
wcetProp.setType((DataType)sysMLDataTypes.get(2));
taskClass.getOwnedAttributes().add(wcetProp);
}
}
private void addAnnotation(IModelElement modelElement, Class sysmlClass,
java.lang.Class<? extends IAnnotatedSpecification> anType, String anName,
EClass umlLiteral, java.lang.Class<? extends Number> javaType, int dataTypeIndex) {
Object value = AnnotationUtils.getAnnotationValue(modelElement, anType, javaType);
if(value != null) {
Property property = createUMLProperty(anName, false, false);
ValueSpecification defaultValue = property.getDefaultValue();
if(umlLiteral.equals(UMLPackage.Literals.LITERAL_REAL)) {
if(!(defaultValue instanceof LiteralReal)) {
defaultValue = property.createDefaultValue(null, null,
UMLPackage.Literals.LITERAL_REAL);
}
((LiteralReal)defaultValue).setValue(Double.valueOf(value.toString()));
} else {
// TODO (see
// https://git.eclipse.org/c/uml2/org.eclipse.uml2.git/plain/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/UMLPackage.java)
// LITERAL_INTEGER
// LITERAL_STRING
// LITERAL_BOOLEAN
// LITERAL_NULL ???
// LITERAL_SPECIFICATION ???
// LITERAL_UNLIMITED_NATURAL ???
}
// TODO: Is sysMLDataTypes and UMLPackage.Literals.* the same?
property.setType((DataType)sysMLDataTypes.get(dataTypeIndex));
sysmlClass.getOwnedAttributes().add(property);
}
}
private void addLongAnnotation(IModelElement modelElement, Class sysmlClass,
java.lang.Class<? extends IAnnotatedSpecification> anType, String anName) {
// TODO: Check if Long annotations should be encoded as LITERAL_REAL or LITERAL_INTEGER (or
// something else)
addAnnotation(modelElement, sysmlClass, anType, anName, UMLPackage.Literals.LITERAL_REAL,
Long.class, 2);
}
Edited by Konstantin Blaschke