Skip to content

Commit f341124

Browse files
committed
fix(metamodel) Add missing support for type reference arguments in decorators
Signed-off-by: jeromesimeon <[email protected]>
1 parent 89052cb commit f341124

File tree

4 files changed

+55
-942
lines changed

4 files changed

+55
-942
lines changed

packages/concerto-core/lib/introspect/metamodel.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ namespace concerto.metamodel
3838
/**
3939
* The metadmodel for Concerto files
4040
*/
41+
concept TypeIdentifier {
42+
@FormEditor("selectOptions", "types")
43+
o String name default="Concept"
44+
@FormEditor( "hide", true)
45+
o String fullyQualifiedName optional
46+
}
47+
4148
abstract concept DecoratorLiteral {
4249
}
4350
@@ -53,11 +60,9 @@ concept DecoratorBoolean extends DecoratorLiteral {
5360
o Boolean value
5461
}
5562
56-
concept TypeIdentifier {
57-
@FormEditor("selectOptions", "types")
58-
o String name default="Concept"
59-
@FormEditor( "hide", true)
60-
o String fullyQualifiedName optional
63+
concept DecoratorTypeReference extends DecoratorLiteral {
64+
o TypeIdentifier type
65+
o Boolean isArray default=false
6166
}
6267
6368
concept Decorator {
@@ -251,7 +256,7 @@ function createNameTable(modelManager, metaModel) {
251256
const modelFile = modelManager.getModelFile(namespace);
252257
if (imp.$class === 'concerto.metamodel.ImportType') {
253258
if (!modelFile.getLocalType(imp.name)) {
254-
throw new Error(`Declaration ${imp.identifier.name} in namespace ${namespace} not found`);
259+
throw new Error(`Declaration ${imp.name} in namespace ${namespace} not found`);
255260
}
256261
table[imp.name] = namespace;
257262
} else {
@@ -316,12 +321,44 @@ function resolveTypeNames(metaModel, table) {
316321
metaModel.fields.forEach((field) => {
317322
resolveTypeNames(field, table);
318323
});
324+
if (metaModel.decorators) {
325+
metaModel.decorators.forEach((decorator) => {
326+
resolveTypeNames(decorator, table);
327+
});
328+
}
329+
}
330+
break;
331+
case 'concerto.metamodel.EnumDeclaration': {
332+
if (metaModel.decorators) {
333+
metaModel.decorators.forEach((decorator) => {
334+
resolveTypeNames(decorator, table);
335+
});
336+
}
319337
}
320338
break;
339+
case 'concerto.metamodel.EnumFieldDeclaration':
321340
case 'concerto.metamodel.ObjectFieldDeclaration':
322341
case 'concerto.metamodel.RelationshipDeclaration': {
323342
const name = metaModel.type.name;
324343
metaModel.type.fullyQualifiedName = resolveName(name, table);
344+
if (metaModel.decorators) {
345+
metaModel.decorators.forEach((decorator) => {
346+
resolveTypeNames(decorator, table);
347+
});
348+
}
349+
}
350+
break;
351+
case 'concerto.metamodel.Decorator': {
352+
if (metaModel.arguments) {
353+
metaModel.arguments.forEach((argument) => {
354+
resolveTypeNames(argument, table);
355+
});
356+
}
357+
}
358+
break;
359+
case 'concerto.metamodel.DecoratorTypeReference': {
360+
const name = metaModel.type.name;
361+
metaModel.type.fullyQualifiedName = resolveName(name, table);
325362
}
326363
break;
327364
}
@@ -365,6 +402,12 @@ function decoratorArgToMetaModel(ast) {
365402
decoratorArg.value = ast.value;
366403
break;
367404
default:
405+
decoratorArg.$class = 'concerto.metamodel.DecoratorTypeReference';
406+
decoratorArg.type = {
407+
$class: 'concerto.metamodel.TypeIdentifier',
408+
name: ast.value.name,
409+
};
410+
decoratorArg.isArray = ast.value.array;
368411
break;
369412
}
370413

@@ -746,6 +789,9 @@ function modelFileToMetaModel(modelFile, validate) {
746789
function decoratorArgFromMetaModel(mm) {
747790
let result = '';
748791
switch (mm.$class) {
792+
case 'concerto.metamodel.DecoratorTypeReference':
793+
result += `${mm.type.name}${mm.isArray ? '[]' : ''}`;
794+
break;
749795
case 'concerto.metamodel.DecoratorString':
750796
result += `"${mm.value}"`;
751797
break;

packages/concerto-core/test/data/model/person.cto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ concept Address identified {
5656
o Boolean isPrivate default=false
5757
}
5858

59-
@Address("x",1,"y","foo","z",true)
59+
@Address("x",1,"y","foo","z",true,Gender,TemporalUnit[])
6060
@Address2()
6161
@Address3
6262
concept USAddress extends Address {

0 commit comments

Comments
 (0)