18
18
* @see <a href="https://www.jetbrains.com/help/mps/structure.html#conceptmembers">MPS equivalent <i>Concept members</i> in documentation</a>
19
19
* @see org.jetbrains.mps.openapi.language.SConceptFeature MPS equivalent <i>SConceptFeature</i> in SModel
20
20
*/
21
- public abstract class Feature <T extends M3Node > extends M3Node <T > implements NamespacedEntity {
22
- @ Experimental
23
- private boolean derived ;
21
+ public abstract class Feature <T extends M3Node > extends M3Node <T > implements NamespacedEntity , HasKey <T > {
24
22
25
23
public Feature () {
26
-
24
+ setDerived ( false );
27
25
}
28
26
29
27
public Feature (@ Nullable String simpleName , @ Nonnull String id ) {
30
28
this (simpleName , null , id );
29
+ setDerived (false );
31
30
}
32
31
33
32
public Feature (@ Nullable String simpleName , @ Nullable FeaturesContainer container , @ Nonnull String id ) {
33
+ setDerived (false );
34
34
Objects .requireNonNull (id , "id should not be null" );
35
35
this .setID (id );
36
36
// TODO verify that the container is also a NamespaceProvider
37
37
// TODO enforce uniqueness of the name within the FeauturesContainer
38
38
setSimpleName (simpleName );
39
- setContainer (container );
39
+ setParent (container );
40
40
}
41
+
41
42
public Feature (@ Nullable String simpleName , @ Nullable FeaturesContainer container ) {
43
+ setDerived (false );
42
44
// TODO verify that the container is also a NamespaceProvider
43
45
// TODO enforce uniqueness of the name within the FeauturesContainer
44
46
setSimpleName (simpleName );
45
- setContainer (container );
47
+ setParent (container );
46
48
}
47
49
48
50
public boolean isOptional () {
@@ -60,12 +62,12 @@ public T setOptional(boolean optional) {
60
62
61
63
@ Experimental
62
64
public boolean isDerived () {
63
- return derived ;
65
+ return getPropertyValue ( " derived" , Boolean . class ) ;
64
66
}
65
67
66
68
@ Experimental
67
69
public T setDerived (boolean derived ) {
68
- this . derived = derived ;
70
+ setPropertyValue ( " derived" , derived ) ;
69
71
return (T )this ;
70
72
}
71
73
@@ -78,17 +80,36 @@ public void setSimpleName(@Nullable String simpleName) {
78
80
this .setPropertyValue ("simpleName" , simpleName );
79
81
}
80
82
83
+ /**
84
+ * The container is always the parent. It is just casted for convenience.
85
+ */
81
86
@ Override
82
87
public @ Nullable NamespaceProvider getContainer () {
83
- return getReferenceSingleValue ("container" );
84
- }
85
-
86
- public void setContainer (@ Nullable FeaturesContainer container ) {
87
- if (container == null ) {
88
- this .setReferenceSingleValue ("container" , null );
88
+ if (this .getParent () == null ) {
89
+ return null ;
90
+ }
91
+ if (this .getParent () instanceof NamespaceProvider ) {
92
+ return (NamespaceProvider ) this .getParent ();
89
93
} else {
90
- this . setReferenceSingleValue ( "container" , new ReferenceValue ( container , container . getSimpleName ()) );
94
+ throw new IllegalStateException ( "The parent is not a NamespaceProvider" );
91
95
}
92
96
}
93
97
98
+ @ Override
99
+ public String getKey () {
100
+ return this .getPropertyValue ("key" , String .class );
101
+ }
102
+
103
+ @ Override
104
+ public T setKey (String key ) {
105
+ setPropertyValue ("key" , key );
106
+ return (T ) this ;
107
+ }
108
+
109
+ protected Object getDerivedValue (Property property ) {
110
+ if (property .getKey ().equals (this .getConcept ().getPropertyByName ("qualifiedName" ).getKey ())) {
111
+ return qualifiedName ();
112
+ }
113
+ return null ;
114
+ }
94
115
}
0 commit comments