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