Skip to content

Commit 8e88532

Browse files
committed
Fix treatment of containments in ECore nodes, release version 1.6.8
1 parent 762f13f commit 8e88532

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

CHANGELOG.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +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
5+
## [1.6.5 - 1.6.8] – 2024-03-06
66

77
### Fixed
88
- Treatment of references in ECore nodes
99

10-
## [1.6.6] – 2024-03-06
11-
12-
### Fixed
13-
- Treatment of containments in ECore nodes
14-
15-
## [1.6.5] – 2024-03-06
16-
17-
### Fixed
18-
- Treatment of containments in ECore nodes
19-
2010
## [1.6.4] – 2024-03-06
2111

2212
### Added

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.7",
6+
"version": "1.6.8",
77
"license": "Apache-2.0",
88
"keywords": [
99
"antlr",

src/interop/ecore.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ export function registerPackages(resource: ECore.Resource): ECore.EPackage[] {
812812
export function isNodeType(type: EClassifier) {
813813
return type && (
814814
(type.get("interface") && type != THE_DESTINATION_INTERFACE) ||
815+
type == THE_NODE_ECLASS_V2 || type == THE_NODE_ECLASS_V1 ||
815816
type.get("eAllSuperTypes")?.find(t => t == THE_NODE_ECLASS_V2 || t == THE_NODE_ECLASS_V1) ||
816817
type == THE_REFERENCE_BY_NAME_ECLASS);
817818
}
@@ -900,7 +901,9 @@ export class ECoreNode extends NodeAdapter {
900901

901902
getProperties(): { [name: string | symbol]: PropertyDefinition } {
902903
const result: { [name: string | symbol]: PropertyDefinition } = {};
903-
for (const ft of this.eo.eClass.get("eAllStructuralFeatures")) {
904+
const eClass = this.eo.eClass;
905+
const features = eClass.get("eAllStructuralFeatures");
906+
for (const ft of features) {
904907
const name = ft.get("name");
905908
const isReference = ft.isTypeOf('EReference');
906909
if (isReference && !isNodeType(ft.get("eType") || ft.get("eGenericType")?.get("eClassifier"))) {

tests/ecore.test.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ 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 references", function () {
164+
it("containments and references - RPG", 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");
@@ -186,6 +186,28 @@ describe("Import/export", function () {
186186
"subroutine": {"child": false, "multiple": false, "name": "subroutine"}
187187
});
188188
});
189+
it("containments and references - SAS", function () {
190+
const resourceSet = ECore.ResourceSet.create();
191+
const resource = resourceSet.create({ uri: 'file:data/sas.metamodel.json' });
192+
const mmBuffer = fs.readFileSync("tests/data/sas.metamodel.json");
193+
const ePackages = loadEPackages(JSON.parse(mmBuffer.toString()), resource);
194+
expect(ePackages.length).to.equal(5);
195+
196+
const SourceFile = ePackages[0].eContents().find(x => x.get("name") == "SourceFile");
197+
const sf = SourceFile.create({});
198+
199+
const VariableDeclaration = ePackages[2].eContents().find(x => x.get("name") == "VariableDeclaration");
200+
const vd = VariableDeclaration.create({});
201+
sf.get("statementsAndDeclarations").add(vd);
202+
const eCoreNode = new ECoreNode(vd);
203+
const properties = eCoreNode.getProperties();
204+
expect(properties).to.eql({
205+
"name": {"child": false, "multiple": undefined, "name": "name"},
206+
"expression": {"child": true, "multiple": false, "name": "expression"},
207+
});
208+
expect(eCoreNode.getRole()).to.equal("statementsAndDeclarations");
209+
expect(eCoreNode.parent!.containment("statementsAndDeclarations")).to.eql({"child": true, "multiple": true, "name": "statementsAndDeclarations"});
210+
});
189211
it("importing using raw Ecore.js",
190212
function () {
191213
const resourceSet = ECore.ResourceSet.create();

0 commit comments

Comments
 (0)