Skip to content

Commit

Permalink
Prefer UML PrimitiveTypes over JAVA PrimitiveTypes
Browse files Browse the repository at this point in the history
- PcmUmlClassHelper.mapPrimitiveTypes returns now only one PrimitiveType instead of a set of matching Types. UML Primitive Types are used if available, the JAVA PrimitiveTypes are only used if no matching type is existent
- goal: make clear which PrimitiveType is used by the reaction (and avoid indeterminism)
- adapted some tests
  • Loading branch information
h4uges committed Sep 26, 2023
1 parent a580305 commit a42320d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Require-Bundle: org.eclipse.uml2.uml;visibility:=reexport,
org.palladiosimulator.pcm;visibility:=reexport,
edu.kit.ipd.sdq.activextendannotations,
edu.kit.ipd.sdq.commons.util.emf,
edu.kit.ipd.sdq.commons.util.java,
tools.vitruv.framework.applications,
tools.vitruv.dsls.reactions.runtime,
tools.vitruv.applications.util.temporary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ import org.palladiosimulator.pcm.system.System
import org.palladiosimulator.pcm.core.entity.Entity
import tools.vitruv.applications.util.temporary.other.CorrespondenceRetriever

import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimOne

@Utility
class PcmUmlClassHelper {

def static Iterable<PrimitiveType> mapPrimitiveTypes(PrimitiveDataType pcmPredefinedPrimitiveType,
def static PrimitiveType mapPrimitiveTypes(PrimitiveDataType pcmPredefinedPrimitiveType,
Iterable<PrimitiveType> umlPredefinedPrimitiveTypes) {
// Prefer UML Types over JAVA Types
return switch (pcmPredefinedPrimitiveType.type) {
case PrimitiveTypeEnum.BOOL: umlPredefinedPrimitiveTypes.filter[it.name.toLowerCase == "bool" || it.name.toLowerCase == "boolean"]
case PrimitiveTypeEnum.BYTE: umlPredefinedPrimitiveTypes.filter[it.name.toLowerCase == "byte"]
case PrimitiveTypeEnum.CHAR: umlPredefinedPrimitiveTypes.filter[it.name.toLowerCase == "char"]
case PrimitiveTypeEnum.INT: umlPredefinedPrimitiveTypes.filter[it.name.toLowerCase == "int" || it.name.toLowerCase == "integer"]
case PrimitiveTypeEnum.DOUBLE: umlPredefinedPrimitiveTypes.filter[it.name.toLowerCase == "double" || it.name.toLowerCase == "real"]
case PrimitiveTypeEnum.STRING: umlPredefinedPrimitiveTypes.filter[it.name.toLowerCase == "string"]
case PrimitiveTypeEnum.BOOL: umlPredefinedPrimitiveTypes.filter[it.name == "Boolean"].claimOne
case PrimitiveTypeEnum.BYTE: umlPredefinedPrimitiveTypes.filter[it.name == "byte"].claimOne
case PrimitiveTypeEnum.CHAR: umlPredefinedPrimitiveTypes.filter[it.name == "char"].claimOne
case PrimitiveTypeEnum.INT: umlPredefinedPrimitiveTypes.filter[it.name == "Integer"].claimOne
case PrimitiveTypeEnum.DOUBLE: umlPredefinedPrimitiveTypes.filter[it.name == "Real"].claimOne
case PrimitiveTypeEnum.STRING: umlPredefinedPrimitiveTypes.filter[it.name == "String"].claimOne
default: null
// uml::UnlimitedNatural are not mapped and the user is notified if one of these types is set
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ routine bootstrapPrimitiveDatatypes(pcm::Repository pcmRepo) {
val pcmPrimitiveTypes = PcmDataTypeUtil.getPcmPrimitiveTypes(pcmRepo)
val umlPrimitiveTypes = UmlTypeUtil.getUmlPrimitiveTypes(pcmRepo.eResource.resourceSet)
for (pcmType : pcmPrimitiveTypes) {
val umlTypes = PcmUmlClassHelper.mapPrimitiveTypes(pcmType, umlPrimitiveTypes)
for (umlType : umlTypes) {
addPrimitiveDatatypeCorrespondence(pcmType, umlType)
}
val umlType = PcmUmlClassHelper.mapPrimitiveTypes(pcmType, umlPrimitiveTypes)
addPrimitiveDatatypeCorrespondence(pcmType, umlType)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class AttributeConceptTest extends PcmUmlClassApplicationTest {
val pcmCollectionDataType = new FluentPCMCollectionDataTypeBuilder(
PcmUmlClassApplicationTestHelper.COLLECTION_DATATYPE_NAME, pcmCompositeDataType2).build

testCreateAttributeConcept_UML([it.name == "int"], 1, 1,
testCreateAttributeConcept_UML([it.name == "Integer"], 1, 1,
#[pcmCompositeDataType1, pcmCompositeDataType2, pcmCollectionDataType])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ParameterConceptTest extends PcmUmlClassApplicationTest {
val pcmInterface = new FluentPCMOperationInterfaceBuilder(PcmUmlClassApplicationTestHelper.INTERFACE_NAME).
addSignature(PcmUmlClassApplicationTestHelper.SIGNATURE_NAME,
#[new Pair(TEST_PARAMETER_NAME, pcmIntDataType)]).build
testCreateParameterConcept_UML([it.name == "int"], 1, 1,
testCreateParameterConcept_UML([it.name == "Integer"], 1, 1,
#[pcmCompositeDataType1, pcmCompositeDataType2, pcmCollectionDataType], pcmInterface)
}

Expand Down Expand Up @@ -181,7 +181,7 @@ class ParameterConceptTest extends PcmUmlClassApplicationTest {
it.filter[it instanceof PrimitiveDataType].findFirst [
(it as PrimitiveDataType).type == PrimitiveTypeEnum.INT
]
], "int", 1, 1)
], "Integer", 1, 1)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SignatureConceptTest extends PcmUmlClassApplicationTest {

_testCreateSignatureConceptUML()
_testReturnTypePropagation_UML(
[it instanceof PrimitiveType && (it as PrimitiveType).name == "int"],
[it instanceof PrimitiveType && (it as PrimitiveType).name == "Integer"],
1,
1,
[it instanceof PrimitiveDataType && (it as PrimitiveDataType).type == PrimitiveTypeEnum.INT]
Expand Down Expand Up @@ -188,7 +188,7 @@ class SignatureConceptTest extends PcmUmlClassApplicationTest {
createRepositoryWithInterface()
_testCreateSignatureConcept_PCM_withReturnType([
it instanceof PrimitiveDataType && (it as PrimitiveDataType).type == PrimitiveTypeEnum.INT
], 1, 1, [it.name == "int"])
], 1, 1, [it.name == "Integer"])
}

@Test
Expand Down

0 comments on commit a42320d

Please sign in to comment.