Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aliasing): resolve aliased import type name to imported type name #32

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/metamodelutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ function findDeclaration(thisModel, name) {
function createNameTable(priorModels, metaModel) {
const concertoNs = '[email protected]';
const table = {
'Concept': concertoNs,
'Asset': concertoNs,
'Participant': concertoNs,
'Transaction ': concertoNs,
'Event': concertoNs
'Concept': {namespace: concertoNs, name: 'Concept'},
'Asset': {namespace: concertoNs, name: 'Asset'},
'Participant': {namespace: concertoNs, name: 'Participant'},
'Transaction': {namespace: concertoNs, name: 'Transaction'},
'Event': {namespace: concertoNs, name: 'Event'}
};

// First list the imported names in order (overriding as we go along)
Expand All @@ -74,7 +74,7 @@ function createNameTable(priorModels, metaModel) {
if (!findDeclaration(modelFile, imp.name)) {
throw new Error(`Declaration ${imp.name} in namespace ${namespace} not found`);
}
table[imp.name] = namespace;
table[imp.name] = {namespace, name: imp.name};
} else if (imp.$class === `${MetaModelNamespace}.ImportTypes`) {
// Create a map of aliased types if they exist, otherwise initialize an empty map.
const aliasedMap = imp.aliasedTypes
Expand All @@ -89,18 +89,18 @@ function createNameTable(priorModels, metaModel) {
if (!findDeclaration(modelFile, type)) {
throw new Error(`Declaration ${type} in namespace ${namespace} not found`);
}
table[localName] = namespace;
table[localName] = {namespace, name: type};
});
} else {
(modelFile.declarations || []).forEach((decl) => {
table[decl.name] = namespace;
table[decl.name] = {namespace, name: decl.name};
});
}
});

// Then add the names local to this metaModel (overriding as we go along)
(metaModel.declarations || []).forEach((decl) => {
table[decl.name] = metaModel.namespace;
table[decl.name] = {namespace: metaModel.namespace, name: decl.name};
});

return table;
Expand All @@ -116,7 +116,7 @@ function resolveName(name, table) {
if (!table[name]) {
throw new Error(`Name ${name} not found`);
}
return table[name];
return table[name].namespace;
}

/**
Expand Down Expand Up @@ -146,6 +146,7 @@ function resolveTypeNames(metaModel, table) {
if (metaModel.superType) {
const name = metaModel.superType.name;
metaModel.superType.namespace = resolveName(name, table);
metaModel.superType.name = table[name].name;
}
(metaModel.properties || []).forEach((property) => {
resolveTypeNames(property, table);
Expand All @@ -170,6 +171,7 @@ function resolveTypeNames(metaModel, table) {
case `${MetaModelNamespace}.ObjectMapKeyType`:
case `${MetaModelNamespace}.ObjectMapValueType`: {
metaModel.type.namespace = resolveName(metaModel.type.name, table);
metaModel.type.name = table[metaModel.type.name].name;
}
break;
case `${MetaModelNamespace}.StringScalar`:
Expand All @@ -179,6 +181,7 @@ function resolveTypeNames(metaModel, table) {
case `${MetaModelNamespace}.LongScalar`:
case `${MetaModelNamespace}.IntegerScalar`: {
metaModel.namespace = resolveName(metaModel.name, table);
metaModel.name = table[metaModel.name].name;
}
break;
}
Expand Down
49 changes: 2 additions & 47 deletions test/cto/aliasedImport.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,9 @@
"$class": "[email protected]",
"name": "name",
"isArray": false,
"isOptional": false,
"location": {
mttrbrts marked this conversation as resolved.
Show resolved Hide resolved
"$class": "[email protected]",
"start": {
"offset": 35,
"line": 4,
"column": 2,
"$class": "[email protected]"
},
"end": {
"offset": 49,
"line": 5,
"column": 1,
"$class": "[email protected]"
}
}
"isOptional": false
}
],
"location": {
"$class": "[email protected]",
"start": {
"offset": 22,
"line": 3,
"column": 1,
"$class": "[email protected]"
},
"end": {
"offset": 50,
"line": 5,
"column": 2,
"$class": "[email protected]"
}
}
]
}
]
},
Expand Down Expand Up @@ -78,21 +48,6 @@
"name": "file",
"isAbstract": false,
"properties": [],
"location": {
"$class": "[email protected]",
"start": {
"offset": 50,
"line": 5,
"column": 1,
"$class": "[email protected]"
},
"end": {
"offset": 75,
"line": 6,
"column": 2,
"$class": "[email protected]"
}
},
"superType": {
"$class": "[email protected]",
"name": "d"
Expand Down
51 changes: 3 additions & 48 deletions test/cto/aliasedImportResolved.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,9 @@
"$class": "[email protected]",
"name": "name",
"isArray": false,
"isOptional": false,
"location": {
"$class": "[email protected]",
"start": {
"offset": 35,
"line": 4,
"column": 2,
"$class": "[email protected]"
},
"end": {
"offset": 49,
"line": 5,
"column": 1,
"$class": "[email protected]"
}
}
"isOptional": false
}
],
"location": {
"$class": "[email protected]",
"start": {
"offset": 22,
"line": 3,
"column": 1,
"$class": "[email protected]"
},
"end": {
"offset": 50,
"line": 5,
"column": 2,
"$class": "[email protected]"
}
}
]
}
]
},
Expand Down Expand Up @@ -78,24 +48,9 @@
"name": "file",
"isAbstract": false,
"properties": [],
"location": {
"$class": "[email protected]",
"start": {
"offset": 50,
"line": 5,
"column": 1,
"$class": "[email protected]"
},
"end": {
"offset": 75,
"line": 6,
"column": 2,
"$class": "[email protected]"
}
},
"superType": {
"$class": "[email protected]",
"name": "d",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the impact of the change in the metamodel

"name": "doc",
"namespace": "org.saluja"
}
}
Expand Down
Loading