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(resolve): resolve namespace for decorators on primitives #25

Merged
merged 1 commit into from
Sep 24, 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
24 changes: 24 additions & 0 deletions categories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$class": "concerto.metamodel@1.0.0.Model",
"decorators": [],
"namespace": "org.categories@1.0.0",
"imports": [],
"declarations": [
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Category",
"isAbstract": true,
"properties": []
},
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Engineering",
"isAbstract": false,
"properties": [],
"superType": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Category"
}
}
]
}
79 changes: 79 additions & 0 deletions decorators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$class": "concerto.metamodel@1.0.0.Model",
"decorators": [],
"namespace": "org.car@1.0.0",
"imports": [
{
"$class": "concerto.metamodel@1.0.0.ImportTypes",
"namespace": "org.categories@1.0.0",
"types": [
"Engineering"
]
}
],
"declarations": [
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Car",
"isAbstract": false,
"properties": [
{
"$class": "concerto.metamodel@1.0.0.ObjectProperty",
"name": "part",
"type": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Part"
},
"isArray": false,
"isOptional": false
}
]
},
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Part",
"isAbstract": true,
"properties": [
{
"$class": "concerto.metamodel@1.0.0.StringProperty",
"name": "name",
"isArray": false,
"isOptional": false,
"decorators": [
{
"$class": "concerto.metamodel@1.0.0.Decorator",
"name": "category",
"arguments": [
{
"$class": "concerto.metamodel@1.0.0.DecoratorTypeReference",
"type": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Engineering"
},
"isArray": false
}
]
}
]
}
]
},
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Wheel",
"isAbstract": false,
"properties": [
{
"$class": "concerto.metamodel@1.0.0.DoubleProperty",
"name": "diameter",
"isArray": false,
"isOptional": false
}
],
"superType": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Part"
}
}
]
}
39 changes: 9 additions & 30 deletions lib/metamodelutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ function resolveName(name, table) {
* @return {object} the metamodel with fully qualified names
*/
function resolveTypeNames(metaModel, table) {
// any element can have a decorator (including primitive fields) , so lets resolve those first
(metaModel.decorators || []).forEach((decorator) => {
resolveTypeNames(decorator, table);
});

switch (metaModel.$class) {
case `${MetaModelNamespace}.Model`: {
(metaModel.declarations || []).forEach((decl) => {
Expand All @@ -145,49 +150,26 @@ function resolveTypeNames(metaModel, table) {
(metaModel.properties || []).forEach((property) => {
resolveTypeNames(property, table);
});
(metaModel.decorators || []).forEach((decorator) => {
resolveTypeNames(decorator, table);
});
}
break;
case `${MetaModelNamespace}.EnumDeclaration`: {
(metaModel.decorators || []).forEach((decorator) => {
resolveTypeNames(decorator, table);
});
}
break;
case `${MetaModelNamespace}.MapDeclaration`: {
resolveTypeNames(metaModel.key, table);
resolveTypeNames(metaModel.value, table);
}
break;
case `${MetaModelNamespace}.EnumProperty`:
case `${MetaModelNamespace}.ObjectProperty`:
case `${MetaModelNamespace}.RelationshipProperty`: {
const name = metaModel.type.name;
metaModel.type.namespace = resolveName(name, table);
(metaModel.decorators || []).forEach((decorator) => {
resolveTypeNames(decorator, table);
});
}
break;
case `${MetaModelNamespace}.Decorator`: {
(metaModel.arguments || []).forEach((argument) => {
resolveTypeNames(argument, table);
});
}
break;
case `${MetaModelNamespace}.DecoratorTypeReference`: {
const name = metaModel.type.name;
metaModel.type.namespace = resolveName(name, table);
}
break;
case `${MetaModelNamespace}.EnumProperty`:
case `${MetaModelNamespace}.ObjectProperty`:
case `${MetaModelNamespace}.RelationshipProperty`:
case `${MetaModelNamespace}.DecoratorTypeReference`:
case `${MetaModelNamespace}.ObjectMapKeyType`:
case `${MetaModelNamespace}.ObjectMapValueType`: {
metaModel.type.namespace = resolveName(metaModel.type.name, table);
(metaModel.decorators || []).forEach((decorator) => {
resolveTypeNames(decorator, table);
});
}
break;
case `${MetaModelNamespace}.StringScalar`:
Expand All @@ -197,9 +179,6 @@ function resolveTypeNames(metaModel, table) {
case `${MetaModelNamespace}.LongScalar`:
case `${MetaModelNamespace}.IntegerScalar`: {
metaModel.namespace = resolveName(metaModel.name, table);
(metaModel.decorators || []).forEach((decorator) => {
resolveTypeNames(decorator, table);
});
}
break;
}
Expand Down
4 changes: 4 additions & 0 deletions test/cto/categories.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace org.categories@1.0.0

abstract concept Category {}
concept Engineering extends Category {}
16 changes: 16 additions & 0 deletions test/cto/decorators.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace org.car@1.0.0

import org.categories@1.0.0.{Engineering}

concept Car {
o Part part
}

abstract concept Part {
@category(Engineering)
o String name
}

concept Wheel extends Part {
o Double diameter
}
108 changes: 108 additions & 0 deletions test/cto/decorators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"$class": "concerto.metamodel@1.0.0.Models",
"models": [
{
"$class": "concerto.metamodel@1.0.0.Model",
"decorators": [],
"namespace": "org.categories@1.0.0",
"imports": [],
"declarations": [
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Category",
"isAbstract": true,
"properties": []
},
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Engineering",
"isAbstract": false,
"properties": [],
"superType": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Category"
}
}
]
},
{
"$class": "concerto.metamodel@1.0.0.Model",
"decorators": [],
"namespace": "org.car@1.0.0",
"imports": [
{
"$class": "concerto.metamodel@1.0.0.ImportTypes",
"namespace": "org.categories@1.0.0",
"types": [
"Engineering"
]
}
],
"declarations": [
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Car",
"isAbstract": false,
"properties": [
{
"$class": "concerto.metamodel@1.0.0.ObjectProperty",
"name": "part",
"type": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Part"
},
"isArray": false,
"isOptional": false
}
]
},
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Part",
"isAbstract": true,
"properties": [
{
"$class": "concerto.metamodel@1.0.0.StringProperty",
"name": "name",
"isArray": false,
"isOptional": false,
"decorators": [
{
"$class": "concerto.metamodel@1.0.0.Decorator",
"name": "category",
"arguments": [
{
"$class": "concerto.metamodel@1.0.0.DecoratorTypeReference",
"type": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Engineering"
},
"isArray": false
}
]
}
]
}
]
},
{
"$class": "concerto.metamodel@1.0.0.ConceptDeclaration",
"name": "Wheel",
"isAbstract": false,
"properties": [
{
"$class": "concerto.metamodel@1.0.0.DoubleProperty",
"name": "diameter",
"isArray": false,
"isOptional": false
}
],
"superType": {
"$class": "concerto.metamodel@1.0.0.TypeIdentifier",
"name": "Part"
}
}
]
}
]
}
Loading
Loading