Skip to content

Commit 762f13f

Browse files
committed
Fix treatment of containments in ECore nodes, release version 1.6.6
1 parent ef58f14 commit 762f13f

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project from version 1.2.0 upwards are documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## [1.6.7] – 2024-03-06
6+
7+
### Fixed
8+
- Treatment of references in ECore nodes
9+
510
## [1.6.6] – 2024-03-06
611

712
### Fixed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "AST building blocks for TypeScript/JavaScript, part of the *lasu family, with optional integrations with ANTLR4 and Ecore.",
44
"author": "Strumenta s.r.l.",
55
"publisher": "strumenta",
6-
"version": "1.6.6",
6+
"version": "1.6.7",
77
"license": "Apache-2.0",
88
"keywords": [
99
"antlr",

src/interop/ecore.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,10 @@ export function registerPackages(resource: ECore.Resource): ECore.EPackage[] {
810810
}
811811

812812
export function isNodeType(type: EClassifier) {
813-
return (type.get("interface") && type != THE_DESTINATION_INTERFACE) ||
814-
type.get("eAllSuperTypes")?.find(t => t == THE_NODE_ECLASS_V2 || t == THE_NODE_ECLASS_V1);
813+
return type && (
814+
(type.get("interface") && type != THE_DESTINATION_INTERFACE) ||
815+
type.get("eAllSuperTypes")?.find(t => t == THE_NODE_ECLASS_V2 || t == THE_NODE_ECLASS_V1) ||
816+
type == THE_REFERENCE_BY_NAME_ECLASS);
815817
}
816818

817819
export interface EcoreMetamodelSupport {
@@ -901,12 +903,14 @@ export class ECoreNode extends NodeAdapter {
901903
for (const ft of this.eo.eClass.get("eAllStructuralFeatures")) {
902904
const name = ft.get("name");
903905
const isReference = ft.isTypeOf('EReference');
904-
if (isReference && !isNodeType(ft.get("eType"))) {
906+
if (isReference && !isNodeType(ft.get("eType") || ft.get("eGenericType")?.get("eClassifier"))) {
905907
// skip
906908
} else {
907909
result[name] = {
908910
name,
909-
child: isReference && ft.get('containment'),
911+
child: isReference &&
912+
ft.get('containment') &&
913+
ft.get("eGenericType")?.get("eClassifier") != THE_REFERENCE_BY_NAME_ECLASS,
910914
multiple: isReference ? ft.get('many') : undefined,
911915
};
912916
}

tests/ecore.test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,30 @@ describe("Import/export", function () {
161161
expect(node instanceof Node).to.be.true;
162162
expect(node.statementsAndDeclarations.length).to.equal(26);
163163
});
164-
it("containments and inheritance", function () {
164+
it("containments and references", function () {
165165
const resourceSet = ECore.ResourceSet.create();
166166
const resource = resourceSet.create({ uri: 'file:data/rpg.metamodel.json' });
167167
const mmBuffer = fs.readFileSync("tests/data/rpg.metamodel.json");
168168
const ePackages = loadEPackages(JSON.parse(mmBuffer.toString()), resource);
169169
expect(ePackages.length).to.equal(2);
170+
170171
const PlistParameter = ePackages[1].eContents().find(x => x.get("name") == "PlistParameter");
171-
const eo = PlistParameter.create({});
172-
const properties = new ECoreNode(eo).getProperties();
172+
let eo = PlistParameter.create({});
173+
let properties = new ECoreNode(eo).getProperties();
173174
expect(properties).to.eql({
174175
"name": {"child": true, "multiple": false, "name": "name"},
175176
"sourceField": {"child": true, "multiple": false, "name": "sourceField"},
176177
"targetField": {"child": true, "multiple": false, "name": "targetField"},
177178
"type": {"child": true, "multiple": false, "name": "type"}
178179
});
180+
181+
const InvokeSubroutineStatement = ePackages[1].eContents().find(x => x.get("name") == "InvokeSubroutineStatement");
182+
eo = InvokeSubroutineStatement.create({});
183+
properties = new ECoreNode(eo).getProperties();
184+
expect(properties).to.eql({
185+
"conditionalIndicator": {"child": true, "multiple": false, "name": "conditionalIndicator"},
186+
"subroutine": {"child": false, "multiple": false, "name": "subroutine"}
187+
});
179188
});
180189
it("importing using raw Ecore.js",
181190
function () {

0 commit comments

Comments
 (0)