@lionweb/class-core-generator 0.6.13-beta.5 → 0.6.13-beta.7
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/dist/api/entity-types.templates.d.ts +2 -3
- package/dist/api/entity-types.templates.d.ts.map +1 -1
- package/dist/api/entity-types.templates.js +2 -2
- package/dist/api/entity-types.templates.js.map +1 -1
- package/dist/api/generation-headers.js.map +1 -1
- package/dist/api/generator.d.ts.map +1 -1
- package/dist/api/generator.js.map +1 -1
- package/dist/api/helpers/classifiers.d.ts.map +1 -1
- package/dist/api/helpers/classifiers.js +1 -1
- package/dist/api/helpers/classifiers.js.map +1 -1
- package/dist/api/helpers/dependencies.d.ts.map +1 -1
- package/dist/api/helpers/dependencies.js +2 -2
- package/dist/api/helpers/dependencies.js.map +1 -1
- package/dist/api/helpers/entities.d.ts.map +1 -1
- package/dist/api/helpers/entities.js.map +1 -1
- package/dist/api/helpers/features.d.ts.map +1 -1
- package/dist/api/helpers/features.js.map +1 -1
- package/dist/api/helpers/imports-tracking.d.ts +0 -3
- package/dist/api/helpers/imports-tracking.d.ts.map +1 -1
- package/dist/api/helpers/imports-tracking.js +0 -8
- package/dist/api/helpers/imports-tracking.js.map +1 -1
- package/dist/api/helpers/mps-annotations.d.ts +6 -6
- package/dist/api/helpers/mps-annotations.d.ts.map +1 -1
- package/dist/api/helpers/mps-annotations.js.map +1 -1
- package/dist/api/helpers/types.d.ts.map +1 -1
- package/dist/api/helpers/types.js +4 -8
- package/dist/api/helpers/types.js.map +1 -1
- package/dist/api/index-ts.d.ts.map +1 -1
- package/dist/api/index-ts.js +5 -4
- package/dist/api/index-ts.js.map +1 -1
- package/dist/api/language-file.templates.d.ts.map +1 -1
- package/dist/api/language-file.templates.js +10 -7
- package/dist/api/language-file.templates.js.map +1 -1
- package/dist/api/mega-factory.templates.d.ts.map +1 -1
- package/dist/api/mega-factory.templates.js +7 -4
- package/dist/api/mega-factory.templates.js.map +1 -1
- package/dist/api/reflective-layer.templates.d.ts.map +1 -1
- package/dist/api/reflective-layer.templates.js +34 -19
- package/dist/api/reflective-layer.templates.js.map +1 -1
- package/dist/utils/textgen.d.ts.map +1 -1
- package/dist/utils/textgen.js.map +1 -1
- package/package.json +3 -5
- package/src/api/entity-types.templates.ts +7 -6
- package/src/api/generation-headers.ts +1 -1
- package/src/api/generator.ts +10 -10
- package/src/api/helpers/classifiers.ts +15 -3
- package/src/api/helpers/dependencies.ts +4 -4
- package/src/api/helpers/entities.ts +8 -2
- package/src/api/helpers/features.ts +2 -1
- package/src/api/helpers/imports-tracking.ts +5 -12
- package/src/api/helpers/mps-annotations.ts +8 -6
- package/src/api/helpers/types.ts +6 -9
- package/src/api/index-ts.ts +16 -26
- package/src/api/language-file.templates.ts +16 -12
- package/src/api/mega-factory.templates.ts +26 -20
- package/src/api/reflective-layer.templates.ts +69 -46
- package/src/utils/textgen.ts +1 -1
|
@@ -15,42 +15,46 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import {isConcrete, Language, LanguageEntity} from "@lionweb/core"
|
|
19
|
+
import {asString, commaSeparated} from "littoral-templates"
|
|
20
|
+
|
|
21
|
+
import {asJSIdentifier, indent} from "../utils/textgen.js"
|
|
22
|
+
import {Deprecated, MpsAnnotation} from "./helpers/index.js";
|
|
20
23
|
|
|
21
|
-
import { asJSIdentifier, indent } from "../utils/textgen.js"
|
|
22
|
-
import { Deprecated, MpsAnnotation } from "./helpers/index.js"
|
|
23
24
|
|
|
24
25
|
export const megaFactoryFor = (megaFactoryName: string, languages: Language[], mpsAnnotations: MpsAnnotation[] = [], header?: string) => {
|
|
25
|
-
const isNotDeprecated = (entity: LanguageEntity)
|
|
26
|
-
!mpsAnnotations.some(
|
|
26
|
+
const isNotDeprecated = (entity: LanguageEntity)=>
|
|
27
|
+
!mpsAnnotations.some(
|
|
28
|
+
(mpsAnnotation) => mpsAnnotation.annotatedNodeId === entity.id && mpsAnnotation instanceof Deprecated
|
|
29
|
+
)
|
|
27
30
|
|
|
28
|
-
const requiresFactoryMethod = (entity: LanguageEntity) =>
|
|
31
|
+
const requiresFactoryMethod = (entity: LanguageEntity) =>
|
|
32
|
+
isConcrete(entity) && isNotDeprecated(entity)
|
|
29
33
|
|
|
30
34
|
const factoryFor = (language: Language) => [
|
|
31
35
|
`${asJSIdentifier(language.name)}Factory = {`,
|
|
32
|
-
indent(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
classifier =>
|
|
38
|
-
`create${classifier.name}: () => ${asJSIdentifier(language.name)}.${classifier.name}.create(newId(), this.handleDelta)`
|
|
39
|
-
)
|
|
40
|
-
)
|
|
41
|
-
),
|
|
36
|
+
indent(commaSeparated(
|
|
37
|
+
language.entities
|
|
38
|
+
.filter(requiresFactoryMethod)
|
|
39
|
+
.map((classifier) => `create${classifier.name}: () => ${asJSIdentifier(language.name)}.${classifier.name}.create(newId(), this.handleDelta)`)
|
|
40
|
+
)),
|
|
42
41
|
`}`,
|
|
43
42
|
``
|
|
44
43
|
]
|
|
45
44
|
|
|
46
|
-
const languagesWithFactoryMethods = languages
|
|
45
|
+
const languagesWithFactoryMethods = languages
|
|
46
|
+
.filter(
|
|
47
|
+
(language) => language.entities.some(requiresFactoryMethod)
|
|
48
|
+
)
|
|
47
49
|
|
|
48
50
|
return asString([
|
|
49
51
|
header ?? [],
|
|
50
52
|
`import {DeltaHandler} from "@lionweb/class-core";`,
|
|
51
53
|
``,
|
|
52
54
|
`import {`,
|
|
53
|
-
indent(commaSeparated(
|
|
55
|
+
indent(commaSeparated(
|
|
56
|
+
languagesWithFactoryMethods.map(({name}) => asJSIdentifier(name))
|
|
57
|
+
)),
|
|
54
58
|
`} from "./index.g.js";`,
|
|
55
59
|
``,
|
|
56
60
|
`import {newId} from "../index.js";`,
|
|
@@ -60,7 +64,9 @@ export const megaFactoryFor = (megaFactoryName: string, languages: Language[], m
|
|
|
60
64
|
indent([
|
|
61
65
|
``,
|
|
62
66
|
`constructor(`,
|
|
63
|
-
indent([
|
|
67
|
+
indent([
|
|
68
|
+
`public readonly handleDelta?: DeltaHandler`
|
|
69
|
+
]),
|
|
64
70
|
`) {`,
|
|
65
71
|
`}`,
|
|
66
72
|
``,
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
Annotation,
|
|
20
|
+
asArray,
|
|
20
21
|
Classifier,
|
|
21
22
|
Concept,
|
|
22
23
|
Enumeration,
|
|
@@ -35,70 +36,90 @@ import {
|
|
|
35
36
|
Property,
|
|
36
37
|
SingleRef
|
|
37
38
|
} from "@lionweb/core"
|
|
38
|
-
import {
|
|
39
|
-
|
|
39
|
+
import {when, withNewlineAppended} from "littoral-templates"
|
|
40
|
+
|
|
41
|
+
import {indent, switchOrIf} from "../utils/textgen.js"
|
|
42
|
+
import {entityMetaType, extendsFrom, Imports, nameOfBaseClassForLanguage} from "./helpers/index.js"
|
|
40
43
|
|
|
41
|
-
import { indent, switchOrIf } from "../utils/textgen.js"
|
|
42
|
-
import { entityMetaType, extendsFrom, Imports, nameOfBaseClassForLanguage } from "./helpers/index.js"
|
|
43
44
|
|
|
44
45
|
export const reflectiveClassFor = (imports: Imports) => {
|
|
46
|
+
|
|
45
47
|
// classifier:
|
|
46
48
|
|
|
47
49
|
const reflectiveMembersForFeature = (feature: Feature) => {
|
|
48
|
-
const {
|
|
50
|
+
const {classifier, name, key, id, optional} = feature
|
|
49
51
|
const metaType = featureMetaType(feature)
|
|
50
52
|
const qName = `${classifier.name}_${name}`
|
|
51
53
|
return [
|
|
52
54
|
`private readonly _${qName} = new ${imports.core(metaType)}(this._${classifier.name}, "${name}", "${key}", "${id}")${optional ? ".isOptional()" : ""}${isMultiple(feature) ? ".isMultiple()" : ""};`,
|
|
53
55
|
// | core (2nd x) |
|
|
54
56
|
`get ${qName}(): ${metaType} {`,
|
|
55
|
-
indent([
|
|
57
|
+
indent([
|
|
58
|
+
`this.ensureWiredUp();`,
|
|
59
|
+
`return this._${qName};`
|
|
60
|
+
]),
|
|
56
61
|
`}`
|
|
57
62
|
]
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
const reflectiveMembersForClassifier = (classifier: Classifier) => {
|
|
61
|
-
const {
|
|
66
|
+
const {name, key, id, features} = classifier
|
|
62
67
|
const metaType = entityMetaType(classifier)
|
|
63
68
|
return [
|
|
64
|
-
`public readonly _${name} = new ${imports.core(metaType)}(this._language, "${name}", "${key}", "${id}"${classifier instanceof Concept ? ", " + classifier.abstract : ""});`,
|
|
69
|
+
`public readonly _${name} = new ${imports.core(metaType)}(this._language, "${name}", "${key}", "${id}"${classifier instanceof Concept ? (", " + classifier.abstract) : ""});`,
|
|
65
70
|
// | core (2nd x) |
|
|
66
71
|
`get ${name}(): ${metaType} {`,
|
|
67
|
-
indent([
|
|
72
|
+
indent([
|
|
73
|
+
`this.ensureWiredUp();`,
|
|
74
|
+
`return this._${name};`
|
|
75
|
+
]),
|
|
68
76
|
`}`,
|
|
69
77
|
features.map(reflectiveMembersForFeature)
|
|
70
78
|
]
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
// enumeration:
|
|
74
81
|
|
|
75
|
-
|
|
82
|
+
// enumeration:
|
|
83
|
+
|
|
84
|
+
const reflectiveMemberForEnumerationLiteral = ({enumeration, name, key, id}: EnumerationLiteral) => {
|
|
76
85
|
const qName = `${enumeration.name}_${name}`
|
|
77
86
|
return [
|
|
78
87
|
`private readonly _${qName} = new ${imports.core("EnumerationLiteral")}(this._${enumeration.name}, "${name}", "${key}", "${id}");`,
|
|
79
88
|
// | core (2nd x) |
|
|
80
89
|
`get ${qName}(): EnumerationLiteral {`,
|
|
81
|
-
indent([
|
|
90
|
+
indent([
|
|
91
|
+
`this.ensureWiredUp();`,
|
|
92
|
+
`return this._${qName};`
|
|
93
|
+
]),
|
|
82
94
|
`}`
|
|
83
95
|
]
|
|
84
96
|
}
|
|
85
97
|
|
|
86
|
-
const reflectiveMembersForEnumeration = ({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
const reflectiveMembersForEnumeration = ({name, key, id, literals}: Enumeration) =>
|
|
99
|
+
[
|
|
100
|
+
`public readonly _${name} = new ${imports.core("Enumeration")}(this._language, "${name}", "${key}", "${id}");`,
|
|
101
|
+
// | core (2nd x) |
|
|
102
|
+
`get ${name}(): Enumeration {`,
|
|
103
|
+
indent([
|
|
104
|
+
`this.ensureWiredUp();`,
|
|
105
|
+
`return this._${name};`
|
|
106
|
+
]),
|
|
107
|
+
`}`,
|
|
108
|
+
literals.map(reflectiveMemberForEnumerationLiteral)
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
const reflectiveMembersForPrimitiveType = ({name, key, id}: PrimitiveType) =>
|
|
112
|
+
[
|
|
113
|
+
`public readonly _${name} = new ${imports.core("PrimitiveType")}(this._language, "${name}", "${key}", "${id}");`,
|
|
114
|
+
// | core (2nd x) |
|
|
115
|
+
`get ${name}(): PrimitiveType {`,
|
|
116
|
+
indent([
|
|
117
|
+
`this.ensureWiredUp();`,
|
|
118
|
+
`return this._${name};`
|
|
119
|
+
]),
|
|
120
|
+
`}`
|
|
121
|
+
]
|
|
122
|
+
|
|
102
123
|
|
|
103
124
|
const reflectiveMembersForEntity = (entity: LanguageEntity) => {
|
|
104
125
|
if (entity instanceof Classifier) {
|
|
@@ -113,6 +134,7 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
113
134
|
return `// unhandled language entity <${entityMetaType(entity)}>"${entity.name}"`
|
|
114
135
|
}
|
|
115
136
|
|
|
137
|
+
|
|
116
138
|
const refForType = (type: SingleRef<LanguageEntity>) => {
|
|
117
139
|
if (type === null) {
|
|
118
140
|
return `???`
|
|
@@ -124,12 +146,12 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
124
146
|
}
|
|
125
147
|
|
|
126
148
|
const wireUpStatementsForProperty = (property: Property) => {
|
|
127
|
-
const {
|
|
149
|
+
const {classifier, name, type, optional} = property
|
|
128
150
|
return `this._${classifier.name}_${name}.ofType(${refForType(type)})${optional ? ".isOptional()" : ""};`
|
|
129
151
|
}
|
|
130
152
|
|
|
131
153
|
const wireUpStatementsForLink = (link: Link) => {
|
|
132
|
-
const {
|
|
154
|
+
const {classifier, name, type} = link
|
|
133
155
|
return `this._${classifier.name}_${name}.ofType(${refForType(type)});`
|
|
134
156
|
}
|
|
135
157
|
|
|
@@ -143,24 +165,23 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
143
165
|
return `// unhandled feature <${featureMetaType(feature)}>"${feature.name}"`
|
|
144
166
|
}
|
|
145
167
|
|
|
146
|
-
const isConcreteClassifier = (classifier: Classifier): classifier is Annotation | Concept =>
|
|
168
|
+
const isConcreteClassifier = (classifier: Classifier): classifier is (Annotation | Concept) =>
|
|
147
169
|
classifier instanceof Annotation || classifier instanceof Concept
|
|
148
170
|
|
|
149
171
|
const wireUpStatementsForEntity = (entity: LanguageEntity) => {
|
|
150
|
-
const {
|
|
172
|
+
const {name} = entity
|
|
151
173
|
const thisLocalName = (localName: string) => `this._${name}_${localName}`
|
|
152
174
|
if (entity instanceof Classifier) {
|
|
153
175
|
const extends_ = extendsFrom(entity)
|
|
154
176
|
return [
|
|
155
|
-
extends_ instanceof Classifier
|
|
177
|
+
extends_ instanceof Classifier
|
|
178
|
+
? `this._${name}.extends = ${refForType(extends_)};`
|
|
179
|
+
: [],
|
|
156
180
|
when(entity instanceof Interface && entity.extends.length > 0)(
|
|
157
|
-
() => `this._${name}.extending(${(entity as Interface).extends.map(interface_ => refForType(interface_)).join(", ")});`
|
|
181
|
+
() => `this._${name}.extending(${(entity as Interface).extends.map((interface_) => refForType(interface_)).join(", ")});`
|
|
158
182
|
),
|
|
159
183
|
when(isConcreteClassifier(entity) && entity.implements.length > 0)(
|
|
160
|
-
() =>
|
|
161
|
-
`this._${name}.implementing(${asArray((entity as Annotation | Concept).implements)
|
|
162
|
-
.map(interface_ => refForType(interface_))
|
|
163
|
-
.join(", ")});`
|
|
184
|
+
() => `this._${name}.implementing(${asArray((entity as (Annotation | Concept)).implements).map((interface_) => refForType(interface_)).join(", ")});`
|
|
164
185
|
),
|
|
165
186
|
when(entity.features.length > 0)(
|
|
166
187
|
`this._${name}.havingFeatures(${entity.features.map(nameOf).map(thisLocalName).join(", ")});`
|
|
@@ -172,13 +193,13 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
172
193
|
return `this._${name}.havingLiterals(${entity.literals.map(nameOf).map(thisLocalName).join(", ")});`
|
|
173
194
|
}
|
|
174
195
|
if (entity instanceof PrimitiveType) {
|
|
175
|
-
return []
|
|
196
|
+
return [] // (nothing to do)
|
|
176
197
|
}
|
|
177
198
|
return `// unhandled language entity <${entityMetaType(entity)}>"${name}"`
|
|
178
199
|
}
|
|
179
200
|
|
|
180
201
|
return (language: Language) => {
|
|
181
|
-
const {
|
|
202
|
+
const {version, id, key, entities} = language
|
|
182
203
|
const enumerations = entities.filter(isEnumeration)
|
|
183
204
|
const concreteClassifiers = entities.filter(isConcrete)
|
|
184
205
|
const parameterPrefix = concreteClassifiers.length === 0 ? "_" : ""
|
|
@@ -191,7 +212,10 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
191
212
|
`private readonly _language: ${imports.core("Language")} = new Language("${imports.thisLanguageNameAsJsIdentifier}", "${version}", "${id}", "${key}");`,
|
|
192
213
|
// | core | (3rd x)
|
|
193
214
|
`get language(): Language {`,
|
|
194
|
-
indent([
|
|
215
|
+
indent([
|
|
216
|
+
`this.ensureWiredUp();`,
|
|
217
|
+
`return this._language;`
|
|
218
|
+
]),
|
|
195
219
|
`}`,
|
|
196
220
|
``,
|
|
197
221
|
entities.map(withNewlineAppended(reflectiveMembersForEntity)),
|
|
@@ -209,13 +233,11 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
209
233
|
``,
|
|
210
234
|
`factory(${parameterPrefix}handleDelta?: ${imports.generic("DeltaHandler")}): ${imports.generic("NodeBaseFactory")} {`,
|
|
211
235
|
indent([
|
|
212
|
-
`return (classifier: ${imports.core("Classifier")}, ${parameterPrefix}id: ${imports.
|
|
236
|
+
`return (classifier: ${imports.core("Classifier")}, ${parameterPrefix}id: ${imports.core("Id")}) => {`,
|
|
213
237
|
indent(
|
|
214
238
|
switchOrIf(
|
|
215
239
|
"classifier.key",
|
|
216
|
-
concreteClassifiers
|
|
217
|
-
.map(nameOf)
|
|
218
|
-
.map(name => [`this._${name}.key`, `${name}.create(id, ${parameterPrefix}handleDelta)`]),
|
|
240
|
+
concreteClassifiers.map(nameOf).map((name) => [`this._${name}.key`, `${name}.create(id, ${parameterPrefix}handleDelta)`]),
|
|
219
241
|
[
|
|
220
242
|
`const {language} = classifier;`,
|
|
221
243
|
`throw new Error(\`can't instantiate \${classifier.name} (key=\${classifier.key}): classifier is not known in language \${language.name} (key=\${language.key}, version=\${language.version})\`);`
|
|
@@ -232,7 +254,7 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
232
254
|
`const {enumeration} = enumerationLiteral;`,
|
|
233
255
|
switchOrIf(
|
|
234
256
|
"enumeration.key",
|
|
235
|
-
enumerations.map(nameOf).map(name => [`this._${name}.key`, "enumerationLiteral.key as EnumType"]),
|
|
257
|
+
enumerations.map(nameOf).map((name) => [`this._${name}.key`, "enumerationLiteral.key as EnumType"]),
|
|
236
258
|
[
|
|
237
259
|
`const {language} = enumeration;`,
|
|
238
260
|
`throw new Error(\`enumeration with key \${enumeration.key} is not known in language \${language.name} (key=\${language.key}, version=\${language.version})\`);`
|
|
@@ -246,5 +268,6 @@ export const reflectiveClassFor = (imports: Imports) => {
|
|
|
246
268
|
`}`
|
|
247
269
|
]
|
|
248
270
|
}
|
|
271
|
+
|
|
249
272
|
}
|
|
250
273
|
|