diff --git a/packages/concerto-cli/test/models/contract.json b/packages/concerto-cli/test/models/contract.json index ba618f738f..dcb74414aa 100644 --- a/packages/concerto-cli/test/models/contract.json +++ b/packages/concerto-cli/test/models/contract.json @@ -2,7 +2,8 @@ "$class": "concerto.metamodel.ModelFile", "namespace": "org.accordproject.cicero.contract", "imports": [], - "declarations": [ + "enumDeclarations": [], + "classDeclarations": [ { "$class": "concerto.metamodel.AssetDeclaration", "name": "AccordContractState", diff --git a/packages/concerto-cli/test/models/contractResolved.json b/packages/concerto-cli/test/models/contractResolved.json index 069e40bc52..9d640bd4e7 100644 --- a/packages/concerto-cli/test/models/contractResolved.json +++ b/packages/concerto-cli/test/models/contractResolved.json @@ -2,7 +2,8 @@ "$class": "concerto.metamodel.ModelFile", "namespace": "org.accordproject.cicero.contract", "imports": [], - "declarations": [ + "enumDeclarations": [], + "classDeclarations": [ { "$class": "concerto.metamodel.AssetDeclaration", "isAbstract": false, diff --git a/packages/concerto-core/lib/introspect/metamodel.js b/packages/concerto-core/lib/introspect/metamodel.js index 0e389427fa..d187a9901f 100644 --- a/packages/concerto-core/lib/introspect/metamodel.js +++ b/packages/concerto-core/lib/introspect/metamodel.js @@ -77,6 +77,7 @@ concept IdentifiedBy extends Identified { o String name } +@FormEditor("defaultSubclass","concerto.metamodel.ClassDeclaration") abstract concept Declaration { // TODO use regex /^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*/u @FormEditor("title", "Name") @@ -217,8 +218,10 @@ concept ModelFile { o String namespace default="my.namespace" @FormEditor("hide", true) o Import[] imports optional + @FormEditor("title", "Enums") + o EnumDeclaration[] enumDeclarations optional @FormEditor("title", "Classes") - o Declaration[] declarations optional + o ClassDeclaration[] classDeclarations optional } `; @@ -274,7 +277,10 @@ function createNameTable(modelManager, metaModel) { }); // Then add the names local to this metaModel (overriding as we go along) - metaModel.declarations.forEach((decl) => { + metaModel.enumDeclarations.forEach((decl) => { + table[decl.name] = metaModel.namespace; + }); + metaModel.classDeclarations.forEach((decl) => { table[decl.name] = metaModel.namespace; }); @@ -304,7 +310,10 @@ function resolveName(name, table) { function resolveTypeNames(metaModel, table) { switch (metaModel.$class) { case 'concerto.metamodel.ModelFile': { - metaModel.declarations.forEach((decl) => { + metaModel.enumDeclarations.forEach((decl) => { + resolveTypeNames(decl, table); + }); + metaModel.classDeclarations.forEach((decl) => { resolveTypeNames(decl, table); }); } @@ -606,12 +615,17 @@ function modelToMetaModel(ast, validate = true) { } if (ast.body.length > 0) { - metamodel.declarations = []; + metamodel.enumDeclarations = []; + metamodel.classDeclarations = []; } for(let n=0; n < ast.body.length; n++ ) { const thing = ast.body[n]; const decl = declToMetaModel(thing); - metamodel.declarations.push(decl); + if (decl.$class === 'concerto.metamodel.EnumDeclaration') { + metamodel.enumDeclarations.push(decl); + } else { + metamodel.classDeclarations.push(decl); + } } // Last, validate the JSON metaModel @@ -780,8 +794,13 @@ function ctoFromMetaModel(metaModel, validate = true) { } }); } - if (mm.declarations && mm.declarations.length > 0) { - mm.declarations.forEach((decl) => { + if (mm.enumDeclarations && mm.enumDeclarations.length > 0) { + mm.enumDeclarations.forEach((decl) => { + result += `\n\n${declFromMetaModel(decl)}`; + }); + } + if (mm.classDeclarations && mm.classDeclarations.length > 0) { + mm.classDeclarations.forEach((decl) => { result += `\n\n${declFromMetaModel(decl)}`; }); } diff --git a/packages/concerto-core/test/data/model/person.json b/packages/concerto-core/test/data/model/person.json index 53bfe72d7a..3977c7ded8 100644 --- a/packages/concerto-core/test/data/model/person.json +++ b/packages/concerto-core/test/data/model/person.json @@ -14,7 +14,7 @@ "uri": "https://models.accordproject.org/time@0.2.0.cto" } ], - "declarations": [ + "enumDeclarations": [ { "$class": "concerto.metamodel.EnumDeclaration", "fields": [ @@ -32,7 +32,9 @@ } ], "name": "Gender" - }, + } + ], + "classDeclarations": [ { "$class": "concerto.metamodel.ParticipantDeclaration", "isAbstract": true, diff --git a/packages/concerto-core/test/data/model/personResolved.json b/packages/concerto-core/test/data/model/personResolved.json index 64bb5f3ab1..6bfb937823 100644 --- a/packages/concerto-core/test/data/model/personResolved.json +++ b/packages/concerto-core/test/data/model/personResolved.json @@ -14,7 +14,7 @@ "uri": "https://models.accordproject.org/time@0.2.0.cto" } ], - "declarations": [ + "enumDeclarations": [ { "$class": "concerto.metamodel.EnumDeclaration", "fields": [ @@ -32,7 +32,9 @@ } ], "name": "Gender" - }, + } + ], + "classDeclarations": [ { "$class": "concerto.metamodel.ParticipantDeclaration", "isAbstract": true,