@emfts/codegen 0.0.1-next.1 → 0.0.1-next.2
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/cli/index.js +0 -0
- package/package.json +1 -1
- package/dist/debug-abstract.d.ts +0 -2
- package/dist/debug-abstract.d.ts.map +0 -1
- package/dist/debug-abstract.js +0 -25
- package/dist/debug-abstract.js.map +0 -1
- package/dist/debug-genmodel.d.ts +0 -2
- package/dist/debug-genmodel.d.ts.map +0 -1
- package/dist/debug-genmodel.js +0 -41
- package/dist/debug-genmodel.js.map +0 -1
- package/dist/templates/templates/partials/decorator/class-file.ejs +0 -98
- package/dist/templates/templates/partials/decorator/enum-file.ejs +0 -35
- package/dist/templates/templates/partials/decorator/interface-file.ejs +0 -61
- package/dist/templates/templates/partials/decorator/model-annotations.ejs +0 -91
- package/dist/templates/templates/partials/decorator/package-file.ejs +0 -7
- package/dist/templates/templates/partials/emf/class-file.ejs +0 -226
- package/dist/templates/templates/partials/emf/enum-file.ejs +0 -36
- package/dist/templates/templates/partials/emf/factory-file.ejs +0 -54
- package/dist/templates/templates/partials/emf/index-file.ejs +0 -29
- package/dist/templates/templates/partials/emf/interface-file.ejs +0 -72
- package/dist/templates/templates/partials/emf/package-file.ejs +0 -149
- package/dist/templates/templates/partials/plain/class-file.ejs +0 -75
- package/dist/templates/templates/partials/plain/enum-file.ejs +0 -28
- package/dist/templates/templates/partials/plain/interface-file.ejs +0 -61
- package/dist/templates/templates/partials/plain/package-file.ejs +0 -6
package/dist/cli/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/dist/debug-abstract.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-abstract.d.ts","sourceRoot":"","sources":["../src/debug-abstract.ts"],"names":[],"mappings":""}
|
package/dist/debug-abstract.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EcoreLoader } from './loader/EcoreLoader.js';
|
|
2
|
-
import * as EObjectHelper from './util/EObjectHelper.js';
|
|
3
|
-
async function test() {
|
|
4
|
-
const loader = new EcoreLoader();
|
|
5
|
-
const pkg = await loader.load('examples/model/library.ecore');
|
|
6
|
-
console.log('Package name:', EObjectHelper.getName(pkg));
|
|
7
|
-
for (const c of pkg.getEClassifiers()) {
|
|
8
|
-
const name = EObjectHelper.getName(c);
|
|
9
|
-
const hasIsAbstract = typeof c.isAbstract === 'function';
|
|
10
|
-
let isAbstractResult = 'N/A';
|
|
11
|
-
if (hasIsAbstract) {
|
|
12
|
-
try {
|
|
13
|
-
isAbstractResult = String(c.isAbstract());
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
isAbstractResult = 'ERROR: ' + e.message;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const isProxy = typeof c.eIsProxy === 'function' && c.eIsProxy();
|
|
20
|
-
const helperResult = EObjectHelper.isAbstract(c);
|
|
21
|
-
console.log(`${name}: hasIsAbstract=${hasIsAbstract}, isAbstract()=${isAbstractResult}, isProxy=${isProxy}, helper=${helperResult}`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
test().catch(console.error);
|
|
25
|
-
//# sourceMappingURL=debug-abstract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-abstract.js","sourceRoot":"","sources":["../src/debug-abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AAEzD,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAE9D,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAEzD,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC;QACzD,IAAI,gBAAgB,GAAG,KAAK,CAAC;QAE7B,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,CAAC;gBACH,gBAAgB,GAAG,MAAM,CAAE,CAAS,CAAC,UAAU,EAAE,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,gBAAgB,GAAG,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC;YAC3C,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,OAAQ,CAAS,CAAC,QAAQ,KAAK,UAAU,IAAK,CAAS,CAAC,QAAQ,EAAE,CAAC;QACnF,MAAM,YAAY,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEjD,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,mBAAmB,aAAa,kBAAkB,gBAAgB,aAAa,OAAO,YAAY,YAAY,EAAE,CAAC,CAAC;IACvI,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/debug-genmodel.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-genmodel.d.ts","sourceRoot":"","sources":["../src/debug-genmodel.ts"],"names":[],"mappings":""}
|
package/dist/debug-genmodel.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { EcoreLoader } from './loader/EcoreLoader.js';
|
|
2
|
-
import { GenModelXMILoader } from './genmodel/GenModelXMILoader.js';
|
|
3
|
-
import * as EObjectHelper from './util/EObjectHelper.js';
|
|
4
|
-
async function test() {
|
|
5
|
-
// Load ecore
|
|
6
|
-
const ecoreLoader = new EcoreLoader();
|
|
7
|
-
const pkg = await ecoreLoader.load('examples/model/library.ecore');
|
|
8
|
-
const packages = ecoreLoader.getAllPackages();
|
|
9
|
-
console.log('=== Loaded ecore classes ===');
|
|
10
|
-
for (const c of pkg.getEClassifiers()) {
|
|
11
|
-
const name = EObjectHelper.getName(c);
|
|
12
|
-
if (typeof c.isAbstract === 'function') {
|
|
13
|
-
console.log(name + ': isAbstract() = ' + c.isAbstract());
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Load genmodel
|
|
17
|
-
const genmodelLoader = new GenModelXMILoader();
|
|
18
|
-
const genModel = await genmodelLoader.load('examples/model/library.genmodel', packages);
|
|
19
|
-
console.log('\n=== GenModel ecoreClass references ===');
|
|
20
|
-
for (const genPkg of genModel.genPackages) {
|
|
21
|
-
for (const genClass of genPkg.genClasses) {
|
|
22
|
-
const eClass = genClass.ecoreClass;
|
|
23
|
-
const name = EObjectHelper.getName(eClass);
|
|
24
|
-
const isProxy = typeof eClass.eIsProxy === 'function' && eClass.eIsProxy();
|
|
25
|
-
const hasIsAbstract = typeof eClass.isAbstract === 'function';
|
|
26
|
-
let isAbstractResult = 'N/A';
|
|
27
|
-
if (hasIsAbstract) {
|
|
28
|
-
try {
|
|
29
|
-
isAbstractResult = String(eClass.isAbstract());
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
isAbstractResult = 'ERROR';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const helperResult = EObjectHelper.isAbstract(eClass);
|
|
36
|
-
console.log(name + ': isProxy=' + isProxy + ', hasIsAbstract=' + hasIsAbstract + ', isAbstract()=' + isAbstractResult + ', helper=' + helperResult);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
test().catch(console.error);
|
|
41
|
-
//# sourceMappingURL=debug-genmodel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-genmodel.js","sourceRoot":"","sources":["../src/debug-genmodel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AAEzD,KAAK,UAAU,IAAI;IACjB,aAAa;IACb,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC;IAE9C,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC5C,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtC,IAAI,OAAQ,CAAS,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,mBAAmB,GAAI,CAAS,CAAC,UAAU,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,gBAAgB;IAChB,MAAM,cAAc,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,iCAAiC,EAAE,QAAQ,CAAC,CAAC;IAExF,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACxD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC1C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC;YACnC,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC3C,MAAM,OAAO,GAAG,OAAQ,MAAc,CAAC,QAAQ,KAAK,UAAU,IAAK,MAAc,CAAC,QAAQ,EAAE,CAAC;YAC7F,MAAM,aAAa,GAAG,OAAQ,MAAc,CAAC,UAAU,KAAK,UAAU,CAAC;YACvE,IAAI,gBAAgB,GAAG,KAAK,CAAC;YAC7B,IAAI,aAAa,EAAE,CAAC;gBAClB,IAAI,CAAC;oBACH,gBAAgB,GAAG,MAAM,CAAE,MAAc,CAAC,UAAU,EAAE,CAAC,CAAC;gBAC1D,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,gBAAgB,GAAG,OAAO,CAAC;gBAC7B,CAAC;YACH,CAAC;YACD,MAAM,YAAY,GAAG,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,YAAY,GAAG,OAAO,GAAG,kBAAkB,GAAG,aAAa,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;QACtJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
<%# Generate imports for referenced types -%>
|
|
4
|
-
<%
|
|
5
|
-
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'decorator');
|
|
6
|
-
for (const imp of imports) {
|
|
7
|
-
if (imp.typeName !== className && !imp.typeName.includes(',')) {
|
|
8
|
-
-%>
|
|
9
|
-
import { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
10
|
-
<%
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
-%>
|
|
14
|
-
import { Documentation, Attribute, ModelClass, Reference, Enum } from './ModelAnnotations';
|
|
15
|
-
|
|
16
|
-
@ModelClass({ type: '<%- nsURI %>#//<%- className %>' })
|
|
17
|
-
export <% if (isAbstract) { %>abstract <% } %>class <%- className %><%
|
|
18
|
-
if (typeParameters && typeParameters.length > 0) {
|
|
19
|
-
const params = [];
|
|
20
|
-
for (const tp of typeParameters) {
|
|
21
|
-
params.push(tp.getName());
|
|
22
|
-
}
|
|
23
|
-
%><<%- params.join(', ') %>><%
|
|
24
|
-
}
|
|
25
|
-
if (superTypes && superTypes.length > 0) {
|
|
26
|
-
const superNames = [];
|
|
27
|
-
for (const st of superTypes) {
|
|
28
|
-
if (st.getName) {
|
|
29
|
-
superNames.push(st.getName());
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (superNames.length > 0) {
|
|
33
|
-
%> extends <%- superNames[0] %><%
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
%> {
|
|
37
|
-
<% for (const genFeature of features) {
|
|
38
|
-
const feature = genFeature.ecoreFeature;
|
|
39
|
-
const featureName = feature.getName();
|
|
40
|
-
const featureType = typeMapper.mapFeatureBaseType(feature);
|
|
41
|
-
const fullType = typeMapper.mapFeature(feature);
|
|
42
|
-
const defaultValue = typeMapper.getDefaultValue(feature);
|
|
43
|
-
const isMany = feature.isMany();
|
|
44
|
-
const isRef = typeMapper.isReference(feature);
|
|
45
|
-
const isEnum = feature.getEType() && typeMapper.isEEnum(feature.getEType());
|
|
46
|
-
|
|
47
|
-
// Check for documentation annotation
|
|
48
|
-
let doc = null;
|
|
49
|
-
if (feature.getEAnnotations) {
|
|
50
|
-
for (const ann of feature.getEAnnotations()) {
|
|
51
|
-
const annSource = typeof ann.getSource === 'function' ? ann.getSource() : ann.source;
|
|
52
|
-
if (annSource === 'http://www.eclipse.org/emf/2002/GenModel') {
|
|
53
|
-
const details = typeof ann.getDetails === 'function' ? ann.getDetails() : ann.details;
|
|
54
|
-
if (details && details.get) {
|
|
55
|
-
doc = details.get('documentation');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (doc) {
|
|
61
|
-
-%>
|
|
62
|
-
@Documentation("<%- doc %>")
|
|
63
|
-
<%
|
|
64
|
-
}
|
|
65
|
-
if (isEnum) {
|
|
66
|
-
-%>
|
|
67
|
-
@Enum('<%- featureType %>')
|
|
68
|
-
<%
|
|
69
|
-
} else if (isRef) {
|
|
70
|
-
-%>
|
|
71
|
-
@Reference('<%- featureType %>')
|
|
72
|
-
<%
|
|
73
|
-
} else {
|
|
74
|
-
-%>
|
|
75
|
-
@Attribute()
|
|
76
|
-
<%
|
|
77
|
-
}
|
|
78
|
-
-%>
|
|
79
|
-
<%- featureName %><% if (!isMany && defaultValue === null) { %>?<% } %>: <%- fullType %><% if (defaultValue !== null) { %> = <%- defaultValue %><% } %>;
|
|
80
|
-
|
|
81
|
-
<% } -%>
|
|
82
|
-
<% for (const genOp of operations) {
|
|
83
|
-
const op = genOp.ecoreOperation;
|
|
84
|
-
const opName = op.getName();
|
|
85
|
-
const returnType = op.getEType() ? typeMapper.mapClassifier(op.getEType()) : 'void';
|
|
86
|
-
const params = [];
|
|
87
|
-
for (const param of op.getEParameters()) {
|
|
88
|
-
const paramName = param.getName();
|
|
89
|
-
const paramType = typeMapper.mapClassifier(param.getEType());
|
|
90
|
-
params.push(`${paramName}: ${paramType}`);
|
|
91
|
-
}
|
|
92
|
-
-%>
|
|
93
|
-
<%- opName %>(<%- params.join(', ') %>): <%- returnType %> {
|
|
94
|
-
throw new Error('<%- opName %> not implemented');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
<% } -%>
|
|
98
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
<%
|
|
3
|
-
// Helper to get property from EEnumLiteral (handles both method calls and direct properties)
|
|
4
|
-
function getLiteralProp(literal, prop) {
|
|
5
|
-
const getter = `get${prop.charAt(0).toUpperCase()}${prop.slice(1)}`;
|
|
6
|
-
if (typeof literal[getter] === 'function') {
|
|
7
|
-
return literal[getter]();
|
|
8
|
-
}
|
|
9
|
-
if (literal[prop] !== undefined) {
|
|
10
|
-
return literal[prop];
|
|
11
|
-
}
|
|
12
|
-
// Try eGet if available
|
|
13
|
-
if (typeof literal.eGet === 'function' && typeof literal.eClass === 'function') {
|
|
14
|
-
const eClass = literal.eClass();
|
|
15
|
-
const feature = eClass?.getEStructuralFeature?.(prop);
|
|
16
|
-
if (feature) {
|
|
17
|
-
return literal.eGet(feature);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
-%>
|
|
23
|
-
/**
|
|
24
|
-
* <%- genEnum.documentation || enumName %>
|
|
25
|
-
*/
|
|
26
|
-
export enum <%- enumName %> {
|
|
27
|
-
<% for (let i = 0; i < literals.length; i++) {
|
|
28
|
-
const literal = literals[i];
|
|
29
|
-
const literalName = getLiteralProp(literal, 'literal') || getLiteralProp(literal, 'name');
|
|
30
|
-
const literalValue = getLiteralProp(literal, 'value');
|
|
31
|
-
const value = useStringValues ? `'${literalName}'` : literalValue;
|
|
32
|
-
-%>
|
|
33
|
-
<%- getLiteralProp(literal, 'name') %> = <%- value %><% if (i < literals.length - 1) { %>,<% } %>
|
|
34
|
-
<% } -%>
|
|
35
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
<%# Generate imports for referenced types -%>
|
|
4
|
-
<%
|
|
5
|
-
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'decorator');
|
|
6
|
-
for (const imp of imports) {
|
|
7
|
-
if (imp.typeName !== interfaceName && !imp.typeName.includes(',')) {
|
|
8
|
-
-%>
|
|
9
|
-
import type { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
10
|
-
<%
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
-%>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* <%- genClass.documentation || eClass.getName() %>
|
|
17
|
-
*/
|
|
18
|
-
export interface <%- interfaceName %><%
|
|
19
|
-
if (typeParameters && typeParameters.length > 0) {
|
|
20
|
-
const params = [];
|
|
21
|
-
for (const tp of typeParameters) {
|
|
22
|
-
params.push(tp.getName());
|
|
23
|
-
}
|
|
24
|
-
%><<%- params.join(', ') %>><%
|
|
25
|
-
}
|
|
26
|
-
if (superTypes && superTypes.length > 0) {
|
|
27
|
-
const superNames = [];
|
|
28
|
-
for (const st of superTypes) {
|
|
29
|
-
if (st.getName) {
|
|
30
|
-
superNames.push(st.getName());
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (superNames.length > 0) {
|
|
34
|
-
%> extends <%- superNames.join(', ') %><%
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
%> {
|
|
38
|
-
<% for (const genFeature of features) {
|
|
39
|
-
const feature = genFeature.ecoreFeature;
|
|
40
|
-
const featureName = feature.getName();
|
|
41
|
-
const featureType = typeMapper.mapFeature(feature);
|
|
42
|
-
const isMany = feature.isMany();
|
|
43
|
-
const lowerBound = feature.getLowerBound();
|
|
44
|
-
-%>
|
|
45
|
-
<%- featureName %><% if (lowerBound === 0 && !isMany) { %>?<% } %>: <%- featureType %>;
|
|
46
|
-
<% } -%>
|
|
47
|
-
|
|
48
|
-
<% for (const genOp of operations) {
|
|
49
|
-
const op = genOp.ecoreOperation;
|
|
50
|
-
const opName = op.getName();
|
|
51
|
-
const returnType = op.getEType() ? typeMapper.mapClassifier(op.getEType()) : 'void';
|
|
52
|
-
const params = [];
|
|
53
|
-
for (const param of op.getEParameters()) {
|
|
54
|
-
const paramName = param.getName();
|
|
55
|
-
const paramType = typeMapper.mapClassifier(param.getEType());
|
|
56
|
-
params.push(`${paramName}: ${paramType}`);
|
|
57
|
-
}
|
|
58
|
-
-%>
|
|
59
|
-
<%- opName %>(<%- params.join(', ') %>): <%- returnType %>;
|
|
60
|
-
<% } -%>
|
|
61
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
import 'reflect-metadata';
|
|
4
|
-
|
|
5
|
-
// Metadata keys
|
|
6
|
-
const MODEL_CLASS_KEY = Symbol('modelClass');
|
|
7
|
-
const ATTRIBUTE_KEY = Symbol('attribute');
|
|
8
|
-
const REFERENCE_KEY = Symbol('reference');
|
|
9
|
-
const ENUM_KEY = Symbol('enum');
|
|
10
|
-
const DOCUMENTATION_KEY = Symbol('documentation');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Decorator for model classes
|
|
14
|
-
*/
|
|
15
|
-
export function ModelClass(options: { type: string }) {
|
|
16
|
-
return function (target: Function) {
|
|
17
|
-
Reflect.defineMetadata(MODEL_CLASS_KEY, options, target);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Decorator for attributes (primitive properties)
|
|
23
|
-
*/
|
|
24
|
-
export function Attribute() {
|
|
25
|
-
return function (target: any, propertyKey: string) {
|
|
26
|
-
const existing = Reflect.getMetadata(ATTRIBUTE_KEY, target) || [];
|
|
27
|
-
existing.push(propertyKey);
|
|
28
|
-
Reflect.defineMetadata(ATTRIBUTE_KEY, existing, target);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Decorator for references (object properties)
|
|
34
|
-
*/
|
|
35
|
-
export function Reference(typeName: string) {
|
|
36
|
-
return function (target: any, propertyKey: string) {
|
|
37
|
-
const existing = Reflect.getMetadata(REFERENCE_KEY, target) || {};
|
|
38
|
-
existing[propertyKey] = typeName;
|
|
39
|
-
Reflect.defineMetadata(REFERENCE_KEY, existing, target);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Decorator for enum properties
|
|
45
|
-
*/
|
|
46
|
-
export function Enum(typeName: string) {
|
|
47
|
-
return function (target: any, propertyKey: string) {
|
|
48
|
-
const existing = Reflect.getMetadata(ENUM_KEY, target) || {};
|
|
49
|
-
existing[propertyKey] = typeName;
|
|
50
|
-
Reflect.defineMetadata(ENUM_KEY, existing, target);
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Decorator for documentation
|
|
56
|
-
*/
|
|
57
|
-
export function Documentation(text: string) {
|
|
58
|
-
return function (target: any, propertyKey?: string) {
|
|
59
|
-
if (propertyKey) {
|
|
60
|
-
Reflect.defineMetadata(DOCUMENTATION_KEY, text, target, propertyKey);
|
|
61
|
-
} else {
|
|
62
|
-
Reflect.defineMetadata(DOCUMENTATION_KEY, text, target);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Utility functions to read metadata
|
|
68
|
-
|
|
69
|
-
export function getModelClassType(target: Function): string | undefined {
|
|
70
|
-
const meta = Reflect.getMetadata(MODEL_CLASS_KEY, target);
|
|
71
|
-
return meta?.type;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getAttributes(target: any): string[] {
|
|
75
|
-
return Reflect.getMetadata(ATTRIBUTE_KEY, target) || [];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function getReferences(target: any): Record<string, string> {
|
|
79
|
-
return Reflect.getMetadata(REFERENCE_KEY, target) || {};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function getEnums(target: any): Record<string, string> {
|
|
83
|
-
return Reflect.getMetadata(ENUM_KEY, target) || {};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function getDocumentation(target: any, propertyKey?: string): string | undefined {
|
|
87
|
-
if (propertyKey) {
|
|
88
|
-
return Reflect.getMetadata(DOCUMENTATION_KEY, target, propertyKey);
|
|
89
|
-
}
|
|
90
|
-
return Reflect.getMetadata(DOCUMENTATION_KEY, target);
|
|
91
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
<% if (!extendsImport) { -%>
|
|
4
|
-
import { BasicEObject } from '@emfts/core';
|
|
5
|
-
<% } -%>
|
|
6
|
-
import type { EClass, EStructuralFeature } from '@emfts/core';
|
|
7
|
-
<%# Generate imports for referenced types -%>
|
|
8
|
-
<%
|
|
9
|
-
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'emf');
|
|
10
|
-
// Filter out types that are already hardcoded above or not needed for impl
|
|
11
|
-
const skipTypes = ['BasicEObject', 'EClass', 'EStructuralFeature', 'EAttribute', 'EReference', 'EEnum'];
|
|
12
|
-
// Separate into type-only and value imports
|
|
13
|
-
const typeOnlyImports = [];
|
|
14
|
-
const valueImports = [];
|
|
15
|
-
for (const imp of imports) {
|
|
16
|
-
if (imp.typeName !== className && imp.typeName !== interfaceName &&
|
|
17
|
-
imp.typeName !== extendsClass &&
|
|
18
|
-
!skipTypes.some(t => imp.typeName.includes(t)) &&
|
|
19
|
-
imp.importPath !== '@emfts/core') {
|
|
20
|
-
// Check if this type is used as a runtime value (e.g., enum default values)
|
|
21
|
-
const usedAsValue = features.some(gf => {
|
|
22
|
-
const dv = typeMapper.getDefaultValue(gf.ecoreFeature);
|
|
23
|
-
return dv !== null && typeof dv === 'string' && dv.startsWith(imp.typeName + '.');
|
|
24
|
-
});
|
|
25
|
-
if (usedAsValue) {
|
|
26
|
-
valueImports.push(imp);
|
|
27
|
-
} else {
|
|
28
|
-
typeOnlyImports.push(imp);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const imp of typeOnlyImports) {
|
|
33
|
-
-%>
|
|
34
|
-
import type { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
35
|
-
<%
|
|
36
|
-
}
|
|
37
|
-
for (const imp of valueImports) {
|
|
38
|
-
-%>
|
|
39
|
-
import { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
40
|
-
<%
|
|
41
|
-
}
|
|
42
|
-
-%>
|
|
43
|
-
<% if (extendsImport) { -%>
|
|
44
|
-
import { <%- extendsClass %> } from '<%- extendsImport %>';
|
|
45
|
-
<% } -%>
|
|
46
|
-
import type { <%- interfaceName %> } from './<%- interfaceName %>';
|
|
47
|
-
import { <%- packagePrefix %>Package } from './<%- packagePrefix %>Package';
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Implementation of <%- interfaceName %>
|
|
51
|
-
* @generated
|
|
52
|
-
*/
|
|
53
|
-
export <% if (isAbstract) { %>abstract <% } %>class <%- className %> extends <%- extendsClass %> implements <%- interfaceName %> {
|
|
54
|
-
// Feature ID Constants (eLiterals)
|
|
55
|
-
<% for (const fid of featureIds) { -%>
|
|
56
|
-
static readonly <%- fid.name %>: number = <%- fid.id %>;
|
|
57
|
-
<% } -%>
|
|
58
|
-
|
|
59
|
-
// Private fields
|
|
60
|
-
<% for (const genFeature of features) {
|
|
61
|
-
const feature = genFeature.ecoreFeature;
|
|
62
|
-
const featureName = getName(feature);
|
|
63
|
-
const featureType = typeMapper.mapFeature(feature);
|
|
64
|
-
const defaultValue = typeMapper.getDefaultValue(feature);
|
|
65
|
-
const featureIsMany = isMany(feature);
|
|
66
|
-
-%>
|
|
67
|
-
private _<%- featureName %><% if (!featureIsMany && defaultValue === null) { %>?<% } %>: <%- featureType %><% if (defaultValue !== null) { %> = <%- defaultValue %><% } %>;
|
|
68
|
-
<% } -%>
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Returns the EClass of this object
|
|
72
|
-
*/
|
|
73
|
-
override eClass(): EClass {
|
|
74
|
-
return <%- packagePrefix %>Package.Literals.<%- toUpperSnake(interfaceName) %>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Getters and Setters
|
|
78
|
-
<% for (const genFeature of features) {
|
|
79
|
-
const feature = genFeature.ecoreFeature;
|
|
80
|
-
const featureName = getName(feature);
|
|
81
|
-
const featureType = typeMapper.mapFeature(feature);
|
|
82
|
-
const featureIsMany = isMany(feature);
|
|
83
|
-
const upperName = toUpperSnake(featureName);
|
|
84
|
-
-%>
|
|
85
|
-
get <%- featureName %>(): <%- featureType %> {
|
|
86
|
-
return this._<%- featureName %><% if (!featureIsMany) { %>!<% } %>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
<% if (genFeature.property !== 'readonly') { -%>
|
|
90
|
-
set <%- featureName %>(value: <%- featureType %>) {
|
|
91
|
-
<% if (genFeature.notify) { -%>
|
|
92
|
-
const oldValue = this._<%- featureName %>;
|
|
93
|
-
<% } -%>
|
|
94
|
-
this._<%- featureName %> = value;
|
|
95
|
-
<% if (genFeature.notify) { -%>
|
|
96
|
-
if (this.eDeliver()) {
|
|
97
|
-
this.eNotify({
|
|
98
|
-
getNotifier: () => this,
|
|
99
|
-
getEventType: () => 1, // SET
|
|
100
|
-
getFeature: () => this.eClass().getEStructuralFeature(<%- className %>.<%- upperName %>),
|
|
101
|
-
getOldValue: () => oldValue,
|
|
102
|
-
getNewValue: () => value,
|
|
103
|
-
getPosition: () => -1,
|
|
104
|
-
wasSet: () => true,
|
|
105
|
-
isTouch: () => false,
|
|
106
|
-
isReset: () => false,
|
|
107
|
-
getFeatureID: () => <%- className %>.<%- upperName %>,
|
|
108
|
-
merge: () => false
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
<% } -%>
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
<% } -%>
|
|
115
|
-
<% } -%>
|
|
116
|
-
// Reflective API
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Returns the value of the given feature
|
|
120
|
-
*/
|
|
121
|
-
override eGet(feature: EStructuralFeature): unknown {
|
|
122
|
-
const featureID = this.eClass().getFeatureID(feature);
|
|
123
|
-
switch (featureID) {
|
|
124
|
-
<% for (const fid of featureIds) { -%>
|
|
125
|
-
case <%- className %>.<%- fid.name %>:
|
|
126
|
-
return this.<%- getName(fid.feature.ecoreFeature) %>;
|
|
127
|
-
<% } -%>
|
|
128
|
-
default:
|
|
129
|
-
return super.eGet(feature);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Sets the value of the given feature
|
|
135
|
-
*/
|
|
136
|
-
override eSet(feature: EStructuralFeature, newValue: unknown): void {
|
|
137
|
-
const featureID = this.eClass().getFeatureID(feature);
|
|
138
|
-
switch (featureID) {
|
|
139
|
-
<% for (const fid of featureIds) {
|
|
140
|
-
const featureType = typeMapper.mapFeature(fid.feature.ecoreFeature);
|
|
141
|
-
-%>
|
|
142
|
-
case <%- className %>.<%- fid.name %>:
|
|
143
|
-
this.<%- getName(fid.feature.ecoreFeature) %> = newValue as <%- featureType %>;
|
|
144
|
-
super.eSet(feature, newValue);
|
|
145
|
-
break;
|
|
146
|
-
<% } -%>
|
|
147
|
-
default:
|
|
148
|
-
super.eSet(feature, newValue);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Returns whether the feature has been set
|
|
154
|
-
*/
|
|
155
|
-
override eIsSet(feature: EStructuralFeature): boolean {
|
|
156
|
-
const featureID = this.eClass().getFeatureID(feature);
|
|
157
|
-
switch (featureID) {
|
|
158
|
-
<% for (const fid of featureIds) {
|
|
159
|
-
const feature = fid.feature.ecoreFeature;
|
|
160
|
-
const featureIsMany = isMany(feature);
|
|
161
|
-
const defaultValue = typeMapper.getDefaultValue(feature);
|
|
162
|
-
const featureName = getName(feature);
|
|
163
|
-
-%>
|
|
164
|
-
case <%- className %>.<%- fid.name %>:
|
|
165
|
-
<% if (featureIsMany) { -%>
|
|
166
|
-
return this._<%- featureName %> !== undefined && this._<%- featureName %>.length > 0;
|
|
167
|
-
<% } else if (defaultValue !== null) { -%>
|
|
168
|
-
return this._<%- featureName %> !== <%- defaultValue %>;
|
|
169
|
-
<% } else { -%>
|
|
170
|
-
return this._<%- featureName %> !== undefined;
|
|
171
|
-
<% } -%>
|
|
172
|
-
<% } -%>
|
|
173
|
-
default:
|
|
174
|
-
return super.eIsSet(feature);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Unsets the given feature
|
|
180
|
-
*/
|
|
181
|
-
override eUnset(feature: EStructuralFeature): void {
|
|
182
|
-
const featureID = this.eClass().getFeatureID(feature);
|
|
183
|
-
switch (featureID) {
|
|
184
|
-
<% for (const fid of featureIds) {
|
|
185
|
-
const feature = fid.feature.ecoreFeature;
|
|
186
|
-
const featureIsMany = isMany(feature);
|
|
187
|
-
const defaultValue = typeMapper.getDefaultValue(feature);
|
|
188
|
-
const featureName = getName(feature);
|
|
189
|
-
-%>
|
|
190
|
-
case <%- className %>.<%- fid.name %>:
|
|
191
|
-
<% if (featureIsMany) { -%>
|
|
192
|
-
this._<%- featureName %> = [];
|
|
193
|
-
<% } else if (defaultValue !== null) { -%>
|
|
194
|
-
this._<%- featureName %> = <%- defaultValue %>;
|
|
195
|
-
<% } else { -%>
|
|
196
|
-
this._<%- featureName %> = undefined;
|
|
197
|
-
<% } -%>
|
|
198
|
-
return;
|
|
199
|
-
<% } -%>
|
|
200
|
-
default:
|
|
201
|
-
super.eUnset(feature);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
<% for (const genOp of operations) {
|
|
206
|
-
const op = genOp.ecoreOperation;
|
|
207
|
-
const opName = getName(op);
|
|
208
|
-
const opType = getEType(op);
|
|
209
|
-
const returnType = opType ? typeMapper.mapClassifier(opType) : 'void';
|
|
210
|
-
const params = [];
|
|
211
|
-
for (const param of getEParameters(op)) {
|
|
212
|
-
const paramName = getName(param);
|
|
213
|
-
const paramType = typeMapper.mapClassifier(getEType(param));
|
|
214
|
-
params.push(`${paramName}: ${paramType}`);
|
|
215
|
-
}
|
|
216
|
-
-%>
|
|
217
|
-
<%- opName %>(<%- params.join(', ') %>): <%- returnType %> {
|
|
218
|
-
<% if (genOp.body) { -%>
|
|
219
|
-
<%- genOp.body %>
|
|
220
|
-
<% } else { -%>
|
|
221
|
-
throw new Error('<%- opName %> not implemented');
|
|
222
|
-
<% } -%>
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
<% } -%>
|
|
226
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* <%- genEnum.documentation || enumName %>
|
|
5
|
-
* @generated
|
|
6
|
-
*/
|
|
7
|
-
export const <%- enumName %> = {
|
|
8
|
-
<% for (let i = 0; i < literals.length; i++) {
|
|
9
|
-
const literal = literals[i];
|
|
10
|
-
const literalName = getName(literal);
|
|
11
|
-
-%>
|
|
12
|
-
<%- literalName %>: '<%- literalName %>'<% if (i < literals.length - 1) { %>,<% } %>
|
|
13
|
-
<% } -%>
|
|
14
|
-
} as const;
|
|
15
|
-
|
|
16
|
-
export type <%- enumName %> = typeof <%- enumName %>[keyof typeof <%- enumName %>];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get enum value by name
|
|
20
|
-
*/
|
|
21
|
-
export function get<%- enumName %>(name: string): <%- enumName %> | undefined {
|
|
22
|
-
return (<%- enumName %> as Record<string, string>)[name] as <%- enumName %> | undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get enum value by literal
|
|
27
|
-
*/
|
|
28
|
-
export function get<%- enumName %>ByLiteral(literal: string): <%- enumName %> | undefined {
|
|
29
|
-
<% for (const literal of literals) {
|
|
30
|
-
const litName = getLiteral(literal) || getName(literal);
|
|
31
|
-
const enumName2 = getName(literal);
|
|
32
|
-
-%>
|
|
33
|
-
if (literal === '<%- litName %>') return <%- enumName %>.<%- enumName2 %>;
|
|
34
|
-
<% } -%>
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
import { BasicEFactory } from '@emfts/core';
|
|
4
|
-
import type { EClass, EObject } from '@emfts/core';
|
|
5
|
-
import { <%- packageName %>Package } from './<%- packageName %>Package';
|
|
6
|
-
<% for (const genClass of concreteClasses) {
|
|
7
|
-
const className = genClass.ecoreClass.getName();
|
|
8
|
-
const implName = genClass.implClassName || (className + 'Impl');
|
|
9
|
-
-%>
|
|
10
|
-
import type { <%- className %> } from './<%- className %>';
|
|
11
|
-
import { <%- implName %> } from './<%- implName %>';
|
|
12
|
-
<% } -%>
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Factory for creating <%- packageName %> model objects
|
|
16
|
-
* @generated
|
|
17
|
-
*/
|
|
18
|
-
export class <%- packageName %>Factory extends BasicEFactory {
|
|
19
|
-
// Singleton instance
|
|
20
|
-
static readonly eINSTANCE = new <%- packageName %>Factory();
|
|
21
|
-
|
|
22
|
-
private constructor() {
|
|
23
|
-
super();
|
|
24
|
-
this.setEPackage(<%- packageName %>Package.eINSTANCE);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
<% for (const genClass of concreteClasses) {
|
|
28
|
-
const className = genClass.ecoreClass.getName();
|
|
29
|
-
const implName = genClass.implClassName || (className + 'Impl');
|
|
30
|
-
-%>
|
|
31
|
-
/**
|
|
32
|
-
* Create a new <%- className %> instance
|
|
33
|
-
*/
|
|
34
|
-
create<%- className %>(): <%- className %> {
|
|
35
|
-
return new <%- implName %>();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
<% } -%>
|
|
39
|
-
/**
|
|
40
|
-
* Create an instance of the given class
|
|
41
|
-
*/
|
|
42
|
-
override create(eClass: EClass): EObject {
|
|
43
|
-
switch (eClass.getName()) {
|
|
44
|
-
<% for (const genClass of concreteClasses) {
|
|
45
|
-
const className = genClass.ecoreClass.getName();
|
|
46
|
-
-%>
|
|
47
|
-
case '<%- className %>':
|
|
48
|
-
return this.create<%- className %>();
|
|
49
|
-
<% } -%>
|
|
50
|
-
default:
|
|
51
|
-
throw new Error(`Unknown class: ${eClass.getName()}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
// Package and Factory
|
|
4
|
-
export { <%- packageName %>Package } from './<%- packageName %>Package';
|
|
5
|
-
export { <%- packageName %>Factory } from './<%- packageName %>Factory';
|
|
6
|
-
|
|
7
|
-
// Interfaces
|
|
8
|
-
<% for (const genClass of genClasses) {
|
|
9
|
-
const name = getName(genClass.ecoreClass);
|
|
10
|
-
-%>
|
|
11
|
-
export type { <%- name %> } from './<%- name %>';
|
|
12
|
-
<% } -%>
|
|
13
|
-
|
|
14
|
-
// Implementations
|
|
15
|
-
<% for (const genClass of genClasses) {
|
|
16
|
-
if (!checkIsAbstract(genClass.ecoreClass) && !checkIsInterface(genClass.ecoreClass)) {
|
|
17
|
-
const implName = genClass.implClassName || (getName(genClass.ecoreClass) + 'Impl');
|
|
18
|
-
-%>
|
|
19
|
-
export { <%- implName %> } from './<%- implName %>';
|
|
20
|
-
<%
|
|
21
|
-
}
|
|
22
|
-
} -%>
|
|
23
|
-
|
|
24
|
-
// Enums
|
|
25
|
-
<% for (const genEnum of genEnums) {
|
|
26
|
-
const name = getName(genEnum.ecoreEnum);
|
|
27
|
-
-%>
|
|
28
|
-
export { <%- name %>, get<%- name %>, get<%- name %>ByLiteral } from './<%- name %>';
|
|
29
|
-
<% } -%>
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
import type { EObject } from '@emfts/core';
|
|
4
|
-
<%# Generate imports for referenced types -%>
|
|
5
|
-
<%
|
|
6
|
-
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'emf');
|
|
7
|
-
// Skip emfts types and self-references
|
|
8
|
-
for (const imp of imports) {
|
|
9
|
-
if (imp.typeName !== interfaceName && imp.importPath !== '@emfts/core') {
|
|
10
|
-
-%>
|
|
11
|
-
import type { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
12
|
-
<%
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
-%>
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* <%- genClass.documentation || interfaceName %>
|
|
19
|
-
* @generated
|
|
20
|
-
*/
|
|
21
|
-
export interface <%- interfaceName %><%
|
|
22
|
-
if (typeParameters && typeParameters.length > 0) {
|
|
23
|
-
const params = [];
|
|
24
|
-
for (const tp of typeParameters) {
|
|
25
|
-
params.push(getName(tp));
|
|
26
|
-
}
|
|
27
|
-
%><<%- params.join(', ') %>><%
|
|
28
|
-
}
|
|
29
|
-
%> extends <%
|
|
30
|
-
if (superTypes && superTypes.length > 0) {
|
|
31
|
-
const superNames = [];
|
|
32
|
-
for (const st of superTypes) {
|
|
33
|
-
const stName = getName(st);
|
|
34
|
-
if (stName) {
|
|
35
|
-
superNames.push(stName);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (superNames.length > 0) {
|
|
39
|
-
%><%- superNames.join(', ') %><%
|
|
40
|
-
} else {
|
|
41
|
-
%><%- rootExtendsInterface %><%
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
%><%- rootExtendsInterface %><%
|
|
45
|
-
}
|
|
46
|
-
%> {
|
|
47
|
-
<% for (const genFeature of features) {
|
|
48
|
-
const feature = genFeature.ecoreFeature;
|
|
49
|
-
const featureName = getName(feature);
|
|
50
|
-
const featureType = typeMapper.mapFeature(feature);
|
|
51
|
-
const many = isMany(feature);
|
|
52
|
-
const lower = getLowerBound(feature);
|
|
53
|
-
const isReadonly = genFeature.property === 'readonly';
|
|
54
|
-
-%>
|
|
55
|
-
<% if (isReadonly) { %>readonly <% } %><%- featureName %><% if (lower === 0 && !many) { %>?<% } %>: <%- featureType %>;
|
|
56
|
-
<% } -%>
|
|
57
|
-
|
|
58
|
-
<% for (const genOp of operations) {
|
|
59
|
-
const op = genOp.ecoreOperation;
|
|
60
|
-
const opName = getName(op);
|
|
61
|
-
const opType = getEType(op);
|
|
62
|
-
const returnType = opType ? typeMapper.mapClassifier(opType) : 'void';
|
|
63
|
-
const params = [];
|
|
64
|
-
for (const param of getEParameters(op)) {
|
|
65
|
-
const paramName = getName(param);
|
|
66
|
-
const paramType = typeMapper.mapClassifier(getEType(param));
|
|
67
|
-
params.push(`${paramName}: ${paramType}`);
|
|
68
|
-
}
|
|
69
|
-
-%>
|
|
70
|
-
<%- opName %>(<%- params.join(', ') %>): <%- returnType %>;
|
|
71
|
-
<% } -%>
|
|
72
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
import { BasicEPackage, BasicEClass, BasicEAttribute, BasicEReference } from '@emfts/core';
|
|
4
|
-
import type { EClass, EAttribute, EReference, EEnum } from '@emfts/core';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* <%- packageName %> Package
|
|
8
|
-
* @generated
|
|
9
|
-
*/
|
|
10
|
-
export class <%- packageName %>Package extends BasicEPackage {
|
|
11
|
-
static readonly eNAME = '<%- getName(ePackage) %>';
|
|
12
|
-
static readonly eNS_URI = '<%- nsURI %>';
|
|
13
|
-
static readonly eNS_PREFIX = '<%- nsPrefix %>';
|
|
14
|
-
|
|
15
|
-
// Singleton instance
|
|
16
|
-
private static _instance: <%- packageName %>Package;
|
|
17
|
-
|
|
18
|
-
static get eINSTANCE(): <%- packageName %>Package {
|
|
19
|
-
if (!this._instance) {
|
|
20
|
-
this._instance = new <%- packageName %>Package();
|
|
21
|
-
this._instance.init();
|
|
22
|
-
}
|
|
23
|
-
return this._instance;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Literals for quick access to metaclasses and features
|
|
28
|
-
*/
|
|
29
|
-
static readonly Literals = {
|
|
30
|
-
<% for (const cls of classLiterals) { -%>
|
|
31
|
-
<%- cls.upperName %>: null as unknown as EClass,
|
|
32
|
-
<% for (const feat of cls.features) { -%>
|
|
33
|
-
<%- cls.upperName %>__<%- feat.upperName %>: null as unknown as EAttribute | EReference,
|
|
34
|
-
<% } -%>
|
|
35
|
-
<% } -%>
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
private constructor() {
|
|
39
|
-
super();
|
|
40
|
-
this.setName(<%- packageName %>Package.eNAME);
|
|
41
|
-
this.setNsURI(<%- packageName %>Package.eNS_URI);
|
|
42
|
-
this.setNsPrefix(<%- packageName %>Package.eNS_PREFIX);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Initialize package contents
|
|
47
|
-
*/
|
|
48
|
-
private init(): void {
|
|
49
|
-
<% for (const genClass of genClasses) {
|
|
50
|
-
const eClass = genClass.ecoreClass;
|
|
51
|
-
const className = getName(eClass);
|
|
52
|
-
const upperName = className.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
53
|
-
-%>
|
|
54
|
-
// Create <%- className %> class
|
|
55
|
-
const <%- uncapitalize(className) %>Class = new BasicEClass();
|
|
56
|
-
<%- uncapitalize(className) %>Class.setName('<%- className %>');
|
|
57
|
-
<%- uncapitalize(className) %>Class.setAbstract(<%- checkIsAbstract(eClass) %>);
|
|
58
|
-
<%- uncapitalize(className) %>Class.setInterface(<%- checkIsInterface(eClass) %>);
|
|
59
|
-
this.getEClassifiers().push(<%- uncapitalize(className) %>Class);
|
|
60
|
-
<%- uncapitalize(className) %>Class.setEPackage(this);
|
|
61
|
-
<%- packageName %>Package.Literals.<%- upperName %> = <%- uncapitalize(className) %>Class;
|
|
62
|
-
|
|
63
|
-
<% let featureIndex = 0;
|
|
64
|
-
for (const genFeature of genClass.genFeatures) {
|
|
65
|
-
const feature = genFeature.ecoreFeature;
|
|
66
|
-
const featureName = getName(feature);
|
|
67
|
-
const featureUpperName = featureName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
68
|
-
const isRef = typeMapper.isReference(feature);
|
|
69
|
-
-%>
|
|
70
|
-
// Create <%- featureName %> feature
|
|
71
|
-
<% if (isRef) { -%>
|
|
72
|
-
const <%- uncapitalize(className) %>_<%- featureName %> = new BasicEReference();
|
|
73
|
-
<%- uncapitalize(className) %>_<%- featureName %>.setContainment(<%- isContainment(feature) %>);
|
|
74
|
-
<% } else { -%>
|
|
75
|
-
const <%- uncapitalize(className) %>_<%- featureName %> = new BasicEAttribute();
|
|
76
|
-
<% } -%>
|
|
77
|
-
<%- uncapitalize(className) %>_<%- featureName %>.setName('<%- featureName %>');
|
|
78
|
-
<%- uncapitalize(className) %>_<%- featureName %>.setLowerBound(<%- getLowerBound(feature) %>);
|
|
79
|
-
<%- uncapitalize(className) %>_<%- featureName %>.setUpperBound(<%- getUpperBound(feature) %>);
|
|
80
|
-
<%- uncapitalize(className) %>Class.getEStructuralFeatures().push(<%- uncapitalize(className) %>_<%- featureName %>);
|
|
81
|
-
<%- packageName %>Package.Literals.<%- upperName %>__<%- featureUpperName %> = <%- uncapitalize(className) %>_<%- featureName %>;
|
|
82
|
-
|
|
83
|
-
<% featureIndex++;
|
|
84
|
-
} -%>
|
|
85
|
-
<% } -%>
|
|
86
|
-
<%# TODO: Enum package metadata initialization - requires BasicEEnum implementation in emfts -%>
|
|
87
|
-
|
|
88
|
-
// ============================================
|
|
89
|
-
// Set ESuperTypes (must be done after all classes are created)
|
|
90
|
-
// ============================================
|
|
91
|
-
<% for (const genClass of genClasses) {
|
|
92
|
-
const eClass = genClass.ecoreClass;
|
|
93
|
-
const className = getName(eClass);
|
|
94
|
-
const upperName = className.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
95
|
-
const superTypes = getESuperTypes(eClass);
|
|
96
|
-
for (const superType of superTypes) {
|
|
97
|
-
const superTypeName = getName(superType);
|
|
98
|
-
if (superTypeName) {
|
|
99
|
-
const superTypeUpperName = superTypeName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
100
|
-
-%>
|
|
101
|
-
(<%- packageName %>Package.Literals.<%- upperName %> as BasicEClass).getESuperTypes().push(<%- packageName %>Package.Literals.<%- superTypeUpperName %>);
|
|
102
|
-
<% }
|
|
103
|
-
}
|
|
104
|
-
} -%>
|
|
105
|
-
|
|
106
|
-
// ============================================
|
|
107
|
-
// Set ETypes for EReferences (must be done after all classes are created)
|
|
108
|
-
// ============================================
|
|
109
|
-
<% for (const genClass of genClasses) {
|
|
110
|
-
const eClass = genClass.ecoreClass;
|
|
111
|
-
const className = getName(eClass);
|
|
112
|
-
const upperName = className.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
113
|
-
for (const genFeature of genClass.genFeatures) {
|
|
114
|
-
const feature = genFeature.ecoreFeature;
|
|
115
|
-
const featureName = getName(feature);
|
|
116
|
-
const featureUpperName = featureName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
117
|
-
const isRef = typeMapper.isReference(feature);
|
|
118
|
-
if (isRef) {
|
|
119
|
-
const eType = getEType(feature);
|
|
120
|
-
if (eType) {
|
|
121
|
-
const typeName = getName(eType);
|
|
122
|
-
const typeUpperName = typeName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
123
|
-
-%>
|
|
124
|
-
(<%- packageName %>Package.Literals.<%- upperName %>__<%- featureUpperName %> as BasicEReference).setEType(<%- packageName %>Package.Literals.<%- typeUpperName %>);
|
|
125
|
-
<% }
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} -%>
|
|
129
|
-
|
|
130
|
-
// ============================================
|
|
131
|
-
// Register XML name mappings from ExtendedMetaData annotations
|
|
132
|
-
// ============================================
|
|
133
|
-
<% for (const genClass of genClasses) {
|
|
134
|
-
const eClass = genClass.ecoreClass;
|
|
135
|
-
const className = getName(eClass);
|
|
136
|
-
const upperName = className.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
137
|
-
for (const genFeature of genClass.genFeatures) {
|
|
138
|
-
const feature = genFeature.ecoreFeature;
|
|
139
|
-
const featureName = getName(feature);
|
|
140
|
-
const xmlName = getExtendedMetaDataName(feature);
|
|
141
|
-
if (xmlName && xmlName !== featureName) {
|
|
142
|
-
const featureUpperName = featureName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
143
|
-
-%>
|
|
144
|
-
(<%- packageName %>Package.Literals.<%- upperName %> as BasicEClass).registerXmlName('<%- xmlName %>', <%- packageName %>Package.Literals.<%- upperName %>__<%- featureUpperName %>);
|
|
145
|
-
<% }
|
|
146
|
-
}
|
|
147
|
-
} -%>
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
<%# Generate imports for referenced types -%>
|
|
4
|
-
<%
|
|
5
|
-
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'plain');
|
|
6
|
-
for (const imp of imports) {
|
|
7
|
-
if (imp.typeName !== className) {
|
|
8
|
-
-%>
|
|
9
|
-
import { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
10
|
-
<%
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
-%>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* <%- genClass.documentation || eClass.getName() %>
|
|
17
|
-
*/
|
|
18
|
-
export <% if (isAbstract) { %>abstract <% } %>class <%- className %><%
|
|
19
|
-
if (typeParameters && typeParameters.length > 0) {
|
|
20
|
-
const params = [];
|
|
21
|
-
for (const tp of typeParameters) {
|
|
22
|
-
params.push(tp.getName());
|
|
23
|
-
}
|
|
24
|
-
%><<%- params.join(', ') %>><%
|
|
25
|
-
}
|
|
26
|
-
if (superTypes && superTypes.length > 0) {
|
|
27
|
-
const superNames = [];
|
|
28
|
-
for (const st of superTypes) {
|
|
29
|
-
if (st.getName) {
|
|
30
|
-
superNames.push(st.getName());
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (superNames.length > 0) {
|
|
34
|
-
%> extends <%- superNames[0] %><%
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
%> {
|
|
38
|
-
<% for (const genFeature of features) {
|
|
39
|
-
const feature = genFeature.ecoreFeature;
|
|
40
|
-
const featureName = feature.getName();
|
|
41
|
-
const featureType = typeMapper.mapFeature(feature);
|
|
42
|
-
const defaultValue = typeMapper.getDefaultValue(feature);
|
|
43
|
-
const isMany = feature.isMany();
|
|
44
|
-
-%>
|
|
45
|
-
<%- featureName %><% if (!isMany && defaultValue === null) { %>?<% } %>: <%- featureType %><% if (defaultValue !== null) { %> = <%- defaultValue %><% } %>;
|
|
46
|
-
<% } -%>
|
|
47
|
-
|
|
48
|
-
<% if (features.length > 0) { -%>
|
|
49
|
-
constructor(init?: Partial<<%- className %>>) {
|
|
50
|
-
<% if (superTypes && superTypes.length > 0) { -%>
|
|
51
|
-
super(init);
|
|
52
|
-
<% } -%>
|
|
53
|
-
if (init) {
|
|
54
|
-
Object.assign(this, init);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
<% } -%>
|
|
58
|
-
|
|
59
|
-
<% for (const genOp of operations) {
|
|
60
|
-
const op = genOp.ecoreOperation;
|
|
61
|
-
const opName = op.getName();
|
|
62
|
-
const returnType = op.getEType() ? typeMapper.mapClassifier(op.getEType()) : 'void';
|
|
63
|
-
const params = [];
|
|
64
|
-
for (const param of op.getEParameters()) {
|
|
65
|
-
const paramName = param.getName();
|
|
66
|
-
const paramType = typeMapper.mapClassifier(param.getEType());
|
|
67
|
-
params.push(`${paramName}: ${paramType}`);
|
|
68
|
-
}
|
|
69
|
-
-%>
|
|
70
|
-
<%- opName %>(<%- params.join(', ') %>): <%- returnType %> {
|
|
71
|
-
throw new Error('<%- opName %> not implemented');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
<% } -%>
|
|
75
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* <%- genEnum.documentation || enumName %>
|
|
5
|
-
*/
|
|
6
|
-
<% if (generateAsConst) { -%>
|
|
7
|
-
export const <%- enumName %> = {
|
|
8
|
-
<% for (let i = 0; i < literals.length; i++) {
|
|
9
|
-
const literal = literals[i];
|
|
10
|
-
const literalName = literal.getLiteral() || literal.getName();
|
|
11
|
-
const value = useStringValues ? `'${literalName}'` : literal.getValue();
|
|
12
|
-
-%>
|
|
13
|
-
<%- literal.getName() %>: <%- value %><% if (i < literals.length - 1) { %>,<% } %>
|
|
14
|
-
<% } -%>
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
|
-
export type <%- enumName %> = typeof <%- enumName %>[keyof typeof <%- enumName %>];
|
|
18
|
-
<% } else { -%>
|
|
19
|
-
export enum <%- enumName %> {
|
|
20
|
-
<% for (let i = 0; i < literals.length; i++) {
|
|
21
|
-
const literal = literals[i];
|
|
22
|
-
const literalName = literal.getLiteral() || literal.getName();
|
|
23
|
-
const value = useStringValues ? `'${literalName}'` : literal.getValue();
|
|
24
|
-
-%>
|
|
25
|
-
<%- literal.getName() %> = <%- value %><% if (i < literals.length - 1) { %>,<% } %>
|
|
26
|
-
<% } -%>
|
|
27
|
-
}
|
|
28
|
-
<% } -%>
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
<%- header %>
|
|
2
|
-
|
|
3
|
-
<%# Generate imports for referenced types -%>
|
|
4
|
-
<%
|
|
5
|
-
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'plain');
|
|
6
|
-
for (const imp of imports) {
|
|
7
|
-
if (imp.typeName !== interfaceName) {
|
|
8
|
-
-%>
|
|
9
|
-
import type { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
10
|
-
<%
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
-%>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* <%- genClass.documentation || eClass.getName() %>
|
|
17
|
-
*/
|
|
18
|
-
export interface <%- interfaceName %><%
|
|
19
|
-
if (typeParameters && typeParameters.length > 0) {
|
|
20
|
-
const params = [];
|
|
21
|
-
for (const tp of typeParameters) {
|
|
22
|
-
params.push(tp.getName());
|
|
23
|
-
}
|
|
24
|
-
%><<%- params.join(', ') %>><%
|
|
25
|
-
}
|
|
26
|
-
if (superTypes && superTypes.length > 0) {
|
|
27
|
-
const superNames = [];
|
|
28
|
-
for (const st of superTypes) {
|
|
29
|
-
if (st.getName) {
|
|
30
|
-
superNames.push(st.getName());
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (superNames.length > 0) {
|
|
34
|
-
%> extends <%- superNames.join(', ') %><%
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
%> {
|
|
38
|
-
<% for (const genFeature of features) {
|
|
39
|
-
const feature = genFeature.ecoreFeature;
|
|
40
|
-
const featureName = feature.getName();
|
|
41
|
-
const featureType = typeMapper.mapFeature(feature);
|
|
42
|
-
const isMany = feature.isMany();
|
|
43
|
-
const lowerBound = feature.getLowerBound();
|
|
44
|
-
-%>
|
|
45
|
-
<%- featureName %><% if (lowerBound === 0 && !isMany) { %>?<% } %>: <%- featureType %>;
|
|
46
|
-
<% } -%>
|
|
47
|
-
|
|
48
|
-
<% for (const genOp of operations) {
|
|
49
|
-
const op = genOp.ecoreOperation;
|
|
50
|
-
const opName = op.getName();
|
|
51
|
-
const returnType = op.getEType() ? typeMapper.mapClassifier(op.getEType()) : 'void';
|
|
52
|
-
const params = [];
|
|
53
|
-
for (const param of op.getEParameters()) {
|
|
54
|
-
const paramName = param.getName();
|
|
55
|
-
const paramType = typeMapper.mapClassifier(param.getEType());
|
|
56
|
-
params.push(`${paramName}: ${paramType}`);
|
|
57
|
-
}
|
|
58
|
-
-%>
|
|
59
|
-
<%- opName %>(<%- params.join(', ') %>): <%- returnType %>;
|
|
60
|
-
<% } -%>
|
|
61
|
-
}
|