@emfts/codegen 0.0.2-next.4 → 0.0.2-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,7 +109,13 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
109
109
  <% } -%>
110
110
 
111
111
  // Private fields
112
- <% for (const genFeature of features) {
112
+ <%
113
+ // unsettable="true" (#45): eIsSet must distinguish "never set" from "set to
114
+ // the default", so the state lives in a separate flag - like Java EMF's ESet
115
+ function isUnsettableFeature(f) {
116
+ return !isMany(f) && (f.isUnsettable?.() ?? false);
117
+ }
118
+ for (const genFeature of features) {
113
119
  const feature = genFeature.ecoreFeature;
114
120
  const featureName = getName(feature);
115
121
  const featureType = typeMapper.mapFeature(feature);
@@ -117,6 +123,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
117
123
  const featureIsMany = isMany(feature);
118
124
  -%>
119
125
  private _<%- featureName %><% if (useEList && featureIsMany) { %>!<% } else if (!featureIsMany && defaultValue === null) { %>?<% } %>: <%- featureType %><% if (defaultValue !== null) { %> = <%- defaultValue %><% } %>;
126
+ <% if (isUnsettableFeature(feature)) { -%>
127
+ private _<%- featureName %>IsSet = false;
128
+ <% } -%>
120
129
  <% } -%>
121
130
  <% for (const mf of (mixinFeatures || [])) {
122
131
  const featureType = typeMapper.mapFeature(mf.feature);
@@ -124,6 +133,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
124
133
  const featureIsMany = isMany(mf.feature);
125
134
  -%>
126
135
  private _<%- mf.name %><% if (useEList && featureIsMany) { %>!<% } else if (!featureIsMany && defaultValue === null) { %>?<% } %>: <%- featureType %><% if (defaultValue !== null) { %> = <%- defaultValue %><% } %>;
136
+ <% if (isUnsettableFeature(mf.feature)) { -%>
137
+ private _<%- mf.name %>IsSet = false;
138
+ <% } -%>
127
139
  <% } -%>
128
140
 
129
141
  /**
@@ -172,6 +184,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
172
184
  const oldValue = this._<%- featureName %>;
173
185
  <% } -%>
174
186
  this._<%- featureName %> = value;
187
+ <% if (isUnsettableFeature(feature)) { -%>
188
+ this._<%- featureName %>IsSet = true;
189
+ <% } -%>
175
190
  <% if (genFeature.notify) { -%>
176
191
  if (this.eDeliver()) {
177
192
  this.eNotify({
@@ -204,6 +219,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
204
219
 
205
220
  set <%- mf.name %>(value: <%- featureType %>) {
206
221
  this._<%- mf.name %> = value;
222
+ <% if (isUnsettableFeature(mf.feature)) { -%>
223
+ this._<%- mf.name %>IsSet = true;
224
+ <% } -%>
207
225
  }
208
226
 
209
227
  <% } -%>
@@ -282,7 +300,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
282
300
  const featureName = getName(feature);
283
301
  -%>
284
302
  case <%- className %>.<%- fid.name %>:
285
- <% if (useEList && featureIsMany) { -%>
303
+ <% if (isUnsettableFeature(feature)) { -%>
304
+ return this._<%- featureName %>IsSet;
305
+ <% } else if (useEList && featureIsMany) { -%>
286
306
  return this._<%- featureName %> !== undefined && !this._<%- featureName %>.isEmpty();
287
307
  <% } else if (featureIsMany) { -%>
288
308
  return this._<%- featureName %> !== undefined && this._<%- featureName %>.length > 0;
@@ -297,7 +317,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
297
317
  const defaultValue = typeMapper.getDefaultValue(mf.feature);
298
318
  -%>
299
319
  case <%- className %>.<%- mf.upperName %>:
300
- <% if (useEList && featureIsMany) { -%>
320
+ <% if (isUnsettableFeature(mf.feature)) { -%>
321
+ return this._<%- mf.name %>IsSet;
322
+ <% } else if (useEList && featureIsMany) { -%>
301
323
  return this._<%- mf.name %> !== undefined && !this._<%- mf.name %>.isEmpty();
302
324
  <% } else if (featureIsMany) { -%>
303
325
  return this._<%- mf.name %> !== undefined && this._<%- mf.name %>.length > 0;
@@ -333,6 +355,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
333
355
  this._<%- featureName %> = <%- defaultValue %>;
334
356
  <% } else { -%>
335
357
  this._<%- featureName %> = undefined;
358
+ <% } -%>
359
+ <% if (isUnsettableFeature(feature)) { -%>
360
+ this._<%- featureName %>IsSet = false;
336
361
  <% } -%>
337
362
  return;
338
363
  <% } -%>
@@ -349,6 +374,9 @@ export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%-
349
374
  this._<%- mf.name %> = <%- defaultValue %>;
350
375
  <% } else { -%>
351
376
  this._<%- mf.name %> = undefined;
377
+ <% } -%>
378
+ <% if (isUnsettableFeature(mf.feature)) { -%>
379
+ this._<%- mf.name %>IsSet = false;
352
380
  <% } -%>
353
381
  return;
354
382
  <% } -%>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emfts/codegen",
3
- "version": "0.0.2-next.4",
3
+ "version": "0.0.2-next.6",
4
4
  "description": "TypeScript code generator for Ecore models using emfts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "commander": "^12.0.0",
48
48
  "ejs": "^3.1.10",
49
- "@emfts/core": "^0.2.0-next.1",
49
+ "@emfts/core": "^0.3.0-next.1",
50
50
  "sax": "^1.4.4"
51
51
  },
52
52
  "devDependencies": {