@emfts/codegen 0.0.1-next.3 → 0.0.1-next.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/generator/GeneratorContext.d.ts.map +1 -1
- package/dist/generator/GeneratorContext.js +2 -0
- package/dist/generator/GeneratorContext.js.map +1 -1
- package/dist/templates/partials/emf/class-file.ejs +26 -29
- package/dist/templates/partials/emf/interface-file.ejs +13 -7
- package/dist/templates/partials/emf/package-file.ejs +70 -5
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorContext.d.ts","sourceRoot":"","sources":["../../src/generator/GeneratorContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"GeneratorContext.d.ts","sourceRoot":"","sources":["../../src/generator/GeneratorContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD;;GAEG;AACH,MAAM,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GxB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TypeMapper } from './TypeMapper.js';
|
|
2
2
|
import { ImportResolver } from './ImportResolver.js';
|
|
3
|
+
const ECORE_NS_URI = 'http://www.eclipse.org/emf/2002/Ecore';
|
|
3
4
|
/**
|
|
4
5
|
* Context shared during code generation
|
|
5
6
|
*/
|
|
@@ -16,6 +17,7 @@ export class GeneratorContext {
|
|
|
16
17
|
this.options = options;
|
|
17
18
|
this.typeMapper = new TypeMapper();
|
|
18
19
|
this.importResolver = new ImportResolver();
|
|
20
|
+
this.importResolver.registerPackage(ECORE_NS_URI, '@emfts/core');
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Set the current package being processed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorContext.js","sourceRoot":"","sources":["../../src/generator/GeneratorContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"GeneratorContext.js","sourceRoot":"","sources":["../../src/generator/GeneratorContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,MAAM,YAAY,GAAG,uCAAuC,CAAC;AAY7D;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAClB,QAAQ,CAAW;IACnB,OAAO,CAAmB;IAC1B,UAAU,CAAa;IACvB,cAAc,CAAiB;IAC/B,WAAW,GAAiB,EAAE,CAAC;IAEhC,cAAc,GAAsB,IAAI,CAAC;IACzC,YAAY,GAAoB,IAAI,CAAC;IAE7C,YAAY,QAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,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U,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QACjC,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;YAChC,OAAO,UAAU,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAChF,CAAC;QAED,OAAO;;;;;IAKP,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,QAAgB,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC9F,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
<%- header %>
|
|
2
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
3
|
<%
|
|
9
4
|
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'emf');
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
// Separate into type-only and value imports
|
|
5
|
+
const hardcodedCoreTypes = ['BasicEObject', 'EClass', 'EStructuralFeature'];
|
|
6
|
+
const coreTypeImports = ['EClass', 'EStructuralFeature'];
|
|
13
7
|
const typeOnlyImports = [];
|
|
14
8
|
const valueImports = [];
|
|
15
9
|
for (const imp of imports) {
|
|
16
|
-
if (imp.typeName
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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);
|
|
10
|
+
if (imp.typeName === className || imp.typeName === interfaceName || imp.typeName === extendsClass) continue;
|
|
11
|
+
if (hardcodedCoreTypes.includes(imp.typeName)) continue;
|
|
12
|
+
if (imp.importPath === '@emfts/core') {
|
|
13
|
+
if (!coreTypeImports.includes(imp.typeName)) {
|
|
14
|
+
coreTypeImports.push(imp.typeName);
|
|
29
15
|
}
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
// Check if this type is used as a runtime value (e.g., enum default values)
|
|
19
|
+
const usedAsValue = features.some(gf => {
|
|
20
|
+
const dv = typeMapper.getDefaultValue(gf.ecoreFeature);
|
|
21
|
+
return dv !== null && typeof dv === 'string' && dv.startsWith(imp.typeName + '.');
|
|
22
|
+
});
|
|
23
|
+
if (usedAsValue) {
|
|
24
|
+
valueImports.push(imp);
|
|
25
|
+
} else {
|
|
26
|
+
typeOnlyImports.push(imp);
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
for (const imp of typeOnlyImports) {
|
|
33
29
|
-%>
|
|
30
|
+
<% if (!extendsImport) { -%>
|
|
31
|
+
import { BasicEObject } from '@emfts/core';
|
|
32
|
+
<% } -%>
|
|
33
|
+
import type { <%- coreTypeImports.join(', ') %> } from '@emfts/core';
|
|
34
|
+
<% for (const imp of typeOnlyImports) { -%>
|
|
34
35
|
import type { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
35
|
-
<%
|
|
36
|
-
|
|
37
|
-
for (const imp of valueImports) {
|
|
38
|
-
-%>
|
|
36
|
+
<% } -%>
|
|
37
|
+
<% for (const imp of valueImports) { -%>
|
|
39
38
|
import { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
40
|
-
<%
|
|
41
|
-
}
|
|
42
|
-
-%>
|
|
39
|
+
<% } -%>
|
|
43
40
|
<% if (extendsImport) { -%>
|
|
44
41
|
import { <%- extendsClass %> } from '<%- extendsImport %>';
|
|
45
42
|
<% } -%>
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
<%- header %>
|
|
2
2
|
|
|
3
|
-
import type { EObject } from '@emfts/core';
|
|
4
|
-
<%# Generate imports for referenced types -%>
|
|
5
3
|
<%
|
|
6
4
|
const imports = importResolver.resolveImportsForClass(eClass, genPackage, 'emf');
|
|
7
|
-
|
|
5
|
+
const coreTypeImports = ['EObject'];
|
|
6
|
+
const otherTypeImports = [];
|
|
8
7
|
for (const imp of imports) {
|
|
9
|
-
if (imp.typeName
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if (imp.typeName === interfaceName) continue;
|
|
9
|
+
if (imp.importPath === '@emfts/core') {
|
|
10
|
+
if (!coreTypeImports.includes(imp.typeName)) {
|
|
11
|
+
coreTypeImports.push(imp.typeName);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
otherTypeImports.push(imp);
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
-%>
|
|
18
|
+
import type { <%- coreTypeImports.join(', ') %> } from '@emfts/core';
|
|
19
|
+
<% for (const imp of otherTypeImports) { -%>
|
|
20
|
+
import type { <%- imp.typeName %> } from '<%- imp.importPath %>';
|
|
21
|
+
<% } -%>
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* <%- genClass.documentation || interfaceName %>
|
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
<%- header %>
|
|
2
2
|
|
|
3
|
+
<%
|
|
4
|
+
const ECORE_NS_URI = 'http://www.eclipse.org/emf/2002/Ecore';
|
|
5
|
+
|
|
6
|
+
// Helper: check if a classifier belongs to the current package
|
|
7
|
+
function isLocalClassifier(classifier) {
|
|
8
|
+
const pkg = getEPackage(classifier);
|
|
9
|
+
if (pkg) {
|
|
10
|
+
const pkgNsURI = pkg.getNsURI?.() ?? null;
|
|
11
|
+
return pkgNsURI === nsURI;
|
|
12
|
+
}
|
|
13
|
+
// For proxies, check the proxy URI
|
|
14
|
+
if (typeof classifier.eIsProxy === 'function' && classifier.eIsProxy() && typeof classifier.eProxyURI === 'function') {
|
|
15
|
+
const proxyURI = classifier.eProxyURI()?.toString() ?? '';
|
|
16
|
+
return !proxyURI.startsWith('http://') && !proxyURI.startsWith('https://');
|
|
17
|
+
}
|
|
18
|
+
return true; // assume local if unknown
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Helper: check if a classifier is from the Ecore metamodel
|
|
22
|
+
function isEcoreClassifier(classifier) {
|
|
23
|
+
const pkg = getEPackage(classifier);
|
|
24
|
+
if (pkg) {
|
|
25
|
+
const pkgNsURI = pkg.getNsURI?.() ?? null;
|
|
26
|
+
return pkgNsURI === ECORE_NS_URI;
|
|
27
|
+
}
|
|
28
|
+
// For proxies, check the proxy URI
|
|
29
|
+
if (typeof classifier.eIsProxy === 'function' && classifier.eIsProxy() && typeof classifier.eProxyURI === 'function') {
|
|
30
|
+
const proxyURI = classifier.eProxyURI()?.toString() ?? '';
|
|
31
|
+
return proxyURI.startsWith(ECORE_NS_URI);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Helper: generate the right expression for a type reference
|
|
37
|
+
function typeRefExpr(classifier) {
|
|
38
|
+
const typeName = getName(classifier);
|
|
39
|
+
if (isLocalClassifier(classifier)) {
|
|
40
|
+
const typeUpperName = typeName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
41
|
+
return packageName + 'Package.Literals.' + typeUpperName;
|
|
42
|
+
}
|
|
43
|
+
if (isEcoreClassifier(classifier)) {
|
|
44
|
+
return "getEcorePackage().getEClassifier('" + typeName + "')!";
|
|
45
|
+
}
|
|
46
|
+
// Fallback for other external packages
|
|
47
|
+
return "getEcorePackage().getEClassifier('" + typeName + "')!";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Pre-scan: check if any cross-package Ecore references exist
|
|
51
|
+
let needsEcoreImport = false;
|
|
52
|
+
for (const genClass of genClasses) {
|
|
53
|
+
const eClass = genClass.ecoreClass;
|
|
54
|
+
for (const superType of getESuperTypes(eClass)) {
|
|
55
|
+
if (!isLocalClassifier(superType)) { needsEcoreImport = true; break; }
|
|
56
|
+
}
|
|
57
|
+
if (needsEcoreImport) break;
|
|
58
|
+
for (const genFeature of genClass.genFeatures) {
|
|
59
|
+
const eType = getEType(genFeature.ecoreFeature);
|
|
60
|
+
if (eType && typeMapper.isReference(genFeature.ecoreFeature) && !isLocalClassifier(eType)) {
|
|
61
|
+
needsEcoreImport = true; break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (needsEcoreImport) break;
|
|
65
|
+
}
|
|
66
|
+
-%>
|
|
67
|
+
<% if (needsEcoreImport) { -%>
|
|
68
|
+
import { BasicEPackage, BasicEClass, BasicEAttribute, BasicEReference, getEcorePackage } from '@emfts/core';
|
|
69
|
+
<% } else { -%>
|
|
3
70
|
import { BasicEPackage, BasicEClass, BasicEAttribute, BasicEReference } from '@emfts/core';
|
|
71
|
+
<% } -%>
|
|
4
72
|
import type { EClass, EAttribute, EReference, EEnum } from '@emfts/core';
|
|
5
73
|
|
|
6
74
|
/**
|
|
@@ -96,9 +164,8 @@ export class <%- packageName %>Package extends BasicEPackage {
|
|
|
96
164
|
for (const superType of superTypes) {
|
|
97
165
|
const superTypeName = getName(superType);
|
|
98
166
|
if (superTypeName) {
|
|
99
|
-
const superTypeUpperName = superTypeName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
100
167
|
-%>
|
|
101
|
-
(<%- packageName %>Package.Literals.<%- upperName %> as BasicEClass).getESuperTypes().push(<%-
|
|
168
|
+
(<%- packageName %>Package.Literals.<%- upperName %> as BasicEClass).getESuperTypes().push(<%- typeRefExpr(superType) %>);
|
|
102
169
|
<% }
|
|
103
170
|
}
|
|
104
171
|
} -%>
|
|
@@ -118,10 +185,8 @@ export class <%- packageName %>Package extends BasicEPackage {
|
|
|
118
185
|
if (isRef) {
|
|
119
186
|
const eType = getEType(feature);
|
|
120
187
|
if (eType) {
|
|
121
|
-
const typeName = getName(eType);
|
|
122
|
-
const typeUpperName = typeName.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
|
|
123
188
|
-%>
|
|
124
|
-
(<%- packageName %>Package.Literals.<%- upperName %>__<%- featureUpperName %> as BasicEReference).setEType(<%-
|
|
189
|
+
(<%- packageName %>Package.Literals.<%- upperName %>__<%- featureUpperName %> as BasicEReference).setEType(<%- typeRefExpr(eType) %>);
|
|
125
190
|
<% }
|
|
126
191
|
}
|
|
127
192
|
}
|