From cd6ed9931f19b50055def352d18d0ca940ef4b76 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Thu, 16 Nov 2023 16:37:33 +0000 Subject: [PATCH 1/5] feat(*): extend plantuml visitor Signed-off-by: Jonathan Casey --- lib/codegen/fromcto/plantuml/plantumlvisitor.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/codegen/fromcto/plantuml/plantumlvisitor.js b/lib/codegen/fromcto/plantuml/plantumlvisitor.js index d3b9614b..70bfd594 100644 --- a/lib/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/lib/codegen/fromcto/plantuml/plantumlvisitor.js @@ -57,6 +57,20 @@ class PlantUMLVisitor extends DiagramVisitor { this.writeDeclaration(classDeclaration, parameters, '(A,green)' ); } + /** + * Visitor design pattern + * @param {MapDeclaration} mapDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @protected + */ + visitMapDeclaration(mapDeclaration, parameters) { + parameters.fileWriter.writeLine(0, 'class ' + this.escapeString(mapDeclaration.getFullyQualifiedName()) + ' << (M,pink) >> ' + '{' ); + parameters.fileWriter.writeLine(1, `+ ${mapDeclaration.getKey().getType()}` ); + parameters.fileWriter.writeLine(1, `+ ${mapDeclaration.getValue().getType()}` ); + parameters.fileWriter.writeLine(0, '}' ); + } + + /** * Visitor design pattern * @param {ClassDeclaration} classDeclaration - the object being visited From 8383e6dcd5f2b2e0ff20dea93faa7af611328b6e Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Thu, 16 Nov 2023 16:38:13 +0000 Subject: [PATCH 2/5] test(*): add test cov Signed-off-by: Jonathan Casey --- .../fromcto/plantuml/plantumlvisitor.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/codegen/fromcto/plantuml/plantumlvisitor.js b/test/codegen/fromcto/plantuml/plantumlvisitor.js index c97b0de5..76fb9140 100644 --- a/test/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/test/codegen/fromcto/plantuml/plantumlvisitor.js @@ -25,6 +25,7 @@ const ModelManager = require('@accordproject/concerto-core').ModelManager; const AssetDeclaration = require('@accordproject/concerto-core').AssetDeclaration; const ParticipantDeclaration = require('@accordproject/concerto-core').ParticipantDeclaration; const ClassDeclaration = require('@accordproject/concerto-core').ClassDeclaration; +const {MapDeclaration, MapKeyType, MapValueType } = require('@accordproject/concerto-core'); const EnumDeclaration = require('@accordproject/concerto-core').EnumDeclaration; const EnumValueDeclaration = require('@accordproject/concerto-core').EnumValueDeclaration; const Field = require('@accordproject/concerto-core').Field; @@ -440,6 +441,33 @@ describe('PlantUMLVisitor', function () { }); }); + describe('visitMapDeclaration', () => { + it('should write the map declaration for a map', () => { + let param = { + fileWriter: mockFileWriter + }; + + let mockMapDeclaration = sinon.createStubInstance(MapDeclaration); + let mockMapKey = sinon.createStubInstance(MapKeyType); + let mockMapValue = sinon.createStubInstance(MapValueType); + + mockMapDeclaration.getKey.returns(mockMapKey); + mockMapDeclaration.getValue.returns(mockMapValue); + mockMapKey.getType.returns('String'); + mockMapValue.getType.returns('String'); + + mockMapDeclaration.getFullyQualifiedName.returns('org.acme.NextOfKin'); + + plantUMLvisitor.visitMapDeclaration(mockMapDeclaration, param); + + param.fileWriter.writeLine.callCount.should.deep.equal(4); + param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'class org.acme.NextOfKin << (M,pink) >> {']); + param.fileWriter.writeLine.getCall(1).args.should.deep.equal([1, '+ String']); + param.fileWriter.writeLine.getCall(2).args.should.deep.equal([1, '+ String']); + param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, '}']); + }); + }); + describe('visitClassDeclaration', () => { it('should write the class declaration for a class', () => { let acceptSpy = sinon.spy(); From fa55c173029ff8f6ef80ef5c446f3e325da94cad Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Thu, 16 Nov 2023 16:38:20 +0000 Subject: [PATCH 3/5] test(*): update snapshot Signed-off-by: Jonathan Casey --- test/codegen/__snapshots__/codegen.js.snap | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index dd92e2f9..2fbbb889 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -3799,6 +3799,10 @@ class org.acme.hr.base.TShirtSizeType << (E,grey) >> { + LARGE } org.acme.hr.base.TShirtSizeType --|> concerto_1_0_0.Concept +class org.acme.hr.base.EmployeeTShirtSizes << (M,pink) >> { + + SSN + + TShirtSizeType +} class org.acme.hr.base.Address { + String street + String city @@ -3807,6 +3811,30 @@ class org.acme.hr.base.Address { + String country } org.acme.hr.base.Address --|> concerto_1_0_0.Concept +class org.acme.hr.CompanyProperties << (M,pink) >> { + + String + + String +} +class org.acme.hr.EmployeeLoginTimes << (M,pink) >> { + + String + + Time +} +class org.acme.hr.EmployeeSocialSecurityNumbers << (M,pink) >> { + + String + + SSN +} +class org.acme.hr.NextOfKin << (M,pink) >> { + + KinName + + KinTelephone +} +class org.acme.hr.EmployeeProfiles << (M,pink) >> { + + String + + Concept +} +class org.acme.hr.EmployeeDirectory << (M,pink) >> { + + SSN + + Employee +} class org.acme.hr.Company { + String name + Address headquarters @@ -5800,6 +5828,10 @@ class org.acme.hr.base_1_0_0.TShirtSizeType << (E,grey) >> { + MEDIUM + LARGE } +class org.acme.hr.base_1_0_0.EmployeeTShirtSizes << (M,pink) >> { + + SSN + + TShirtSizeType +} class org.acme.hr.base_1_0_0.Address { + String street + String city @@ -5808,6 +5840,30 @@ class org.acme.hr.base_1_0_0.Address { + String country } org.acme.hr.base_1_0_0.Address "1" *-- "1" org.acme.hr.base_1_0_0.State : state +class org.acme.hr_1_0_0.CompanyProperties << (M,pink) >> { + + String + + String +} +class org.acme.hr_1_0_0.EmployeeLoginTimes << (M,pink) >> { + + String + + Time +} +class org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers << (M,pink) >> { + + String + + SSN +} +class org.acme.hr_1_0_0.NextOfKin << (M,pink) >> { + + KinName + + KinTelephone +} +class org.acme.hr_1_0_0.EmployeeProfiles << (M,pink) >> { + + String + + Concept +} +class org.acme.hr_1_0_0.EmployeeDirectory << (M,pink) >> { + + SSN + + Employee +} class org.acme.hr_1_0_0.Company { + String name + Address headquarters @@ -9717,6 +9773,10 @@ class org.acme.hr.base_1_0_0.TShirtSizeType << (E,grey) >> { + LARGE } org.acme.hr.base_1_0_0.TShirtSizeType --|> concerto_1_0_0.Concept +class org.acme.hr.base_1_0_0.EmployeeTShirtSizes << (M,pink) >> { + + SSN + + TShirtSizeType +} class org.acme.hr.base_1_0_0.Address { + String street + String city @@ -9726,6 +9786,30 @@ class org.acme.hr.base_1_0_0.Address { } org.acme.hr.base_1_0_0.Address "1" *-- "1" org.acme.hr.base_1_0_0.State : state org.acme.hr.base_1_0_0.Address --|> concerto_1_0_0.Concept +class org.acme.hr_1_0_0.CompanyProperties << (M,pink) >> { + + String + + String +} +class org.acme.hr_1_0_0.EmployeeLoginTimes << (M,pink) >> { + + String + + Time +} +class org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers << (M,pink) >> { + + String + + SSN +} +class org.acme.hr_1_0_0.NextOfKin << (M,pink) >> { + + KinName + + KinTelephone +} +class org.acme.hr_1_0_0.EmployeeProfiles << (M,pink) >> { + + String + + Concept +} +class org.acme.hr_1_0_0.EmployeeDirectory << (M,pink) >> { + + SSN + + Employee +} class org.acme.hr_1_0_0.Company { + String name + Address headquarters From e136f65c86c98e8669bcc445301a1e7f8edaa8de Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Fri, 17 Nov 2023 11:12:34 +0000 Subject: [PATCH 4/5] feat(*): uses associate array Signed-off-by: Jonathan Casey --- lib/codegen/fromcto/plantuml/plantumlvisitor.js | 8 +++++--- test/codegen/fromcto/plantuml/plantumlvisitor.js | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/codegen/fromcto/plantuml/plantumlvisitor.js b/lib/codegen/fromcto/plantuml/plantumlvisitor.js index 70bfd594..dbcb207c 100644 --- a/lib/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/lib/codegen/fromcto/plantuml/plantumlvisitor.js @@ -64,9 +64,11 @@ class PlantUMLVisitor extends DiagramVisitor { * @protected */ visitMapDeclaration(mapDeclaration, parameters) { - parameters.fileWriter.writeLine(0, 'class ' + this.escapeString(mapDeclaration.getFullyQualifiedName()) + ' << (M,pink) >> ' + '{' ); - parameters.fileWriter.writeLine(1, `+ ${mapDeclaration.getKey().getType()}` ); - parameters.fileWriter.writeLine(1, `+ ${mapDeclaration.getValue().getType()}` ); + const fqn = this.escapeString(mapDeclaration.getFullyQualifiedName()); + const keyType = mapDeclaration.getKey().getType(); + const valueType = mapDeclaration.getValue().getType(); + + parameters.fileWriter.writeLine(0, `map "${fqn}: Map<${keyType}, ${valueType}>" as ${fqn} {`); parameters.fileWriter.writeLine(0, '}' ); } diff --git a/test/codegen/fromcto/plantuml/plantumlvisitor.js b/test/codegen/fromcto/plantuml/plantumlvisitor.js index 76fb9140..6c8b2aca 100644 --- a/test/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/test/codegen/fromcto/plantuml/plantumlvisitor.js @@ -460,10 +460,8 @@ describe('PlantUMLVisitor', function () { plantUMLvisitor.visitMapDeclaration(mockMapDeclaration, param); - param.fileWriter.writeLine.callCount.should.deep.equal(4); - param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'class org.acme.NextOfKin << (M,pink) >> {']); - param.fileWriter.writeLine.getCall(1).args.should.deep.equal([1, '+ String']); - param.fileWriter.writeLine.getCall(2).args.should.deep.equal([1, '+ String']); + param.fileWriter.writeLine.callCount.should.deep.equal(2); + param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'map "org.acme.NextOfKin: Map" as org.acme.NextOfKin {']); param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, '}']); }); }); From 1fd3269c8f8d44974e84375cd0926ebb1fbf5fe6 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Fri, 17 Nov 2023 11:19:01 +0000 Subject: [PATCH 5/5] test(*): snapshot update Signed-off-by: Jonathan Casey --- test/codegen/__snapshots__/codegen.js.snap | 84 +++++-------------- .../fromcto/plantuml/plantumlvisitor.js | 2 +- 2 files changed, 22 insertions(+), 64 deletions(-) diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index 2fbbb889..3425c333 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -3799,9 +3799,7 @@ class org.acme.hr.base.TShirtSizeType << (E,grey) >> { + LARGE } org.acme.hr.base.TShirtSizeType --|> concerto_1_0_0.Concept -class org.acme.hr.base.EmployeeTShirtSizes << (M,pink) >> { - + SSN - + TShirtSizeType +map "org.acme.hr.base.EmployeeTShirtSizes: Map" as org.acme.hr.base.EmployeeTShirtSizes { } class org.acme.hr.base.Address { + String street @@ -3811,29 +3809,17 @@ class org.acme.hr.base.Address { + String country } org.acme.hr.base.Address --|> concerto_1_0_0.Concept -class org.acme.hr.CompanyProperties << (M,pink) >> { - + String - + String +map "org.acme.hr.CompanyProperties: Map" as org.acme.hr.CompanyProperties { } -class org.acme.hr.EmployeeLoginTimes << (M,pink) >> { - + String - + Time +map "org.acme.hr.EmployeeLoginTimes: Map" as org.acme.hr.EmployeeLoginTimes { } -class org.acme.hr.EmployeeSocialSecurityNumbers << (M,pink) >> { - + String - + SSN +map "org.acme.hr.EmployeeSocialSecurityNumbers: Map" as org.acme.hr.EmployeeSocialSecurityNumbers { } -class org.acme.hr.NextOfKin << (M,pink) >> { - + KinName - + KinTelephone +map "org.acme.hr.NextOfKin: Map" as org.acme.hr.NextOfKin { } -class org.acme.hr.EmployeeProfiles << (M,pink) >> { - + String - + Concept +map "org.acme.hr.EmployeeProfiles: Map" as org.acme.hr.EmployeeProfiles { } -class org.acme.hr.EmployeeDirectory << (M,pink) >> { - + SSN - + Employee +map "org.acme.hr.EmployeeDirectory: Map" as org.acme.hr.EmployeeDirectory { } class org.acme.hr.Company { + String name @@ -5828,9 +5814,7 @@ class org.acme.hr.base_1_0_0.TShirtSizeType << (E,grey) >> { + MEDIUM + LARGE } -class org.acme.hr.base_1_0_0.EmployeeTShirtSizes << (M,pink) >> { - + SSN - + TShirtSizeType +map "org.acme.hr.base_1_0_0.EmployeeTShirtSizes: Map" as org.acme.hr.base_1_0_0.EmployeeTShirtSizes { } class org.acme.hr.base_1_0_0.Address { + String street @@ -5840,29 +5824,17 @@ class org.acme.hr.base_1_0_0.Address { + String country } org.acme.hr.base_1_0_0.Address "1" *-- "1" org.acme.hr.base_1_0_0.State : state -class org.acme.hr_1_0_0.CompanyProperties << (M,pink) >> { - + String - + String +map "org.acme.hr_1_0_0.CompanyProperties: Map" as org.acme.hr_1_0_0.CompanyProperties { } -class org.acme.hr_1_0_0.EmployeeLoginTimes << (M,pink) >> { - + String - + Time +map "org.acme.hr_1_0_0.EmployeeLoginTimes: Map" as org.acme.hr_1_0_0.EmployeeLoginTimes { } -class org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers << (M,pink) >> { - + String - + SSN +map "org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers: Map" as org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers { } -class org.acme.hr_1_0_0.NextOfKin << (M,pink) >> { - + KinName - + KinTelephone +map "org.acme.hr_1_0_0.NextOfKin: Map" as org.acme.hr_1_0_0.NextOfKin { } -class org.acme.hr_1_0_0.EmployeeProfiles << (M,pink) >> { - + String - + Concept +map "org.acme.hr_1_0_0.EmployeeProfiles: Map" as org.acme.hr_1_0_0.EmployeeProfiles { } -class org.acme.hr_1_0_0.EmployeeDirectory << (M,pink) >> { - + SSN - + Employee +map "org.acme.hr_1_0_0.EmployeeDirectory: Map" as org.acme.hr_1_0_0.EmployeeDirectory { } class org.acme.hr_1_0_0.Company { + String name @@ -9773,9 +9745,7 @@ class org.acme.hr.base_1_0_0.TShirtSizeType << (E,grey) >> { + LARGE } org.acme.hr.base_1_0_0.TShirtSizeType --|> concerto_1_0_0.Concept -class org.acme.hr.base_1_0_0.EmployeeTShirtSizes << (M,pink) >> { - + SSN - + TShirtSizeType +map "org.acme.hr.base_1_0_0.EmployeeTShirtSizes: Map" as org.acme.hr.base_1_0_0.EmployeeTShirtSizes { } class org.acme.hr.base_1_0_0.Address { + String street @@ -9786,29 +9756,17 @@ class org.acme.hr.base_1_0_0.Address { } org.acme.hr.base_1_0_0.Address "1" *-- "1" org.acme.hr.base_1_0_0.State : state org.acme.hr.base_1_0_0.Address --|> concerto_1_0_0.Concept -class org.acme.hr_1_0_0.CompanyProperties << (M,pink) >> { - + String - + String +map "org.acme.hr_1_0_0.CompanyProperties: Map" as org.acme.hr_1_0_0.CompanyProperties { } -class org.acme.hr_1_0_0.EmployeeLoginTimes << (M,pink) >> { - + String - + Time +map "org.acme.hr_1_0_0.EmployeeLoginTimes: Map" as org.acme.hr_1_0_0.EmployeeLoginTimes { } -class org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers << (M,pink) >> { - + String - + SSN +map "org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers: Map" as org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers { } -class org.acme.hr_1_0_0.NextOfKin << (M,pink) >> { - + KinName - + KinTelephone +map "org.acme.hr_1_0_0.NextOfKin: Map" as org.acme.hr_1_0_0.NextOfKin { } -class org.acme.hr_1_0_0.EmployeeProfiles << (M,pink) >> { - + String - + Concept +map "org.acme.hr_1_0_0.EmployeeProfiles: Map" as org.acme.hr_1_0_0.EmployeeProfiles { } -class org.acme.hr_1_0_0.EmployeeDirectory << (M,pink) >> { - + SSN - + Employee +map "org.acme.hr_1_0_0.EmployeeDirectory: Map" as org.acme.hr_1_0_0.EmployeeDirectory { } class org.acme.hr_1_0_0.Company { + String name diff --git a/test/codegen/fromcto/plantuml/plantumlvisitor.js b/test/codegen/fromcto/plantuml/plantumlvisitor.js index 6c8b2aca..34e2ddcd 100644 --- a/test/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/test/codegen/fromcto/plantuml/plantumlvisitor.js @@ -462,7 +462,7 @@ describe('PlantUMLVisitor', function () { param.fileWriter.writeLine.callCount.should.deep.equal(2); param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'map "org.acme.NextOfKin: Map" as org.acme.NextOfKin {']); - param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, '}']); + param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, '}']); }); });