Skip to content

Commit f7011e0

Browse files
authored
Merge pull request #618 from Systems-Modeling/ST6RI-819
ST6RI-819 Association end type constraint (KERML_-32)
2 parents 6f8298f + 9c48f21 commit f7011e0

3 files changed

Lines changed: 63 additions & 8 deletions

File tree

kerml/src/examples/KerML Spec Annex A Examples/A-3-5-TimingForStructures.kerml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ package TimingForStructuresExecution2 {
6262
private import Atoms::*;
6363
private import TimingForStructuresModelToBeExecuted2::*;
6464
private import Occurrences::HappensDuring;
65-
private import OneToOneConnectorsExecution::MyWheel1;
66-
private import OneToOneConnectorsExecution::MyWheel2;
6765
private import OneToOneConnectorsExecution::MyWheel;
68-
private import OneToOneConnectorsExecution::MyBikeFork1;
69-
private import OneToOneConnectorsExecution::MyBikeFork2;
7066
private import OneToOneConnectorsExecution::MyBikeFork;
67+
68+
struct MyWheel1 specializes OneToOneConnectorsExecution::MyWheel1;
69+
struct MyWheel2 specializes OneToOneConnectorsExecution::MyWheel2;
70+
struct MyBikeFork1 specializes OneToOneConnectorsExecution::MyBikeFork1;
71+
struct MyBikeFork2 specializes OneToOneConnectorsExecution::MyBikeFork2;
7172

7273
#atom
7374
assoc MyBike_During_Wheel1_Link specializes HappensDuring {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//*
2+
XPECT_SETUP org.omg.kerml.xpect.tests.parsing.KerMLParsingTest
3+
ResourceSet {
4+
ThisFile {}
5+
File {from ="/library/Base.kerml"}
6+
File {from ="/library/Links.kerml"}
7+
File {from ="/library/Occurrences.kerml"}
8+
File {from ="/library/Objects.kerml"}
9+
File {from ="/library/Performances.kerml"}
10+
}
11+
Workspace {
12+
JavaProject {
13+
SrcFolder {
14+
ThisFile {}
15+
File {from ="/library/Base.kerml"}
16+
File {from ="/library/Links.kerml"}
17+
File {from ="/library/Occurrences.kerml"}
18+
File {from ="/library/Objects.kerml"}
19+
File {from ="/library/Performances.kerml"}
20+
}
21+
}
22+
}
23+
END_SETUP
24+
*/
25+
package AssociationTest_EndTypes_invalid {
26+
class C1;
27+
class C2;
28+
class C3 specializes C1;
29+
30+
assoc A1 {
31+
end x : C1;
32+
// XPECT errors --> "An association end must have exactly one type" at "end y : C1, C2;"
33+
end y : C1, C2;
34+
}
35+
36+
assoc A2 specializes A1 {
37+
// XPECT errors --> "An association end must have exactly one type" at "end x : C2;"
38+
end x : C2;
39+
}
40+
41+
assoc A3 specializes A1 {
42+
end x : C3;
43+
}
44+
45+
}

org.omg.kerml.xtext/src/org/omg/kerml/xtext/validation/KerMLValidator.xtend

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ class KerMLValidator extends AbstractKerMLValidator {
211211

212212
public static val INVALID_ASSOCIATION_BINARY_SPECIALIZATION = "validateAssociationBinarySpecialization"
213213
public static val INVALID_ASSOCIATION_BINARY_SPECIALIZATION_MSG = "Cannot have more than two ends"
214+
public static val INVALID_ASSOCIATION_END_TYPES = "validateAssociationEndTypes"
215+
public static val INVALID_ASSOCIATION_END_TYPES_MSG = "An association end must have exactly one type"
214216
public static val INVALID_ASSOCIATION_RELATED_TYPES = "validateAssociationRelatedTypes"
215217
public static val INVALID_ASSOCIATION_RELATED_TYPES_MSG = "Must have at least two related elements"
216218
public static val INVALID_ASSOCIATION_STRUCTURE_INTERSECTION = "validateAssociationStructureIntersection"
@@ -767,12 +769,12 @@ class KerMLValidator extends AbstractKerMLValidator {
767769
def checkAssociation(Association a){
768770
// validateAssociationBinarySpecialization
769771
// NOTE: It is sufficient to check owned ends, since they will redefine ends from any supertypes.
770-
val associationEnds = TypeUtil.getOwnedEndFeaturesOf(a);
771-
if (associationEnds.size() > 2) {
772+
val ownedEndFeatures = TypeUtil.getOwnedEndFeaturesOf(a);
773+
if (ownedEndFeatures.size() > 2) {
772774
val binaryLinkType = SysMLLibraryUtil.getLibraryElement(a, "Links::BinaryLink") as Type
773775
if (a.conformsTo(binaryLinkType)) {
774-
for (var i = 2; i < associationEnds.size(); i++) {
775-
error(INVALID_ASSOCIATION_BINARY_SPECIALIZATION_MSG, associationEnds.get(i), null, INVALID_ASSOCIATION_BINARY_SPECIALIZATION)
776+
for (var i = 2; i < ownedEndFeatures.size(); i++) {
777+
error(INVALID_ASSOCIATION_BINARY_SPECIALIZATION_MSG, ownedEndFeatures.get(i), null, INVALID_ASSOCIATION_BINARY_SPECIALIZATION)
776778
}
777779
}
778780
}
@@ -784,6 +786,13 @@ class KerMLValidator extends AbstractKerMLValidator {
784786
error(INVALID_ASSOCIATION_RELATED_TYPES_MSG, a, SysMLPackage.eINSTANCE.relationship_RelatedElement, INVALID_ASSOCIATION_RELATED_TYPES)
785787
}
786788

789+
// validateAssociationEndTypes
790+
for (end: ownedEndFeatures) {
791+
if (end.type.size != 1) {
792+
error(INVALID_ASSOCIATION_END_TYPES_MSG, end, null, INVALID_ASSOCIATION_END_TYPES)
793+
}
794+
}
795+
787796
// validateAssociationStructureIntersection is automatically satisfied
788797
}
789798

0 commit comments

Comments
 (0)