@emfts/codegen 0.0.1-next.4 → 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.
@@ -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(<%- packageName %>Package.Literals.<%- superTypeUpperName %>);
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(<%- packageName %>Package.Literals.<%- typeUpperName %>);
189
+ (<%- packageName %>Package.Literals.<%- upperName %>__<%- featureUpperName %> as BasicEReference).setEType(<%- typeRefExpr(eType) %>);
125
190
  <% }
126
191
  }
127
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emfts/codegen",
3
- "version": "0.0.1-next.4",
3
+ "version": "0.0.1-next.5",
4
4
  "description": "TypeScript code generator for Ecore models using emfts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",