Skip to content

Commit 83869d2

Browse files
authored
Merge pull request #707 from Systems-Modeling/ST6RI-885
ST6RI-885 Usage should not be allowed to be typed by another usage
2 parents 03b9880 + 1f73247 commit 83869d2

9 files changed

Lines changed: 88 additions & 48 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ class KerMLValidator extends AbstractKerMLValidator {
562562

563563
@Check
564564
def checkFeature(Feature f){
565-
// TODO: Remove?
566-
val types = f.type;
565+
// Note: Use utility method to ensure types are not filtered out by redefinitions of getType.
566+
val types = FeatureUtil.getAllTypesOf(f);
567567
if (types !== null && types.isEmpty)
568568
error(INVALID_FEATURE_HAS_TYPE_MSG, f, SysMLPackage.eINSTANCE.feature_Type, INVALID_FEATURE_HAS_TYPE)
569569

org.omg.sysml.xpect.tests/src/org/omg/sysml/xpect/tests/validation/invalid/AttributeUsage_invalid.sysml.xt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,19 @@ package 'ValueProperty Example' {
4141
port p: P;
4242
}
4343
part def Vehicle {
44-
//* XPECT errors ---
45-
"An attribute must be typed by attribute definitions." at "attribute a : A;"
46-
"Features must have at least one type" at "attribute a : A;"
47-
--- */
44+
// XPECT errors ---> "An attribute must be typed by attribute definitions." at "attribute a : A;"
4845
attribute a : A;
4946
// XPECT errors --> "An attribute must be typed by attribute definitions." at "attribute b : A::a;"
5047
// XPECT warnings --> "Duplicate of inherited member name 'self' from DataValue, Part" at "attribute b : A::a;"
5148
attribute b : A::a;
52-
//* XPECT errors ---
53-
"An attribute must be typed by attribute definitions." at "attribute s : P;"
54-
"Features must have at least one type" at "attribute s : P;"
55-
--- */
49+
// XPECT errors ---> "An attribute must be typed by attribute definitions." at "attribute s : P;"
5650
attribute s : P;
5751
// XPECT errors --> "An attribute must be typed by attribute definitions." at "attribute un : A::p;"
5852
// XPECT warnings --> "Duplicate of inherited member name 'self' from DataValue, Port" at "attribute un : A::p;"
5953
attribute un: A::p;
60-
//* XPECT errors ---
61-
"An attribute must be typed by attribute definitions." at "attribute n: AB;"
62-
"Features must have at least one type" at "attribute n: AB;"
63-
--- */
54+
// XPECT errors ---> "An attribute must be typed by attribute definitions." at "attribute n: AB;"
6455
attribute n: AB;
65-
}
56+
}
6657
connection def AB {
6758
end : A;
6859
end : A;

org.omg.sysml.xpect.tests/src/org/omg/sysml/xpect/tests/validation/invalid/CalculationUsage_Invalid1.sysml.xt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,18 @@ package pkg {
5151
"Duplicate of inherited member name 'done' from Action, Part" at "calc f2 : A;"
5252
--- */
5353
calc f2: A;
54-
/* XPECT errors ---
55-
"A calculation must be typed by one calculation definition." at "calc f3 : f2;"
56-
"Features must have at least one type" at "calc f3 : f2;"
57-
--- */
54+
// XPECT errors ---> "A calculation must be typed by one calculation definition." at "calc f3 : f2;"
5855
//* XPECT warnings ---
5956
"Duplicate of inherited member name 'self' from Calculation, Part" at "calc f3 : f2;"
6057
"Duplicate of inherited member name 'start' from Action, Part" at "calc f3 : f2;"
6158
"Duplicate of inherited member name 'done' from Action, Part" at "calc f3 : f2;"
6259
--- */
6360
calc f3: f2;
64-
/* XPECT errors ---
65-
"A calculation must be typed by one calculation definition." at "calc f4 : A::f1;"
66-
"Features must have at least one type" at "calc f4 : A::f1;"
67-
--- */
61+
// XPECT errors ---> "A calculation must be typed by one calculation definition." at "calc f4 : A::f1;"
6862
calc f4: A::f1;
69-
/* XPECT errors ---
70-
"A calculation must be typed by one calculation definition." at "calc f5 : B;"
71-
--- */
63+
// XPECT errors ---> "A calculation must be typed by one calculation definition." at "calc f5 : B;"
7264
calc f5: B;
73-
/* XPECT errors ---
74-
"A calculation must be typed by one calculation definition." at "calc f6 : bb;"
75-
--- */
65+
// XPECT errors ---> "A calculation must be typed by one calculation definition." at "calc f6 : bb;"
7666
calc f6: bb;
7767
}
7868
}

org.omg.sysml.xpect.tests/src/org/omg/sysml/xpect/tests/validation/invalid/EnumerationUsage_invalid.sysml.xt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ package EnumerationUsage_invalid {
4444
attribute a3 : E, EE;
4545

4646
enum e1 : E;
47-
//* XPECT errors ---
48-
"An enumeration must be typed by one enumeration definition." at "enum e2 : A;"
49-
"Features must have at least one type" at "enum e2 : A;"
50-
---
51-
*/
47+
// XPECT errors ---> "An enumeration must be typed by one enumeration definition." at "enum e2 : A;"
5248
enum e2 : A;
5349
// XPECT errors --> "An enumeration must be typed by one enumeration definition." at "enum e3 : E, EE;"
5450
enum e3 : E, EE;

org.omg.sysml.xpect.tests/src/org/omg/sysml/xpect/tests/validation/invalid/InterfaceUsage_Invalid.sysml.xt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ package 'Interface Example' {
7171
interface opposite : Fuel connect
7272
x ::> tankAssy.fuelTankPort to
7373
y ::> eng.engineFuelPort;
74-
//*XPECT errors ---
75-
"An interface must be typed by interface definitions." at "interface opposite1 : fi connect eng.engineFuelPort to tankAssy.fuelTankPort;"
76-
"Features must have at least one type" at "interface opposite1 : fi connect eng.engineFuelPort to tankAssy.fuelTankPort;"
77-
---*/
74+
//XPECT errors ---> "An interface must be typed by interface definitions." at "interface opposite1 : fi connect eng.engineFuelPort to tankAssy.fuelTankPort;"
7875
interface opposite1 : fi connect eng.engineFuelPort to tankAssy.fuelTankPort;
7976
interface bad {
8077
//XPECT errors --> "An interface end must be a port." at "end part ::> tankAssy.fuel;"

org.omg.sysml.xpect.tests/src/org/omg/sysml/xpect/tests/validation/invalid/ItemUsage_invalid.sysml.xt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ package pkg {
5656
// XPECT errors ---> "An item must be typed by item definitions." at "item i5: PartDef::aPort;"
5757
// XPECT warnings --> "Duplicate of inherited member name 'self' from Item, Port" at "item i5: PartDef::aPort;"
5858
item i5: PartDef::aPort;
59-
/* XPECT errors ---
60-
"An item must be typed by item definitions." at "item i6: PartDef::aPart;"
61-
"Features must have at least one type" at "item i6: PartDef::aPart;"
62-
--- */
59+
// XPECT errors ---> "An item must be typed by item definitions." at "item i6: PartDef::aPart;"
6360
item i6: PartDef::aPart;
6461
// XPECT errors --> "An item must be typed by item definitions." at "item i7: PartDef, AttDef;"
6562
// XPECT warnings --> "Duplicate of inherited member name 'self' from DataValue, Part" at "item i7: PartDef, AttDef;"

org.omg.sysml.xpect.tests/src/org/omg/sysml/xpect/tests/validation/invalid/PartUsage_invalid.sysml.xt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ package pkg {
5656
// XPECT errors --> "A part must be typed by item definitions." at "part p5: PartDef::aPort;"
5757
// XPECT warnings --> "Duplicate of inherited member name 'self' from Part, Port" at "part p5: PartDef::aPort;"
5858
part p5: PartDef::aPort;
59-
//* XPECT errors ---
60-
"A part must be typed by item definitions." at "part p6: PartDef::aPart;"
61-
"Features must have at least one type" at "part p6: PartDef::aPart;"
62-
--- */
59+
// XPECT errors ---> "A part must be typed by item definitions." at "part p6: PartDef::aPart;"
6360
part p6: PartDef::aPart;
6461
// XPECT errors --> "A part must be typed by item definitions." at "part p7: PartDef, AttDef;"
6562
// XPECT warnings --> "Duplicate of inherited member name 'self' from DataValue, Part" at "part p7: PartDef, AttDef;"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//*
2+
XPECT_SETUP org.omg.sysml.xpect.tests.validation.invalid.SysMLTests
3+
ResourceSet {
4+
ThisFile {}
5+
File {from ="/library.kernel/Base.kerml"}
6+
File {from ="/library.kernel/Occurrences.kerml"}
7+
File {from ="/library.kernel/Objects.kerml"}
8+
File {from ="/library.kernel/Performances.kerml"}
9+
File {from ="/library.systems/Items.sysml"}
10+
File {from ="/library.systems/Parts.sysml"}
11+
File {from ="/library.systems/Actions.sysml"}
12+
}
13+
Workspace {
14+
JavaProject {
15+
SrcFolder {
16+
ThisFile {}
17+
File {from ="/library.kernel/Base.kerml"}
18+
File {from ="/library.kernel/Occurrences.kerml"}
19+
File {from ="/library.kernel/Objects.kerml"}
20+
File {from ="/library.kernel/Performances.kerml"}
21+
File {from ="/library.systems/Items.sysml"}
22+
File {from ="/library.systems/Parts.sysml"}
23+
File {from ="/library.systems/Actions.sysml"}
24+
}
25+
}
26+
}
27+
END_SETUP
28+
*/
29+
package UsageDefinition_invalid {
30+
attribute def A;
31+
attribute a;
32+
// XPECT errors ---> "A usage must be typed by definitions." at "ref a1 : a, A;"
33+
ref a1 : a, A;
34+
// XPECT errors ---> "A usage must be typed by definitions." at "ref a2 : a;"
35+
ref a2 : a;
36+
// XPECT errors ---> "An attribute must be typed by attribute definitions." at "attribute a3 : a;"
37+
attribute a3 : a;
38+
39+
item def I;
40+
item i;
41+
// XPECT errors ---> "A usage must be typed by definitions." at "ref i1 : i, I;"
42+
ref i1 : i, I;
43+
// XPECT errors ---> "A usage must be typed by definitions." at "ref i2 : i;"
44+
ref i2 : i;
45+
// XPECT errors ---> "An item must be typed by item definitions." at "item i3 : i;"
46+
item i3 : i;
47+
48+
part def P;
49+
part p;
50+
// XPECT errors ---> "A usage must be typed by definitions." at "ref p1 : p, P;"
51+
ref p1 : p, P;
52+
// XPECT errors ---> "A usage must be typed by definitions." at "ref p2 : p;"
53+
ref p2 : p;
54+
// XPECT errors ---> "A part must be typed by item definitions." at "part p3 : p;"
55+
part p3 : p;
56+
57+
action def Ac;
58+
action ac;
59+
// XPECT errors ---> "A usage must be typed by definitions." at "ref ac1 : ac, Ac;"
60+
ref ac1 : ac, Ac;
61+
// XPECT errors ---> "A usage must be typed by definitions." at "ref ac2 : ac;"
62+
ref ac2 : ac;
63+
// XPECT errors ---> "An action must be typed by action definitions." at "action ac3 : ac;"
64+
action ac3 : ac;
65+
}

org.omg.sysml.xtext/src/org/omg/sysml/xtext/validation/SysMLValidator.xtend

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ import org.omg.sysml.lang.sysml.FlowUsage
134134
import org.omg.sysml.lang.sysml.Relationship
135135
import org.omg.sysml.util.FeatureUtil
136136
import org.omg.sysml.util.UsageUtil
137+
import org.omg.sysml.lang.sysml.Classifier
137138

138139
/**
139140
* This class contains custom validation rules.
@@ -149,8 +150,10 @@ class SysMLValidator extends KerMLValidator {
149150
public static val INVALID_DEFINITION_VARIATION_SPECIALIZATION = "validateDefinitionVariationSpecialization"
150151
public static val INVALID_DEFINITION_VARIATION_SPECIALIZATION_MSG = "A variation must not specialize another variation."
151152

152-
public static val INVALID_USAGE_VARIATION_IS_ABSTRACT = "validateUsageVariationIsAbstract"
153-
public static val INVALID_USAGE_VARIATION_IS_ABSTRACT_MSG = "A variation must be abstract."
153+
public static val INVALID_USAGE_TYPE = "validateUsageType_"
154+
public static val INVALID_USAGE_TYPE_MSG = "A usage must be typed by definitions."
155+
public static val INVALID_USAGE_VARIATION_IS_ABSTRACT = "validateUsageVariationIsAbstract"
156+
public static val INVALID_USAGE_VARIATION_IS_ABSTRACT_MSG = "A variation must be abstract."
154157
public static val INVALID_USAGE_VARIATION_MEMBERSHIP = "validateUsageVariationMembership"
155158
public static val INVALID_USAGE_VARIATION_MEMBERSHIP_MSG = "An owned usage of a variation must be a variant."
156159
public static val INVALID_USAGE_VARIATION_SPECIALIZATION = "validateUsageVariationSpecialization"
@@ -476,6 +479,10 @@ class SysMLValidator extends KerMLValidator {
476479

477480
@Check
478481
def checkUsage(Usage usage) {
482+
// All types must be Classifiers
483+
if (!(usage instanceof AttributeUsage || usage instanceof OccurrenceUsage))
484+
checkAllTypes(usage, Classifier, INVALID_USAGE_TYPE_MSG, SysMLPackage.eINSTANCE.usage_Definition, INVALID_USAGE_TYPE)
485+
479486
// validateUsageIsReferential is satisfied automatically
480487

481488
if (usage.isVariation) {

0 commit comments

Comments
 (0)