@typemf/generator 0.5.0 → 0.5.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typemf/generator",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -30,9 +30,9 @@
30
30
  "provenance": true
31
31
  },
32
32
  "dependencies": {
33
- "@typemf/core": "0.5.0",
34
- "@typemf/node": "0.5.0",
35
- "@typemf/xmi": "0.5.0",
33
+ "@typemf/core": "0.5.1",
34
+ "@typemf/node": "0.5.1",
35
+ "@typemf/xmi": "0.5.1",
36
36
  "nunjucks": "^3.2.4",
37
37
  "prettier": "^3.9.8"
38
38
  },
@@ -74,9 +74,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
74
74
  private _{{ feature.getName() }}Cache: BasicEList<{{ tsScalarType(feature) }}> | undefined;
75
75
 
76
76
  private get _{{ feature.getName() }}(): BasicEList<{{ tsScalarType(feature) }}> {
77
- if (!this._{{ feature.getName() }}Cache) {
78
- this._{{ feature.getName() }}Cache = new BasicEList<{{ tsScalarType(feature) }}>(this, get{{ packageClassName(package) }}Ref().get{{ eClass.getName() }}_{{ ucfirst(feature.getName()) }}());
79
- }
77
+ this._{{ feature.getName() }}Cache ??= new BasicEList<{{ tsScalarType(feature) }}>(this, get{{ packageClassName(package) }}Ref().get{{ eClass.getName() }}_{{ ucfirst(feature.getName()) }}());
80
78
  return this._{{ feature.getName() }}Cache;
81
79
  }
82
80
  {% else %}
@@ -359,7 +357,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
359
357
  {% if superClass %}
360
358
  return super.eGet(feature);
361
359
  {% else %}
362
- throw new Error(`{{ eClass.getName() }} has no feature with id ${feature.getFeatureID()}`);
360
+ throw new Error(`{{ eClass.getName() }} has no feature with id ${String(feature.getFeatureID())}`);
363
361
  {% endif %}
364
362
  }
365
363
  }
@@ -404,7 +402,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
404
402
  super.eSet(feature, value);
405
403
  return;
406
404
  {% else %}
407
- throw new Error(`{{ eClass.getName() }} has no feature with id ${feature.getFeatureID()}`);
405
+ throw new Error(`{{ eClass.getName() }} has no feature with id ${String(feature.getFeatureID())}`);
408
406
  {% endif %}
409
407
  }
410
408
  }
@@ -420,21 +418,29 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
420
418
  the first place - only its ID. Ordinary callers (eSet, generated
421
419
  bean setters) are unaffected; they still pass a real feature and
422
420
  get identical behavior. #}
423
- eBasicSetValue(feature: EStructuralFeature | number, value: unknown): void {
421
+ {#- The `value` parameter is only genuinely used when some case below assigns it, or when
422
+ delegating to a superclass - for a class with no single-valued, non-computed features of
423
+ its own AND no supertype (e.g. a classifier with only many-valued features, or none at
424
+ all), the switch body below is just "default: throw", and `value` would otherwise be an
425
+ unused parameter. Naming it `_value` in exactly that case (tsc's noUnusedParameters, like
426
+ the conventional ESLint argsIgnorePattern, ignores a leading underscore) avoids that
427
+ without a `void value;` marker statement, which `no-meaningless-void-operator`-style lint
428
+ rules flag as pointless. #}
429
+ {% set valueParam = "value" if (singleValuedFeatures(ownFeatures).length > 0 or superClass) else "_value" %}
430
+ eBasicSetValue(feature: EStructuralFeature | number, {{ valueParam }}: unknown): void {
424
431
  const featureId = typeof feature === 'number' ? feature : feature.getFeatureID();
425
432
  switch (featureId) {
426
433
  {% for feature in singleValuedFeatures(ownFeatures) %}
427
434
  {% if not featureGetter(feature) %}
428
- case {{ feature.getFeatureID() }}: this._{{ feature.getName() }} = value as {{ tsOptionalScalarType(feature) }}; return;
435
+ case {{ feature.getFeatureID() }}: this._{{ feature.getName() }} = {{ valueParam }} as {{ tsOptionalScalarType(feature) }}; return;
429
436
  {% endif %}
430
437
  {% endfor %}
431
438
  default:
432
439
  {% if superClass %}
433
- super.eBasicSetValue(feature, value);
440
+ super.eBasicSetValue(feature, {{ valueParam }});
434
441
  return;
435
442
  {% else %}
436
- void value;
437
- throw new Error(`Feature ${featureId} on {{ eClass.getName() }} is many-valued or unknown.`);
443
+ throw new Error(`Feature ${String(featureId)} on {{ eClass.getName() }} is many-valued or unknown.`);
438
444
  {% endif %}
439
445
  }
440
446
  }
@@ -456,7 +462,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
456
462
  {% for feature in ownFeatures %}
457
463
  {% if feature.isMany() and not featureGetter(feature) %}
458
464
  case {{ feature.getFeatureID() }}:
459
- if (!this._{{ feature.getName() }}Cache) this._{{ feature.getName() }}Cache = new BasicEList<{{ tsScalarType(feature) }}>(this);
465
+ this._{{ feature.getName() }}Cache ??= new BasicEList<{{ tsScalarType(feature) }}>(this);
460
466
  return this._{{ feature.getName() }}Cache;
461
467
  {% endif %}
462
468
  {% endfor %}
@@ -464,7 +470,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
464
470
  {% if superClass %}
465
471
  return super.eBootstrapList(featureId);
466
472
  {% else %}
467
- throw new Error(`Feature ${featureId} on {{ eClass.getName() }} is single-valued or unknown.`);
473
+ throw new Error(`Feature ${String(featureId)} on {{ eClass.getName() }} is single-valued or unknown.`);
468
474
  {% endif %}
469
475
  }
470
476
  }
@@ -514,7 +520,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
514
520
  {% if superClass %}
515
521
  return super.eIsSet(feature);
516
522
  {% else %}
517
- throw new Error(`{{ eClass.getName() }} has no feature with id ${feature.getFeatureID()}`);
523
+ throw new Error(`{{ eClass.getName() }} has no feature with id ${String(feature.getFeatureID())}`);
518
524
  {% endif %}
519
525
  }
520
526
  }
@@ -551,7 +557,7 @@ export class {{ eClass.getName() }}Impl extends {{ (superClass.getName() + "Impl
551
557
  super.eUnset(feature);
552
558
  return;
553
559
  {% else %}
554
- throw new Error(`{{ eClass.getName() }} has no feature with id ${feature.getFeatureID()}`);
560
+ throw new Error(`{{ eClass.getName() }} has no feature with id ${String(feature.getFeatureID())}`);
555
561
  {% endif %}
556
562
  }
557
563
  }
@@ -31,7 +31,7 @@ export class {{ factoryClassName(package) }}Impl extends {{ useImport("EFactoryI
31
31
  }
32
32
  {% endfor %}
33
33
 
34
- create(eClass: {{ useImport("EClass", "types", {foundational: true}) }}): {{ useImport("EObject", "types", {foundational: true}) }} {
34
+ override create(eClass: {{ useImport("EClass", "types", {foundational: true}) }}): {{ useImport("EObject", "types", {foundational: true}) }} {
35
35
  switch (eClass.getClassifierID()) {
36
36
  {% for classifier in concreteEClassesOf(package) %}
37
37
  case {{ useImport("Ids", "root", {file: packageClassName(package), foundational: false}) }}.{{ classifier.getName() }}.self:
@@ -44,20 +44,61 @@ export interface {{ pkgClass }} extends {{ useImport("EPackage", "types", {found
44
44
  }
45
45
  {% endfile %}
46
46
  {% file "impl/" + pkgClass + "Impl.ts" %}
47
+ {#- Every foundational Impl class below is only actually referenced in the body further down
48
+ when the package genuinely contains the classifier/feature/annotation kind it backs (e.g.
49
+ EEnumImpl is only `new`'d if some classifier here is an EEnum) - importing it unconditionally
50
+ produced an unused import, and therefore a lint error, for every package missing that kind
51
+ (e.g. a package with no EOperations never uses EOperationImpl/EParameterImpl at all). These
52
+ flags mirror that same condition once, up front, so each import below is requested only when
53
+ the body will actually use it. EFactoryImpl is never referenced in this file's body at all
54
+ (only efactory.njk's own generated file extends it) and so is not imported here regardless. #}
55
+ {% set needsAttribute = false %}
56
+ {% set needsReference = false %}
57
+ {% set needsOperation = false %}
58
+ {% set needsParameter = false %}
59
+ {% set needsDataType = false %}
60
+ {% set needsEnum = false %}
61
+ {% set needsEnumLiteral = false %}
62
+ {% set needsAnnotation = false %}
63
+ {% if package.getEAnnotations().size() > 0 %}{% set needsAnnotation = true %}{% endif %}
64
+ {% for classifier in package.getEClassifiers() %}
65
+ {% if classifier.getEAnnotations().size() > 0 %}{% set needsAnnotation = true %}{% endif %}
66
+ {% if isEClass(classifier) %}
67
+ {% for feature in classifier.getEStructuralFeatures() %}
68
+ {% if isEReference(feature) %}{% set needsReference = true %}{% else %}{% set needsAttribute = true %}{% endif %}
69
+ {% if feature.getEAnnotations().size() > 0 %}{% set needsAnnotation = true %}{% endif %}
70
+ {% endfor %}
71
+ {% for op in classifier.getEOperations() %}
72
+ {% set needsOperation = true %}
73
+ {% if op.getEAnnotations().size() > 0 %}{% set needsAnnotation = true %}{% endif %}
74
+ {% if op.getEParameters().size() > 0 %}{% set needsParameter = true %}{% endif %}
75
+ {% for param in op.getEParameters() %}
76
+ {% if param.getEAnnotations().size() > 0 %}{% set needsAnnotation = true %}{% endif %}
77
+ {% endfor %}
78
+ {% endfor %}
79
+ {% elif isEEnum(classifier) %}
80
+ {% set needsEnum = true %}
81
+ {% for literal in classifier.getELiterals() %}
82
+ {% set needsEnumLiteral = true %}
83
+ {% if literal.getEAnnotations().size() > 0 %}{% set needsAnnotation = true %}{% endif %}
84
+ {% endfor %}
85
+ {% else %}
86
+ {% set needsDataType = true %}
87
+ {% endif %}
88
+ {% endfor %}
47
89
  {% for name in metaclassAccessorCollisionTypeNames(package) %}
48
90
  {% set _ = useImport(name, "types", {foundational: true}) %}
49
91
  {% endfor %}
50
92
  {% set _ = useImport("EPackageImpl", "impl", {foundational: true}) %}
51
93
  {% set _ = useImport("EClassImpl", "impl", {foundational: true}) %}
52
- {% set _ = useImport("EAttributeImpl", "impl", {foundational: true}) %}
53
- {% set _ = useImport("EReferenceImpl", "impl", {foundational: true}) %}
54
- {% set _ = useImport("EOperationImpl", "impl", {foundational: true}) %}
55
- {% set _ = useImport("EParameterImpl", "impl", {foundational: true}) %}
56
- {% set _ = useImport("EDataTypeImpl", "impl", {foundational: true}) %}
57
- {% set _ = useImport("EEnumImpl", "impl", {foundational: true}) %}
58
- {% set _ = useImport("EEnumLiteralImpl", "impl", {foundational: true}) %}
59
- {% set _ = useImport("EAnnotationImpl", "impl", {foundational: true}) %}
60
- {% set _ = useImport("EFactoryImpl", "impl", {foundational: true}) %}
94
+ {% if needsAttribute %}{% set _ = useImport("EAttributeImpl", "impl", {foundational: true}) %}{% endif %}
95
+ {% if needsReference %}{% set _ = useImport("EReferenceImpl", "impl", {foundational: true}) %}{% endif %}
96
+ {% if needsOperation %}{% set _ = useImport("EOperationImpl", "impl", {foundational: true}) %}{% endif %}
97
+ {% if needsParameter %}{% set _ = useImport("EParameterImpl", "impl", {foundational: true}) %}{% endif %}
98
+ {% if needsDataType %}{% set _ = useImport("EDataTypeImpl", "impl", {foundational: true}) %}{% endif %}
99
+ {% if needsEnum %}{% set _ = useImport("EEnumImpl", "impl", {foundational: true}) %}{% endif %}
100
+ {% if needsEnumLiteral %}{% set _ = useImport("EEnumLiteralImpl", "impl", {foundational: true}) %}{% endif %}
101
+ {% if needsAnnotation %}{% set _ = useImport("EAnnotationImpl", "impl", {foundational: true}) %}{% endif %}
61
102
  {% set _ = useImport(pkgClass, "root", {foundational: false}) %}
62
103
  {% set _ = useImport("Ids", "root", {file: pkgClass, foundational: false}) %}
63
104
  {% set _ = useImport(factoryClassName(package), "root", {foundational: false}) %}
@@ -17,15 +17,18 @@ export abstract class {{ switchClassName(package) }}<T> {
17
17
  }
18
18
  }
19
19
 
20
+ {#- `_object` (not `object`): every stub below always returns `undefined` without looking at
21
+ its argument - it exists purely as an override point for subclasses, which are free to
22
+ name their own parameter however they like (TypeScript overriding is structural, not
23
+ name-based). A leading underscore says so directly and avoids the `void object;` marker
24
+ statement a merely-unused `object` parameter would otherwise need. #}
20
25
  {% for classifier in eClassesOf(package) %}
21
- case{{ classifier.getName() }}(object: {{ useImport(classifier.getName(), "types", {foundational: false}) }}): T | undefined {
22
- void object;
26
+ case{{ classifier.getName() }}(_object: {{ useImport(classifier.getName(), "types", {foundational: false}) }}): T | undefined {
23
27
  return undefined;
24
28
  }
25
29
  {% endfor %}
26
30
 
27
- defaultCase(object: {{ useImport("EObject", "types", {foundational: true}) }}): T | undefined {
28
- void object;
31
+ defaultCase(_object: {{ useImport("EObject", "types", {foundational: true}) }}): T | undefined {
29
32
  return undefined;
30
33
  }
31
34
  }