From a42320d71309aa177175e952cb98f93944c522d7 Mon Sep 17 00:00:00 2001 From: Simon Haug Date: Tue, 26 Sep 2023 11:46:35 +0200 Subject: [PATCH] Prefer UML PrimitiveTypes over JAVA PrimitiveTypes - 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 --- .../META-INF/MANIFEST.MF | 1 + .../pcmumlclass/PcmUmlClassHelper.xtend | 17 ++++++++++------- .../pcmumlclass/pcm2uml/PcmRepository.reactions | 6 ++---- .../tests/AttributeConceptTest.xtend | 2 +- .../tests/ParameterConceptTest.xtend | 4 ++-- .../tests/SignatureConceptTest.xtend | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/bundles/tools.vitruv.applications.pcmumlclass/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.pcmumlclass/META-INF/MANIFEST.MF index 283421731..e85be7aca 100644 --- a/bundles/tools.vitruv.applications.pcmumlclass/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.applications.pcmumlclass/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/PcmUmlClassHelper.xtend b/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/PcmUmlClassHelper.xtend index 51603fb38..eefb6e73e 100644 --- a/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/PcmUmlClassHelper.xtend +++ b/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/PcmUmlClassHelper.xtend @@ -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 mapPrimitiveTypes(PrimitiveDataType pcmPredefinedPrimitiveType, + def static PrimitiveType mapPrimitiveTypes(PrimitiveDataType pcmPredefinedPrimitiveType, Iterable 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 } diff --git a/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/pcm2uml/PcmRepository.reactions b/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/pcm2uml/PcmRepository.reactions index 8d13a3569..5b3208aae 100644 --- a/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/pcm2uml/PcmRepository.reactions +++ b/bundles/tools.vitruv.applications.pcmumlclass/src/tools/vitruv/applications/pcmumlclass/pcm2uml/PcmRepository.reactions @@ -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) } } } diff --git a/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/AttributeConceptTest.xtend b/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/AttributeConceptTest.xtend index dc0d82ee0..7871868f7 100644 --- a/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/AttributeConceptTest.xtend +++ b/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/AttributeConceptTest.xtend @@ -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]) } diff --git a/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/ParameterConceptTest.xtend b/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/ParameterConceptTest.xtend index 805d2d5a7..ec4b2f4f7 100644 --- a/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/ParameterConceptTest.xtend +++ b/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/ParameterConceptTest.xtend @@ -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) } @@ -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 diff --git a/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/SignatureConceptTest.xtend b/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/SignatureConceptTest.xtend index 189b5a595..fab077a61 100644 --- a/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/SignatureConceptTest.xtend +++ b/tests/tools.vitruv.applications.pcmumlclass.tests/src/tools/vitruv/applications/pcmumlclass/tests/SignatureConceptTest.xtend @@ -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] @@ -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