From da8622095341074a5b4018453da37631d5df3f8c Mon Sep 17 00:00:00 2001 From: Jerome Simeon Date: Fri, 17 Dec 2021 10:43:30 -0500 Subject: [PATCH] fix(cto) Prints extends and identified in declarations in the right order Signed-off-by: Jerome Simeon --- packages/concerto-cto/lib/printer.js | 7 +++---- packages/concerto-cto/test/cto/identified.cto | 5 +++++ packages/concerto-cto/test/cto/identified.json | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 packages/concerto-cto/test/cto/identified.cto create mode 100644 packages/concerto-cto/test/cto/identified.json diff --git a/packages/concerto-cto/lib/printer.js b/packages/concerto-cto/lib/printer.js index 96973e600d..d2f1a1a2a5 100644 --- a/packages/concerto-cto/lib/printer.js +++ b/packages/concerto-cto/lib/printer.js @@ -199,10 +199,6 @@ function declFromMetaModel(mm) { result += `enum ${mm.name} `; break; } - if (mm.superType) { - result += `extends ${mm.superType.name} `; - } - // XXX Needs to be fixed to support `identified` if (mm.identified) { if (mm.identified.$class === 'concerto.metamodel.IdentifiedBy') { result += `identified by ${mm.identified.name} `; @@ -210,6 +206,9 @@ function declFromMetaModel(mm) { result += 'identified '; } } + if (mm.superType) { + result += `extends ${mm.superType.name} `; + } result += '{'; mm.properties.forEach((property) => { result += `\n ${propertyFromMetaModel(property)}`; diff --git a/packages/concerto-cto/test/cto/identified.cto b/packages/concerto-cto/test/cto/identified.cto new file mode 100644 index 0000000000..ddb0b3d007 --- /dev/null +++ b/packages/concerto-cto/test/cto/identified.cto @@ -0,0 +1,5 @@ +namespace test.field + +concept Foo identified extends Concept { + o String foo default="FOO" optional +} \ No newline at end of file diff --git a/packages/concerto-cto/test/cto/identified.json b/packages/concerto-cto/test/cto/identified.json new file mode 100644 index 0000000000..36a9206fce --- /dev/null +++ b/packages/concerto-cto/test/cto/identified.json @@ -0,0 +1 @@ +{"$class":"concerto.metamodel.Model","namespace":"test.field","imports":[],"declarations":[{"$class":"concerto.metamodel.ConceptDeclaration","name":"Foo","isAbstract":false,"properties":[{"$class":"concerto.metamodel.StringProperty","name":"foo","isArray":false,"isOptional":true,"location":{"$class":"concerto.metamodel.Range","start":{"offset":65,"line":4,"column":3,"$class":"concerto.metamodel.Position"},"end":{"offset":101,"line":5,"column":1,"$class":"concerto.metamodel.Position"}},"defaultValue":"FOO"}],"location":{"$class":"concerto.metamodel.Range","start":{"offset":22,"line":3,"column":1,"$class":"concerto.metamodel.Position"},"end":{"offset":102,"line":5,"column":2,"$class":"concerto.metamodel.Position"}},"superType":{"$class":"concerto.metamodel.TypeIdentifier","name":"Concept"},"identified":{"$class":"concerto.metamodel.Identified"}}]} \ No newline at end of file