@emfts/codegen 0.0.1-next.1

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.
Files changed (184) hide show
  1. package/README.md +39 -0
  2. package/dist/cli/commands/generate-rest-client.d.ts +3 -0
  3. package/dist/cli/commands/generate-rest-client.d.ts.map +1 -0
  4. package/dist/cli/commands/generate-rest-client.js +38 -0
  5. package/dist/cli/commands/generate-rest-client.js.map +1 -0
  6. package/dist/cli/commands/generate.d.ts +3 -0
  7. package/dist/cli/commands/generate.d.ts.map +1 -0
  8. package/dist/cli/commands/generate.js +108 -0
  9. package/dist/cli/commands/generate.js.map +1 -0
  10. package/dist/cli/commands/init.d.ts +3 -0
  11. package/dist/cli/commands/init.d.ts.map +1 -0
  12. package/dist/cli/commands/init.js +57 -0
  13. package/dist/cli/commands/init.js.map +1 -0
  14. package/dist/cli/index.d.ts +3 -0
  15. package/dist/cli/index.d.ts.map +1 -0
  16. package/dist/cli/index.js +15 -0
  17. package/dist/cli/index.js.map +1 -0
  18. package/dist/debug-abstract.d.ts +2 -0
  19. package/dist/debug-abstract.d.ts.map +1 -0
  20. package/dist/debug-abstract.js +25 -0
  21. package/dist/debug-abstract.js.map +1 -0
  22. package/dist/debug-genmodel.d.ts +2 -0
  23. package/dist/debug-genmodel.d.ts.map +1 -0
  24. package/dist/debug-genmodel.js +41 -0
  25. package/dist/debug-genmodel.js.map +1 -0
  26. package/dist/genconfig/GenConfig.d.ts +125 -0
  27. package/dist/genconfig/GenConfig.d.ts.map +1 -0
  28. package/dist/genconfig/GenConfig.js +46 -0
  29. package/dist/genconfig/GenConfig.js.map +1 -0
  30. package/dist/genconfig/GenConfigConverter.d.ts +64 -0
  31. package/dist/genconfig/GenConfigConverter.d.ts.map +1 -0
  32. package/dist/genconfig/GenConfigConverter.js +293 -0
  33. package/dist/genconfig/GenConfigConverter.js.map +1 -0
  34. package/dist/genconfig/GenConfigLoader.d.ts +83 -0
  35. package/dist/genconfig/GenConfigLoader.d.ts.map +1 -0
  36. package/dist/genconfig/GenConfigLoader.js +455 -0
  37. package/dist/genconfig/GenConfigLoader.js.map +1 -0
  38. package/dist/genconfig/index.d.ts +4 -0
  39. package/dist/genconfig/index.d.ts.map +1 -0
  40. package/dist/genconfig/index.js +4 -0
  41. package/dist/genconfig/index.js.map +1 -0
  42. package/dist/generator/CodeGenerator.d.ts +45 -0
  43. package/dist/generator/CodeGenerator.d.ts.map +1 -0
  44. package/dist/generator/CodeGenerator.js +142 -0
  45. package/dist/generator/CodeGenerator.js.map +1 -0
  46. package/dist/generator/GeneratedFile.d.ts +23 -0
  47. package/dist/generator/GeneratedFile.d.ts.map +1 -0
  48. package/dist/generator/GeneratedFile.js +42 -0
  49. package/dist/generator/GeneratedFile.js.map +1 -0
  50. package/dist/generator/GeneratorContext.d.ts +73 -0
  51. package/dist/generator/GeneratorContext.d.ts.map +1 -0
  52. package/dist/generator/GeneratorContext.js +99 -0
  53. package/dist/generator/GeneratorContext.js.map +1 -0
  54. package/dist/generator/GeneratorOptions.d.ts +26 -0
  55. package/dist/generator/GeneratorOptions.d.ts.map +1 -0
  56. package/dist/generator/GeneratorOptions.js +16 -0
  57. package/dist/generator/GeneratorOptions.js.map +1 -0
  58. package/dist/generator/ImportResolver.d.ts +85 -0
  59. package/dist/generator/ImportResolver.d.ts.map +1 -0
  60. package/dist/generator/ImportResolver.js +381 -0
  61. package/dist/generator/ImportResolver.js.map +1 -0
  62. package/dist/generator/RestClientGenerator.d.ts +72 -0
  63. package/dist/generator/RestClientGenerator.d.ts.map +1 -0
  64. package/dist/generator/RestClientGenerator.js +488 -0
  65. package/dist/generator/RestClientGenerator.js.map +1 -0
  66. package/dist/generator/TypeMapper.d.ts +62 -0
  67. package/dist/generator/TypeMapper.d.ts.map +1 -0
  68. package/dist/generator/TypeMapper.js +224 -0
  69. package/dist/generator/TypeMapper.js.map +1 -0
  70. package/dist/generator/index.d.ts +9 -0
  71. package/dist/generator/index.d.ts.map +1 -0
  72. package/dist/generator/index.js +9 -0
  73. package/dist/generator/index.js.map +1 -0
  74. package/dist/generator/modes/BaseGenerator.d.ts +67 -0
  75. package/dist/generator/modes/BaseGenerator.d.ts.map +1 -0
  76. package/dist/generator/modes/BaseGenerator.js +128 -0
  77. package/dist/generator/modes/BaseGenerator.js.map +1 -0
  78. package/dist/generator/modes/DecoratorGenerator.d.ts +28 -0
  79. package/dist/generator/modes/DecoratorGenerator.d.ts.map +1 -0
  80. package/dist/generator/modes/DecoratorGenerator.js +147 -0
  81. package/dist/generator/modes/DecoratorGenerator.js.map +1 -0
  82. package/dist/generator/modes/EmfGenerator.d.ts +22 -0
  83. package/dist/generator/modes/EmfGenerator.d.ts.map +1 -0
  84. package/dist/generator/modes/EmfGenerator.js +202 -0
  85. package/dist/generator/modes/EmfGenerator.js.map +1 -0
  86. package/dist/generator/modes/PlainGenerator.d.ts +16 -0
  87. package/dist/generator/modes/PlainGenerator.d.ts.map +1 -0
  88. package/dist/generator/modes/PlainGenerator.js +95 -0
  89. package/dist/generator/modes/PlainGenerator.js.map +1 -0
  90. package/dist/generator/modes/index.d.ts +5 -0
  91. package/dist/generator/modes/index.d.ts.map +1 -0
  92. package/dist/generator/modes/index.js +5 -0
  93. package/dist/generator/modes/index.js.map +1 -0
  94. package/dist/genmodel/GenClass.d.ts +37 -0
  95. package/dist/genmodel/GenClass.d.ts.map +1 -0
  96. package/dist/genmodel/GenClass.js +14 -0
  97. package/dist/genmodel/GenClass.js.map +1 -0
  98. package/dist/genmodel/GenDataType.d.ts +19 -0
  99. package/dist/genmodel/GenDataType.d.ts.map +1 -0
  100. package/dist/genmodel/GenDataType.js +46 -0
  101. package/dist/genmodel/GenDataType.js.map +1 -0
  102. package/dist/genmodel/GenEnum.d.ts +30 -0
  103. package/dist/genmodel/GenEnum.d.ts.map +1 -0
  104. package/dist/genmodel/GenEnum.js +11 -0
  105. package/dist/genmodel/GenEnum.js.map +1 -0
  106. package/dist/genmodel/GenFeature.d.ts +30 -0
  107. package/dist/genmodel/GenFeature.d.ts.map +1 -0
  108. package/dist/genmodel/GenFeature.js +15 -0
  109. package/dist/genmodel/GenFeature.js.map +1 -0
  110. package/dist/genmodel/GenModel.d.ts +54 -0
  111. package/dist/genmodel/GenModel.d.ts.map +1 -0
  112. package/dist/genmodel/GenModel.js +24 -0
  113. package/dist/genmodel/GenModel.js.map +1 -0
  114. package/dist/genmodel/GenOperation.d.ts +19 -0
  115. package/dist/genmodel/GenOperation.d.ts.map +1 -0
  116. package/dist/genmodel/GenOperation.js +10 -0
  117. package/dist/genmodel/GenOperation.js.map +1 -0
  118. package/dist/genmodel/GenPackage.d.ts +42 -0
  119. package/dist/genmodel/GenPackage.d.ts.map +1 -0
  120. package/dist/genmodel/GenPackage.js +25 -0
  121. package/dist/genmodel/GenPackage.js.map +1 -0
  122. package/dist/genmodel/GenerationMode.d.ts +23 -0
  123. package/dist/genmodel/GenerationMode.d.ts.map +1 -0
  124. package/dist/genmodel/GenerationMode.js +25 -0
  125. package/dist/genmodel/GenerationMode.js.map +1 -0
  126. package/dist/genmodel/index.d.ts +9 -0
  127. package/dist/genmodel/index.d.ts.map +1 -0
  128. package/dist/genmodel/index.js +10 -0
  129. package/dist/genmodel/index.js.map +1 -0
  130. package/dist/index.d.ts +66 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +110 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/loader/EcoreLoader.d.ts +33 -0
  135. package/dist/loader/EcoreLoader.d.ts.map +1 -0
  136. package/dist/loader/EcoreLoader.js +91 -0
  137. package/dist/loader/EcoreLoader.js.map +1 -0
  138. package/dist/loader/index.d.ts +2 -0
  139. package/dist/loader/index.d.ts.map +1 -0
  140. package/dist/loader/index.js +2 -0
  141. package/dist/loader/index.js.map +1 -0
  142. package/dist/templates/partials/decorator/class-file.ejs +98 -0
  143. package/dist/templates/partials/decorator/enum-file.ejs +35 -0
  144. package/dist/templates/partials/decorator/interface-file.ejs +61 -0
  145. package/dist/templates/partials/decorator/model-annotations.ejs +91 -0
  146. package/dist/templates/partials/decorator/package-file.ejs +7 -0
  147. package/dist/templates/partials/emf/class-file.ejs +226 -0
  148. package/dist/templates/partials/emf/enum-file.ejs +36 -0
  149. package/dist/templates/partials/emf/factory-file.ejs +54 -0
  150. package/dist/templates/partials/emf/index-file.ejs +29 -0
  151. package/dist/templates/partials/emf/interface-file.ejs +72 -0
  152. package/dist/templates/partials/emf/package-file.ejs +149 -0
  153. package/dist/templates/partials/plain/class-file.ejs +75 -0
  154. package/dist/templates/partials/plain/enum-file.ejs +28 -0
  155. package/dist/templates/partials/plain/interface-file.ejs +61 -0
  156. package/dist/templates/partials/plain/package-file.ejs +6 -0
  157. package/dist/templates/templates/partials/decorator/class-file.ejs +98 -0
  158. package/dist/templates/templates/partials/decorator/enum-file.ejs +35 -0
  159. package/dist/templates/templates/partials/decorator/interface-file.ejs +61 -0
  160. package/dist/templates/templates/partials/decorator/model-annotations.ejs +91 -0
  161. package/dist/templates/templates/partials/decorator/package-file.ejs +7 -0
  162. package/dist/templates/templates/partials/emf/class-file.ejs +226 -0
  163. package/dist/templates/templates/partials/emf/enum-file.ejs +36 -0
  164. package/dist/templates/templates/partials/emf/factory-file.ejs +54 -0
  165. package/dist/templates/templates/partials/emf/index-file.ejs +29 -0
  166. package/dist/templates/templates/partials/emf/interface-file.ejs +72 -0
  167. package/dist/templates/templates/partials/emf/package-file.ejs +149 -0
  168. package/dist/templates/templates/partials/plain/class-file.ejs +75 -0
  169. package/dist/templates/templates/partials/plain/enum-file.ejs +28 -0
  170. package/dist/templates/templates/partials/plain/interface-file.ejs +61 -0
  171. package/dist/templates/templates/partials/plain/package-file.ejs +6 -0
  172. package/dist/util/EObjectHelper.d.ts +90 -0
  173. package/dist/util/EObjectHelper.d.ts.map +1 -0
  174. package/dist/util/EObjectHelper.js +381 -0
  175. package/dist/util/EObjectHelper.js.map +1 -0
  176. package/dist/util/StringUtils.d.ts +44 -0
  177. package/dist/util/StringUtils.d.ts.map +1 -0
  178. package/dist/util/StringUtils.js +115 -0
  179. package/dist/util/StringUtils.js.map +1 -0
  180. package/dist/util/index.d.ts +3 -0
  181. package/dist/util/index.d.ts.map +1 -0
  182. package/dist/util/index.js +3 -0
  183. package/dist/util/index.js.map +1 -0
  184. package/package.json +60 -0
@@ -0,0 +1,72 @@
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
+ }
@@ -0,0 +1,149 @@
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
+ }
@@ -0,0 +1,75 @@
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
+ }
@@ -0,0 +1,28 @@
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
+ <% } -%>
@@ -0,0 +1,61 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ <%- header %>
2
+
3
+ // Re-export all types from this package
4
+ <% for (const exp of exports) { -%>
5
+ export * from './<%- exp %>';
6
+ <% } -%>
@@ -0,0 +1,98 @@
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
+ }
@@ -0,0 +1,35 @@
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
+ }
@@ -0,0 +1,61 @@
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
+ }
@@ -0,0 +1,91 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ <%- header %>
2
+
3
+ // Re-export all types from this package
4
+ <% for (const exp of exports) { -%>
5
+ export * from './<%- exp %>';
6
+ <% } -%>
7
+ export * from './ModelAnnotations';