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

feat(map): Codegen for PlantUML Target #73

Merged
merged 5 commits into from
Nov 22, 2023
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
16 changes: 16 additions & 0 deletions lib/codegen/fromcto/plantuml/plantumlvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ 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) {
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, '}' );
}


/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
Expand Down
42 changes: 42 additions & 0 deletions test/codegen/__snapshots__/codegen.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3799,6 +3799,8 @@ class org.acme.hr.base.TShirtSizeType << (E,grey) >> {
+ LARGE
}
org.acme.hr.base.TShirtSizeType --|> concerto_1_0_0.Concept
map "org.acme.hr.base.EmployeeTShirtSizes: Map<SSN, TShirtSizeType>" as org.acme.hr.base.EmployeeTShirtSizes {
}
class org.acme.hr.base.Address {
+ String street
+ String city
Expand All @@ -3807,6 +3809,18 @@ class org.acme.hr.base.Address {
+ String country
}
org.acme.hr.base.Address --|> concerto_1_0_0.Concept
map "org.acme.hr.CompanyProperties: Map<String, String>" as org.acme.hr.CompanyProperties {
}
map "org.acme.hr.EmployeeLoginTimes: Map<String, Time>" as org.acme.hr.EmployeeLoginTimes {
}
map "org.acme.hr.EmployeeSocialSecurityNumbers: Map<String, SSN>" as org.acme.hr.EmployeeSocialSecurityNumbers {
}
map "org.acme.hr.NextOfKin: Map<KinName, KinTelephone>" as org.acme.hr.NextOfKin {
}
map "org.acme.hr.EmployeeProfiles: Map<String, Concept>" as org.acme.hr.EmployeeProfiles {
}
map "org.acme.hr.EmployeeDirectory: Map<SSN, Employee>" as org.acme.hr.EmployeeDirectory {
}
class org.acme.hr.Company {
+ String name
+ Address headquarters
Expand Down Expand Up @@ -5800,6 +5814,8 @@ class org.acme.hr.base_1_0_0.TShirtSizeType << (E,grey) >> {
+ MEDIUM
+ LARGE
}
map "org.acme.hr.base_1_0_0.EmployeeTShirtSizes: Map<SSN, TShirtSizeType>" as org.acme.hr.base_1_0_0.EmployeeTShirtSizes {
}
class org.acme.hr.base_1_0_0.Address {
+ String street
+ String city
Expand All @@ -5808,6 +5824,18 @@ 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
map "org.acme.hr_1_0_0.CompanyProperties: Map<String, String>" as org.acme.hr_1_0_0.CompanyProperties {
}
map "org.acme.hr_1_0_0.EmployeeLoginTimes: Map<String, Time>" as org.acme.hr_1_0_0.EmployeeLoginTimes {
}
map "org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers: Map<String, SSN>" as org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers {
}
map "org.acme.hr_1_0_0.NextOfKin: Map<KinName, KinTelephone>" as org.acme.hr_1_0_0.NextOfKin {
}
map "org.acme.hr_1_0_0.EmployeeProfiles: Map<String, Concept>" as org.acme.hr_1_0_0.EmployeeProfiles {
}
map "org.acme.hr_1_0_0.EmployeeDirectory: Map<SSN, Employee>" as org.acme.hr_1_0_0.EmployeeDirectory {
}
class org.acme.hr_1_0_0.Company {
+ String name
+ Address headquarters
Expand Down Expand Up @@ -9717,6 +9745,8 @@ 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
map "org.acme.hr.base_1_0_0.EmployeeTShirtSizes: Map<SSN, TShirtSizeType>" as org.acme.hr.base_1_0_0.EmployeeTShirtSizes {
}
class org.acme.hr.base_1_0_0.Address {
+ String street
+ String city
Expand All @@ -9726,6 +9756,18 @@ 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
map "org.acme.hr_1_0_0.CompanyProperties: Map<String, String>" as org.acme.hr_1_0_0.CompanyProperties {
}
map "org.acme.hr_1_0_0.EmployeeLoginTimes: Map<String, Time>" as org.acme.hr_1_0_0.EmployeeLoginTimes {
}
map "org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers: Map<String, SSN>" as org.acme.hr_1_0_0.EmployeeSocialSecurityNumbers {
}
map "org.acme.hr_1_0_0.NextOfKin: Map<KinName, KinTelephone>" as org.acme.hr_1_0_0.NextOfKin {
}
map "org.acme.hr_1_0_0.EmployeeProfiles: Map<String, Concept>" as org.acme.hr_1_0_0.EmployeeProfiles {
}
map "org.acme.hr_1_0_0.EmployeeDirectory: Map<SSN, Employee>" as org.acme.hr_1_0_0.EmployeeDirectory {
}
class org.acme.hr_1_0_0.Company {
+ String name
+ Address headquarters
Expand Down
26 changes: 26 additions & 0 deletions test/codegen/fromcto/plantuml/plantumlvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -440,6 +441,31 @@ 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(2);
param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'map "org.acme.NextOfKin: Map<String, String>" as org.acme.NextOfKin {']);
param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, '}']);
});
});

describe('visitClassDeclaration', () => {
it('should write the class declaration for a class', () => {
let acceptSpy = sinon.spy();
Expand Down
Loading