From d1096bc66e041a746ccd4939eb7b992f908f857a Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Thu, 1 Aug 2024 00:18:31 +0530 Subject: [PATCH 01/17] feat(i114): updated the property type-resolution Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index fefab2c..fcdb6b9 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -383,7 +383,7 @@ class CSharpVisitor { } } else if (!field.isPrimitive()) { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); - fieldType = `${fqn}${fieldType}`; + fieldType = `${fqn}${field.getModelFile().getActualImportType(fieldType)}`; } let nullableType = ''; From 256d766690be15ea8d3fabd440b44d1fa7154647 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Fri, 2 Aug 2024 11:03:02 +0530 Subject: [PATCH 02/17] feat(csharp-alias-import): minor bug fixed - Earlier non-imported types gave error. Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index fcdb6b9..a33c495 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -383,7 +383,11 @@ class CSharpVisitor { } } else if (!field.isPrimitive()) { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); - fieldType = `${fqn}${field.getModelFile().getActualImportType(fieldType)}`; + const modelFile = field.getModelFile(); + if (modelFile.isImportedType(fieldType)) { + fieldType = modelFile.getActualImportType(fieldType); + } + fieldType = `${fqn}${fieldType}`; } let nullableType = ''; From 818ce77a3322fc75d28fed281ae621a275d7323a Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Fri, 2 Aug 2024 12:17:24 +0530 Subject: [PATCH 03/17] feat(i114): test cases added and minor bug fixed Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 2 +- test/codegen/fromcto/csharp/csharpvisitor.js | 59 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index a33c495..37d6456 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -384,7 +384,7 @@ class CSharpVisitor { } else if (!field.isPrimitive()) { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); const modelFile = field.getModelFile(); - if (modelFile.isImportedType(fieldType)) { + if (modelFile && modelFile.isImportedType(fieldType)) { fieldType = modelFile.getActualImportType(fieldType); } fieldType = `${fqn}${fieldType}`; diff --git a/test/codegen/fromcto/csharp/csharpvisitor.js b/test/codegen/fromcto/csharp/csharpvisitor.js index 1e9640e..7ae4cf0 100644 --- a/test/codegen/fromcto/csharp/csharpvisitor.js +++ b/test/codegen/fromcto/csharp/csharpvisitor.js @@ -785,6 +785,65 @@ public class SampleModel : Concept { file1.should.match(/public System.Guid otherThingId/); file1.should.match(/public string someOtherThingId/); }); + + it('should handle imported field which is aliased in a concept', () => { + const modelManager = new ModelManager({ enableAliasedType: true }); + modelManager.addCTOModel(` + namespace org.example.basic + concept file{ + o String name + } + `); + modelManager.addCTOModel(` + namespace org.example.complex + import org.example.basic.{file as f} + + concept folder { + o String name + o f[] files + } + `); + csharpVisitor.visit(modelManager, { fileWriter }); + const files = fileWriter.getFilesInMemory(); + const file1 = files.get('org.example.basic.cs'); + file1.should.match(/namespace org.example.basic;/); + file1.should.match(/class file : Concept/); + file1.should.match(/public string name { get; set; }/); + + const file2 = files.get('org.example.complex.cs'); + file2.should.match(/namespace org.example.complex;/); + file2.should.match(/using org.example.basic;/); + file2.should.match(/class folder : Concept/); + file2.should.match(/org.example.basic.file\[\] files/); + }); + + it('should handle imported field which extended in concept', () => { + const modelManager = new ModelManager({ enableAliasedType: true }); + modelManager.addCTOModel(` + namespace org.example.basic + concept file{ + o String name + } + `); + modelManager.addCTOModel(` + namespace org.example.complex + import org.example.basic.{file as f} + + concept bigFile extends f{ + } + `); + csharpVisitor.visit(modelManager, { fileWriter }); + const files = fileWriter.getFilesInMemory(); + const file1 = files.get('org.example.basic.cs'); + file1.should.match(/namespace org.example.basic;/); + file1.should.match(/class file : Concept/); + file1.should.match(/public string name { get; set; }/); + + const file2 = files.get('org.example.complex.cs'); + file2.should.match(/namespace org.example.complex;/); + file2.should.match(/using org.example.basic;/); + file2.should.match(/public class bigFile : org.example.basic.file/); + }); }); describe('visit', () => { From c3e6377896d169410e605e5e27f961936f6a17df Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Sun, 4 Aug 2024 20:51:10 +0530 Subject: [PATCH 04/17] feat(i114): Java visitor updated for aliased import Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 4 ++-- lib/codegen/fromcto/java/javavisitor.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index 37d6456..0590f53 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -15,7 +15,7 @@ 'use strict'; -const { ModelUtil } = require('@accordproject/concerto-core'); +const { ModelUtil, ModelFile } = require('@accordproject/concerto-core'); const camelCase = require('camelcase'); const { throwUnrecognizedType } = require('../../../common/util'); @@ -384,7 +384,7 @@ class CSharpVisitor { } else if (!field.isPrimitive()) { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); const modelFile = field.getModelFile(); - if (modelFile && modelFile.isImportedType(fieldType)) { + if (modelFile instanceof ModelFile && modelFile.isImportedType(fieldType)) { fieldType = modelFile.getActualImportType(fieldType); } fieldType = `${fqn}${fieldType}`; diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index a3f296c..182506c 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -14,6 +14,7 @@ 'use strict'; +const { ModelFile } = require('@accordproject/concerto-core'); const EmptyPlugin = require('./emptyplugin'); const ModelUtil = require('@accordproject/concerto-core').ModelUtil; const util = require('util'); @@ -267,9 +268,14 @@ class JavaVisitor { if(field.isArray()) { array = '[]'; } - - const fieldType = this.toJavaType(field.getType()) + array; - + let fieldType = field.getType(); + if (!ModelUtil.isPrimitiveType(fieldType)) { + const modelFile = field.getModelFile(); + if (modelFile instanceof ModelFile && modelFile.isImportedType(fieldType)) { + fieldType = modelFile.getActualImportType(fieldType); + } + } + fieldType = this.toJavaType(fieldType) + array; const fieldName = field.getName(); const getterName = 'get' + this.capitalizeFirstLetter(fieldName); const setterName = 'set' + this.capitalizeFirstLetter(fieldName); From 52bdf48ab4febcad198053ae038d780b479c7099 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Fri, 23 Aug 2024 18:03:51 +0530 Subject: [PATCH 05/17] feat(alias-import):updating changes Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 2 +- lib/codegen/fromcto/java/javavisitor.js | 2 +- test/codegen/fromcto/csharp/csharpvisitor.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index 0590f53..293f06c 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -385,7 +385,7 @@ class CSharpVisitor { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); const modelFile = field.getModelFile(); if (modelFile instanceof ModelFile && modelFile.isImportedType(fieldType)) { - fieldType = modelFile.getActualImportType(fieldType); + fieldType = modelFile.getImportedType(fieldType); } fieldType = `${fqn}${fieldType}`; } diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index 182506c..7822d08 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -272,7 +272,7 @@ class JavaVisitor { if (!ModelUtil.isPrimitiveType(fieldType)) { const modelFile = field.getModelFile(); if (modelFile instanceof ModelFile && modelFile.isImportedType(fieldType)) { - fieldType = modelFile.getActualImportType(fieldType); + fieldType = modelFile.getImportedType(fieldType); } } fieldType = this.toJavaType(fieldType) + array; diff --git a/test/codegen/fromcto/csharp/csharpvisitor.js b/test/codegen/fromcto/csharp/csharpvisitor.js index 7ae4cf0..01c475e 100644 --- a/test/codegen/fromcto/csharp/csharpvisitor.js +++ b/test/codegen/fromcto/csharp/csharpvisitor.js @@ -787,7 +787,7 @@ public class SampleModel : Concept { }); it('should handle imported field which is aliased in a concept', () => { - const modelManager = new ModelManager({ enableAliasedType: true }); + const modelManager = new ModelManager({ importAliasing: true }); modelManager.addCTOModel(` namespace org.example.basic concept file{ @@ -818,7 +818,7 @@ public class SampleModel : Concept { }); it('should handle imported field which extended in concept', () => { - const modelManager = new ModelManager({ enableAliasedType: true }); + const modelManager = new ModelManager({ importAliasing: true }); modelManager.addCTOModel(` namespace org.example.basic concept file{ From d99666bb597c37305528572c161ccb4fca58600f Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Tue, 3 Sep 2024 16:16:38 +0530 Subject: [PATCH 06/17] feat(alias-import): Test cases for java-visitor added Signed-off-by: Jaskeerat Singh Saluja --- test/codegen/fromcto/java/javavisitor.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/codegen/fromcto/java/javavisitor.js b/test/codegen/fromcto/java/javavisitor.js index 7ed6f00..3389fc5 100644 --- a/test/codegen/fromcto/java/javavisitor.js +++ b/test/codegen/fromcto/java/javavisitor.js @@ -582,6 +582,26 @@ describe('JavaVisitor', function () { param.fileWriter.writeLine.getCall(1).args.should.deep.equal([2, 'return this.Bob;']); param.fileWriter.writeLine.getCall(2).args.should.deep.equal([1, '}']); }); + + it('should write a line getting a field of type aliased import', ()=> { + // Document aliased as Doc + let mockField = sinon.createStubInstance(Field); + let mockModelFile = sinon.createStubInstance(ModelFile); + + mockField.isField.returns(true); + mockField.isArray.returns(false); + mockField.getName.returns('Bob'); + mockField.getType.returns('Doc'); + mockField.getModelFile.returns(mockModelFile); + mockModelFile.isImportedType.returns(true); + mockModelFile.getImportedType.returns('Document'); + + javaVisit.visitField(mockField , Object.assign({},param,{mode:'getter'})); + param.fileWriter.writeLine.callCount.should.deep.equal(3); + param.fileWriter.writeLine.getCall(0).args.should.deep.equal([1, 'public Document getBob() {']); + param.fileWriter.writeLine.getCall(1).args.should.deep.equal([2, 'return this.Bob;']); + param.fileWriter.writeLine.getCall(2).args.should.deep.equal([1, '}']); + }); }); describe('visitEnumValueDeclaration', () => { From b692d4d56d8ecd0f27636aaee16cd72cb4e8c44f Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Tue, 3 Sep 2024 16:29:25 +0530 Subject: [PATCH 07/17] feat(import-alias): concerto-core version updated and minor changes Signed-off-by: Jaskeerat Singh Saluja --- package-lock.json | 47 +++++++++++++++++++++--- package.json | 2 +- test/codegen/codegen.js | 1 + test/codegen/fromcto/java/javavisitor.js | 4 +- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8766e93..c3112c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.23.1", "license": "Apache-2.0", "dependencies": { - "@accordproject/concerto-core": "3.18.0", + "@accordproject/concerto-core": "3.19.0", "@accordproject/concerto-util": "3.18.0", "@accordproject/concerto-vocabulary": "3.18.0", "@openapi-contrib/openapi-schema-to-json-schema": "5.1.0", @@ -61,13 +61,14 @@ } }, "node_modules/@accordproject/concerto-core": { - "version": "3.18.0", - "resolved": "https://registry.npmjs.org/@accordproject/concerto-core/-/concerto-core-3.18.0.tgz", - "integrity": "sha512-a1f1Z79oJEBrW+eYa65+R14TLv6Mdom/5tny7sBWV/RT2S3iCUCop6jGSpycADgvIkrDySnW4F3hSct4+0ZHLg==", + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/@accordproject/concerto-core/-/concerto-core-3.19.0.tgz", + "integrity": "sha512-zgAV8s5e+I4wGJjYeQkYl/5c3/Ew8ZbQWunbICu2obtoW4xmvPJ7gWBRg2n3lrsCYuEde7eMT8tRZ8Kcgwuh7w==", + "license": "Apache-2.0", "dependencies": { - "@accordproject/concerto-cto": "3.18.0", + "@accordproject/concerto-cto": "3.19.0", "@accordproject/concerto-metamodel": "3.10.0", - "@accordproject/concerto-util": "3.18.0", + "@accordproject/concerto-util": "3.19.0", "dayjs": "1.11.10", "debug": "4.3.4", "lorem-ipsum": "2.0.8", @@ -82,10 +83,44 @@ "npm": ">=8" } }, + "node_modules/@accordproject/concerto-core/node_modules/@accordproject/concerto-cto": { + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/@accordproject/concerto-cto/-/concerto-cto-3.19.0.tgz", + "integrity": "sha512-eA8O2IcEmnOdGTu2bWeSFQMSSHQr7vJ/Gzhv0cWxnh41wxKhmfoBK/BmEZgyJi6dI7HufKkat+p2B76MIwCqOA==", + "license": "Apache-2.0", + "dependencies": { + "@accordproject/concerto-metamodel": "3.10.0", + "@accordproject/concerto-util": "3.19.0", + "path-browserify": "1.0.1" + }, + "engines": { + "node": ">=16", + "npm": ">=8" + } + }, + "node_modules/@accordproject/concerto-core/node_modules/@accordproject/concerto-util": { + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/@accordproject/concerto-util/-/concerto-util-3.19.0.tgz", + "integrity": "sha512-zadhEhKoVDuRcmUZGH5xbgV2Am1zv8jMPJaedWadiSyqw2qif95MZvKg7DEIdSohQvcfJ5z53iPJqsdmfauJAA==", + "license": "Apache-2.0", + "dependencies": { + "@supercharge/promise-pool": "1.7.0", + "axios": "1.6.8", + "colors": "1.4.0", + "debug": "4.3.4", + "json-colorizer": "2.2.2", + "slash": "3.0.0" + }, + "engines": { + "node": ">=16", + "npm": ">=8" + } + }, "node_modules/@accordproject/concerto-cto": { "version": "3.18.0", "resolved": "https://registry.npmjs.org/@accordproject/concerto-cto/-/concerto-cto-3.18.0.tgz", "integrity": "sha512-zrE42ip6Tfavyr/Hox2AIc785McobYjK756KR1bOX4aUWZQtQTpzBZKIwM4wsfsb7HZ+sLxEkzFYidk2TCguBw==", + "dev": true, "dependencies": { "@accordproject/concerto-metamodel": "3.10.0", "@accordproject/concerto-util": "3.18.0", diff --git a/package.json b/package.json index ef6bcdf..6650b19 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "webpack-cli": "4.9.1" }, "dependencies": { - "@accordproject/concerto-core": "3.18.0", + "@accordproject/concerto-core": "3.19.0", "@accordproject/concerto-util": "3.18.0", "@accordproject/concerto-vocabulary": "3.18.0", "@openapi-contrib/openapi-schema-to-json-schema": "5.1.0", diff --git a/test/codegen/codegen.js b/test/codegen/codegen.js index b80204d..2aaf4c9 100644 --- a/test/codegen/codegen.js +++ b/test/codegen/codegen.js @@ -31,6 +31,7 @@ describe('codegen', function () { before(function() { process.env.ENABLE_MAP_TYPE = 'true'; // TODO Remove on release of MapType + process.env.IMPORT_ALIASING = 'true'; }); beforeEach(function() { diff --git a/test/codegen/fromcto/java/javavisitor.js b/test/codegen/fromcto/java/javavisitor.js index 3389fc5..557eab2 100644 --- a/test/codegen/fromcto/java/javavisitor.js +++ b/test/codegen/fromcto/java/javavisitor.js @@ -583,7 +583,7 @@ describe('JavaVisitor', function () { param.fileWriter.writeLine.getCall(2).args.should.deep.equal([1, '}']); }); - it('should write a line getting a field of type aliased import', ()=> { + it('should write a line getting a field of type aliased import', () => { // Document aliased as Doc let mockField = sinon.createStubInstance(Field); let mockModelFile = sinon.createStubInstance(ModelFile); @@ -596,7 +596,7 @@ describe('JavaVisitor', function () { mockModelFile.isImportedType.returns(true); mockModelFile.getImportedType.returns('Document'); - javaVisit.visitField(mockField , Object.assign({},param,{mode:'getter'})); + javaVisit.visitField(mockField, Object.assign({}, param, { mode: 'getter' })); param.fileWriter.writeLine.callCount.should.deep.equal(3); param.fileWriter.writeLine.getCall(0).args.should.deep.equal([1, 'public Document getBob() {']); param.fileWriter.writeLine.getCall(1).args.should.deep.equal([2, 'return this.Bob;']); From e2386359de88115ed8ac06dcafe1655fcc65d290 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Tue, 3 Sep 2024 17:39:34 +0530 Subject: [PATCH 08/17] feat(alias-import):Minor bug fixed Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 4 ++-- lib/codegen/fromcto/java/javavisitor.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index 293f06c..6b8c970 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -15,7 +15,7 @@ 'use strict'; -const { ModelUtil, ModelFile } = require('@accordproject/concerto-core'); +const { ModelUtil } = require('@accordproject/concerto-core'); const camelCase = require('camelcase'); const { throwUnrecognizedType } = require('../../../common/util'); @@ -384,7 +384,7 @@ class CSharpVisitor { } else if (!field.isPrimitive()) { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); const modelFile = field.getModelFile(); - if (modelFile instanceof ModelFile && modelFile.isImportedType(fieldType)) { + if (modelFile?.isImportedType?.(fieldType)) { fieldType = modelFile.getImportedType(fieldType); } fieldType = `${fqn}${fieldType}`; diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index 7822d08..bffc386 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -14,7 +14,6 @@ 'use strict'; -const { ModelFile } = require('@accordproject/concerto-core'); const EmptyPlugin = require('./emptyplugin'); const ModelUtil = require('@accordproject/concerto-core').ModelUtil; const util = require('util'); @@ -271,7 +270,7 @@ class JavaVisitor { let fieldType = field.getType(); if (!ModelUtil.isPrimitiveType(fieldType)) { const modelFile = field.getModelFile(); - if (modelFile instanceof ModelFile && modelFile.isImportedType(fieldType)) { + if (modelFile?.isImportedType?.(fieldType)) { fieldType = modelFile.getImportedType(fieldType); } } From c204762ac95cf13c8e7d62184dcc43ed7711adba Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Tue, 3 Sep 2024 18:50:33 +0530 Subject: [PATCH 09/17] feat(alias-import): Pr suggestions Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/csharp/csharpvisitor.js | 2 +- lib/codegen/fromcto/java/javavisitor.js | 2 +- test/codegen/fromcto/java/javavisitor.js | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index 6b8c970..e7ac7a7 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -384,7 +384,7 @@ class CSharpVisitor { } else if (!field.isPrimitive()) { let fqn = this.getDotNetNamespaceOfType(field.getFullyQualifiedTypeName(), field.getParent(), parameters); const modelFile = field.getModelFile(); - if (modelFile?.isImportedType?.(fieldType)) { + if (modelFile?.isImportedType(fieldType)) { fieldType = modelFile.getImportedType(fieldType); } fieldType = `${fqn}${fieldType}`; diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index bffc386..7a6b838 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -270,7 +270,7 @@ class JavaVisitor { let fieldType = field.getType(); if (!ModelUtil.isPrimitiveType(fieldType)) { const modelFile = field.getModelFile(); - if (modelFile?.isImportedType?.(fieldType)) { + if (modelFile?.isImportedType(fieldType)) { fieldType = modelFile.getImportedType(fieldType); } } diff --git a/test/codegen/fromcto/java/javavisitor.js b/test/codegen/fromcto/java/javavisitor.js index 557eab2..375ab98 100644 --- a/test/codegen/fromcto/java/javavisitor.js +++ b/test/codegen/fromcto/java/javavisitor.js @@ -467,9 +467,10 @@ describe('JavaVisitor', function () { const mockField = sinon.createStubInstance(Field); const getType = sinon.stub(); + const isImportedType = sinon.stub(); mockField.ast = { type: { name: 'Dummy Value'} }; - mockField.getModelFile.returns({ getType: getType }); + mockField.getModelFile.returns({ getType: getType, isImportedType: isImportedType }); const mockMapDeclaration = sinon.createStubInstance(MapDeclaration); const getKeyType = sinon.stub(); @@ -481,6 +482,7 @@ describe('JavaVisitor', function () { getType.returns(mockMapDeclaration); getKeyType.returns('String'); getValueType.returns('String'); + isImportedType.returns(false); mockField.getName.returns('Map1'); mockMapDeclaration.getName.returns('Map1'); mockMapDeclaration.isMapDeclaration.returns(true); From 063f08d7ce473d43470ab15647fcd24216d51db4 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Tue, 3 Sep 2024 23:19:39 +0530 Subject: [PATCH 10/17] feat(alias-import): visit function updated visitModelFile and visitClassDeclaration updated for the typescriptvisitor.js Signed-off-by: Jaskeerat Singh Saluja --- .../fromcto/typescript/typescriptvisitor.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/codegen/fromcto/typescript/typescriptvisitor.js b/lib/codegen/fromcto/typescript/typescriptvisitor.js index 0d79460..7486a16 100644 --- a/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -89,6 +89,15 @@ class TypescriptVisitor { // Compute the types we need to import (based on all the types of the properites // as well as all the super types) for all the classes in this model file parameters.fileWriter.writeLine(0, '\n// imports'); + + const aliasedTypesMap = new Map(); + modelFile.imports.forEach((imp) => { + if (imp['$class'] == 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) { + imp.aliasedTypes.forEach((type) => { + aliasedTypesMap.set(`I${type.name}`, `I${type.aliasedName}`); + }); + } + }); const properties = new Map(); modelFile.getAllDeclarations() .filter(declaration => !declaration.isScalarDeclaration?.()) @@ -143,12 +152,15 @@ class TypescriptVisitor { .forEach(namespace => { const propertyTypeNames = properties.get(namespace); if (propertyTypeNames) { - const csvPropertyTypeNames = Array.from(propertyTypeNames).join(); + const csvPropertyTypeNames = Array.from(propertyTypeNames).map((type) => + aliasedTypesMap.has(type) ? `${type} as ${aliasedTypesMap.get(type)}` : type + ); parameters.fileWriter.writeLine(0, `import {${csvPropertyTypeNames}} from './${namespace}';`); } }); parameters.fileWriter.writeLine(0, '\n// interfaces'); + parameters.aliasedTypesMap = aliasedTypesMap; modelFile.getAllDeclarations() .filter(declaration => !declaration.isScalarDeclaration?.()).forEach((decl) => { decl.accept(this, parameters); @@ -189,7 +201,8 @@ class TypescriptVisitor { let superType = ' '; if (classDeclaration.getSuperType()) { - superType = ` extends I${ModelUtil.getShortName(classDeclaration.getSuperType())} `; + superType = `I${ModelUtil.getShortName(classDeclaration.getSuperType())}`; + superType = ` extends ${parameters.aliasedTypesMap.has(superType) ? parameters.aliasedTypesMap.get(superType) : superType} `; } parameters.fileWriter.writeLine(0, 'export interface I' + classDeclaration.getName() + superType + '{'); From 0b262503f2ed269acf3385a2e8077fe2c88920e4 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Wed, 4 Sep 2024 16:03:17 +0530 Subject: [PATCH 11/17] feat(alias-import): fixing code Signed-off-by: Jaskeerat Singh Saluja --- .../fromcto/typescript/typescriptvisitor.js | 4 +- .../fromcto/typescript/typescriptvisitor.js | 55 ++++++++++++++++++- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/lib/codegen/fromcto/typescript/typescriptvisitor.js b/lib/codegen/fromcto/typescript/typescriptvisitor.js index 7486a16..513da37 100644 --- a/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -92,12 +92,12 @@ class TypescriptVisitor { const aliasedTypesMap = new Map(); modelFile.imports.forEach((imp) => { - if (imp['$class'] == 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) { + if (imp.$class === 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) { imp.aliasedTypes.forEach((type) => { aliasedTypesMap.set(`I${type.name}`, `I${type.aliasedName}`); }); } - }); + }); const properties = new Map(); modelFile.getAllDeclarations() .filter(declaration => !declaration.isScalarDeclaration?.()) diff --git a/test/codegen/fromcto/typescript/typescriptvisitor.js b/test/codegen/fromcto/typescript/typescriptvisitor.js index 26fbcb7..57f92c1 100644 --- a/test/codegen/fromcto/typescript/typescriptvisitor.js +++ b/test/codegen/fromcto/typescript/typescriptvisitor.js @@ -232,6 +232,7 @@ describe('TypescriptVisitor', function () { 'super.Property3', 'super.Parent' ]); + mockModelFile.imports= []; typescriptVisitor.visitModelFile(mockModelFile, param); @@ -302,7 +303,7 @@ describe('TypescriptVisitor', function () { 'org.org2.Import1' ]); mockModelFile.getModelManager.returns(mockModelManager); - + mockModelFile.imports= []; typescriptVisitor.visitModelFile(mockModelFile, param); param.fileWriter.openFile.withArgs('org.acme.ts').calledOnce.should.be.ok; @@ -358,7 +359,7 @@ describe('TypescriptVisitor', function () { ]); mockModelFile.getImports.returns([]); mockModelFile.getModelManager.returns(mockModelManager); - + mockModelFile.imports = []; typescriptVisitor.visitModelFile(mockModelFile, param); param.fileWriter.openFile.withArgs('org.acme.ts').calledOnce.should.be.ok; @@ -373,6 +374,54 @@ describe('TypescriptVisitor', function () { acceptSpy.withArgs(typescriptVisitor, param).calledOnce.should.be.ok; }); + + it('should write lines for the aliased imports from other namespace ', () => { + + let property1 = { + isPrimitive: () => { + return false; + }, + getFullyQualifiedTypeName: () => { + return 'org.test.basic.file'; + } + }; + + let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); + + mockClassDeclaration.isClassDeclaration.returns(true); + mockClassDeclaration.getProperties.returns([property1]); + mockClassDeclaration.getNamespace.returns('org.test.collection'); + mockClassDeclaration.getName.returns('folder'); + mockClassDeclaration.getDirectSubclasses.returns([]); + + let mockModelFile = sinon.createStubInstance(ModelFile); + mockModelFile.getNamespace.returns('org.test.collection'); + mockModelFile.imports = [ + { + '$class': 'concerto.metamodel@1.0.0.ImportTypes', + types: ['document', 'file'], + aliasedTypes: [ + { + name: 'file', + aliasedName: 'f' + } + ] + } + ]; + + mockModelFile.getAllDeclarations.returns([mockClassDeclaration]); + mockModelFile.getImports.returns(['org.test.basic.file','org.test.basic.document']); + typescriptVisitor.visitModelFile(mockModelFile,param); + + param.fileWriter.writeLine.callCount.should.deep.equal(5); + param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, '/* eslint-disable @typescript-eslint/no-empty-interface */']); + param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, '// Generated code for namespace: org.test.collection']); + param.fileWriter.writeLine.getCall(2).args.should.deep.equal([0, '\n// imports']); + param.fileWriter.writeLine.getCall(4).args.should.deep.equal([0, 'import type {\nIfile as If} from \'./org.test.collection\';']); + param.fileWriter.writeLine.getCall(5).args.should.deep.equal([0, '// interfaces']); + param.fileWriter.closeFile.calledOnce.should.be.ok; + + }); }); describe('visitEnumDeclaration', () => { @@ -444,7 +493,7 @@ describe('TypescriptVisitor', function () { mockClassDeclaration.getName.returns('Bob'); mockClassDeclaration.isAbstract.returns(true); mockClassDeclaration.getSuperType.returns('org.acme.Person'); - + param.aliasedTypesMap=new Map(); typescriptVisitor.visitClassDeclaration(mockClassDeclaration, param); param.fileWriter.writeLine.callCount.should.deep.equal(2); From 189081dc4c1f86d9dedaf6c26c361a7d4be09b95 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Thu, 5 Sep 2024 23:09:36 +0530 Subject: [PATCH 12/17] feat(alias-import): Typescript Codegen fixed Signed-off-by: Jaskeerat Singh Saluja --- .../fromcto/typescript/typescriptvisitor.js | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/codegen/fromcto/typescript/typescriptvisitor.js b/lib/codegen/fromcto/typescript/typescriptvisitor.js index 513da37..cfead7c 100644 --- a/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -14,6 +14,7 @@ 'use strict'; +const ModelFile = require('@accordproject/concerto-core').ModelFile const ModelUtil = require('@accordproject/concerto-core').ModelUtil; const { throwUnrecognizedType } = require('../../../common/util'); @@ -89,15 +90,14 @@ class TypescriptVisitor { // Compute the types we need to import (based on all the types of the properites // as well as all the super types) for all the classes in this model file parameters.fileWriter.writeLine(0, '\n// imports'); - const aliasedTypesMap = new Map(); - modelFile.imports.forEach((imp) => { - if (imp.$class === 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) { - imp.aliasedTypes.forEach((type) => { - aliasedTypesMap.set(`I${type.name}`, `I${type.aliasedName}`); + modelFile.imports + .filter(imp => imp.$class === 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) + .forEach(imp => { + imp.aliasedTypes.forEach(type => { + aliasedTypesMap.set(`${imp.namespace}.I${type.name}`, `I${type.aliasedName}`); }); - } - }); + }); const properties = new Map(); modelFile.getAllDeclarations() .filter(declaration => !declaration.isScalarDeclaration?.()) @@ -152,9 +152,10 @@ class TypescriptVisitor { .forEach(namespace => { const propertyTypeNames = properties.get(namespace); if (propertyTypeNames) { - const csvPropertyTypeNames = Array.from(propertyTypeNames).map((type) => - aliasedTypesMap.has(type) ? `${type} as ${aliasedTypesMap.get(type)}` : type - ); + const csvPropertyTypeNames = Array.from(propertyTypeNames).map(type => { + const fqnType = `${namespace}.${type}`; + return aliasedTypesMap.get(fqnType) ? `${type} as ${aliasedTypesMap.get(fqnType)}` : type; + }); parameters.fileWriter.writeLine(0, `import {${csvPropertyTypeNames}} from './${namespace}';`); } }); @@ -199,14 +200,15 @@ class TypescriptVisitor { */ visitClassDeclaration(classDeclaration, parameters) { - let superType = ' '; - if (classDeclaration.getSuperType()) { - superType = `I${ModelUtil.getShortName(classDeclaration.getSuperType())}`; - superType = ` extends ${parameters.aliasedTypesMap.has(superType) ? parameters.aliasedTypesMap.get(superType) : superType} `; + let superType = ''; + const type = classDeclaration.getSuperType(); + if (type) { + const namespace = ModelUtil.getNamespace(type); + const shortName = `I${ModelUtil.getShortName(type)}`; + const fullType = `${namespace}.${shortName}`; + superType = ` extends ${parameters.aliasedTypesMap.get(fullType) || shortName}`; } - - parameters.fileWriter.writeLine(0, 'export interface I' + classDeclaration.getName() + superType + '{'); - + parameters.fileWriter.writeLine(0, `export interface I${classDeclaration.getName()}${superType} {`); if(!classDeclaration.getSuperType()) { parameters.fileWriter.writeLine(1, '$class: string;'); } From f2c6d632a98151845d37e1c911fa9b5db3b116bc Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Thu, 5 Sep 2024 23:28:03 +0530 Subject: [PATCH 13/17] feat(alias-import): test-cases Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/typescript/typescriptvisitor.js | 1 - test/codegen/fromcto/typescript/typescriptvisitor.js | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/codegen/fromcto/typescript/typescriptvisitor.js b/lib/codegen/fromcto/typescript/typescriptvisitor.js index cfead7c..5befdef 100644 --- a/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -14,7 +14,6 @@ 'use strict'; -const ModelFile = require('@accordproject/concerto-core').ModelFile const ModelUtil = require('@accordproject/concerto-core').ModelUtil; const { throwUnrecognizedType } = require('../../../common/util'); diff --git a/test/codegen/fromcto/typescript/typescriptvisitor.js b/test/codegen/fromcto/typescript/typescriptvisitor.js index 57f92c1..33f6948 100644 --- a/test/codegen/fromcto/typescript/typescriptvisitor.js +++ b/test/codegen/fromcto/typescript/typescriptvisitor.js @@ -392,6 +392,7 @@ describe('TypescriptVisitor', function () { mockClassDeclaration.getProperties.returns([property1]); mockClassDeclaration.getNamespace.returns('org.test.collection'); mockClassDeclaration.getName.returns('folder'); + mockClassDeclaration.getDirectSubclasses.returns([]); let mockModelFile = sinon.createStubInstance(ModelFile); @@ -400,6 +401,7 @@ describe('TypescriptVisitor', function () { { '$class': 'concerto.metamodel@1.0.0.ImportTypes', types: ['document', 'file'], + namespace:'org.test.basic', aliasedTypes: [ { name: 'file', @@ -417,8 +419,8 @@ describe('TypescriptVisitor', function () { param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, '/* eslint-disable @typescript-eslint/no-empty-interface */']); param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, '// Generated code for namespace: org.test.collection']); param.fileWriter.writeLine.getCall(2).args.should.deep.equal([0, '\n// imports']); - param.fileWriter.writeLine.getCall(4).args.should.deep.equal([0, 'import type {\nIfile as If} from \'./org.test.collection\';']); - param.fileWriter.writeLine.getCall(5).args.should.deep.equal([0, '// interfaces']); + param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, 'import {Ifile as If} from \'./org.test.basic\';']); + param.fileWriter.writeLine.getCall(4).args.should.deep.equal([0, '\n// interfaces']); param.fileWriter.closeFile.calledOnce.should.be.ok; }); From a6d615f984edec638f4232f09b90636529863efa Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Thu, 5 Sep 2024 23:47:57 +0530 Subject: [PATCH 14/17] feat(import-alias):Test case updated Signed-off-by: Jaskeerat Singh Saluja --- .../fromcto/typescript/typescriptvisitor.js | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/codegen/fromcto/typescript/typescriptvisitor.js b/test/codegen/fromcto/typescript/typescriptvisitor.js index 33f6948..2060f90 100644 --- a/test/codegen/fromcto/typescript/typescriptvisitor.js +++ b/test/codegen/fromcto/typescript/typescriptvisitor.js @@ -386,10 +386,19 @@ describe('TypescriptVisitor', function () { } }; + let property2 = { + isPrimitive: () => { + return false; + }, + getFullyQualifiedTypeName: () => { + return 'org.test.complex.file'; + } + }; + let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); mockClassDeclaration.isClassDeclaration.returns(true); - mockClassDeclaration.getProperties.returns([property1]); + mockClassDeclaration.getProperties.returns([property1, property2]); mockClassDeclaration.getNamespace.returns('org.test.collection'); mockClassDeclaration.getName.returns('folder'); @@ -401,26 +410,32 @@ describe('TypescriptVisitor', function () { { '$class': 'concerto.metamodel@1.0.0.ImportTypes', types: ['document', 'file'], - namespace:'org.test.basic', + namespace: 'org.test.basic', aliasedTypes: [ { name: 'file', aliasedName: 'f' } ] + }, + { + '$class': 'concerto.metamodel@1.0.0.ImportTypes', + types: ['file'], + namespace: 'org.test.complex', } ]; mockModelFile.getAllDeclarations.returns([mockClassDeclaration]); - mockModelFile.getImports.returns(['org.test.basic.file','org.test.basic.document']); + mockModelFile.getImports.returns(['org.test.basic.file', 'org.test.basic.document', 'org.test.complex.file']); typescriptVisitor.visitModelFile(mockModelFile,param); - param.fileWriter.writeLine.callCount.should.deep.equal(5); + param.fileWriter.writeLine.callCount.should.deep.equal(6); param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, '/* eslint-disable @typescript-eslint/no-empty-interface */']); param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, '// Generated code for namespace: org.test.collection']); param.fileWriter.writeLine.getCall(2).args.should.deep.equal([0, '\n// imports']); param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, 'import {Ifile as If} from \'./org.test.basic\';']); - param.fileWriter.writeLine.getCall(4).args.should.deep.equal([0, '\n// interfaces']); + param.fileWriter.writeLine.getCall(4).args.should.deep.equal([0, 'import {Ifile} from \'./org.test.complex\';']); + param.fileWriter.writeLine.getCall(5).args.should.deep.equal([0, '\n// interfaces']); param.fileWriter.closeFile.calledOnce.should.be.ok; }); From 4334ac135cfa4cfdec3fbbe0afc68ac85e4230c4 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Fri, 6 Sep 2024 08:46:04 +0530 Subject: [PATCH 15/17] feat(import-alias): Code refactored Signed-off-by: Jaskeerat Singh Saluja --- .../fromcto/typescript/typescriptvisitor.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/codegen/fromcto/typescript/typescriptvisitor.js b/lib/codegen/fromcto/typescript/typescriptvisitor.js index 5befdef..eb90ff4 100644 --- a/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -146,18 +146,23 @@ class TypescriptVisitor { }); - modelFile.getImports().map(importString => ModelUtil.getNamespace(importString)).filter(namespace => namespace !== modelFile.getNamespace()) // Skip own namespace. - .filter((v, i, a) => a.indexOf(v) === i) // Remove any duplicates from direct imports - .forEach(namespace => { - const propertyTypeNames = properties.get(namespace); - if (propertyTypeNames) { - const csvPropertyTypeNames = Array.from(propertyTypeNames).map(type => { - const fqnType = `${namespace}.${type}`; - return aliasedTypesMap.get(fqnType) ? `${type} as ${aliasedTypesMap.get(fqnType)}` : type; - }); - parameters.fileWriter.writeLine(0, `import {${csvPropertyTypeNames}} from './${namespace}';`); - } - }); + const uniqueNamespaces = new Set( + modelFile.getImports() + .map(importString => ModelUtil.getNamespace(importString)) + .filter(namespace => namespace !== modelFile.getNamespace()) + ); + uniqueNamespaces.forEach(namespace => { + const propertyTypeNames = properties.get(namespace); + if (propertyTypeNames) { + const csvPropertyTypeNames = Array.from(propertyTypeNames).map(type => { + const fqnType = `${namespace}.${type}`; + return aliasedTypesMap.has(fqnType) ? `${type} as ${aliasedTypesMap.get(fqnType)}` : type; + }).join(','); + + parameters.fileWriter.writeLine(0, `import {${csvPropertyTypeNames}} from './${namespace}';`); + } + }); + parameters.fileWriter.writeLine(0, '\n// interfaces'); parameters.aliasedTypesMap = aliasedTypesMap; From 782cff87bdc7f28d92277c834335deea414a0b8b Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Fri, 6 Sep 2024 15:25:03 +0530 Subject: [PATCH 16/17] feat(alias-import):Pr refactoring Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/typescript/typescriptvisitor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/codegen/fromcto/typescript/typescriptvisitor.js b/lib/codegen/fromcto/typescript/typescriptvisitor.js index eb90ff4..5ffd94d 100644 --- a/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -90,13 +90,14 @@ class TypescriptVisitor { // as well as all the super types) for all the classes in this model file parameters.fileWriter.writeLine(0, '\n// imports'); const aliasedTypesMap = new Map(); - modelFile.imports - .filter(imp => imp.$class === 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) - .forEach(imp => { + modelFile.imports.forEach((imp) => { + if (imp.$class === 'concerto.metamodel@1.0.0.ImportTypes' && imp.aliasedTypes) { imp.aliasedTypes.forEach(type => { aliasedTypesMap.set(`${imp.namespace}.I${type.name}`, `I${type.aliasedName}`); }); - }); + } + }); + const properties = new Map(); modelFile.getAllDeclarations() .filter(declaration => !declaration.isScalarDeclaration?.()) @@ -163,7 +164,6 @@ class TypescriptVisitor { } }); - parameters.fileWriter.writeLine(0, '\n// interfaces'); parameters.aliasedTypesMap = aliasedTypesMap; modelFile.getAllDeclarations() From 427d3db51d294d6e7c00fc8103eaf4ecd598f741 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Fri, 6 Sep 2024 17:22:17 +0530 Subject: [PATCH 17/17] feat(alias-import):Test cases added Signed-off-by: Jaskeerat Singh Saluja --- .../fromcto/typescript/typescriptvisitor.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/codegen/fromcto/typescript/typescriptvisitor.js b/test/codegen/fromcto/typescript/typescriptvisitor.js index 2060f90..39fe80b 100644 --- a/test/codegen/fromcto/typescript/typescriptvisitor.js +++ b/test/codegen/fromcto/typescript/typescriptvisitor.js @@ -578,6 +578,34 @@ describe('TypescriptVisitor', function () { param.fileWriter.writeLine.getCall(1).args.should.deep.equal([1, '$class: string;']); param.fileWriter.writeLine.getCall(2).args.should.deep.equal([0, '}\n']); }); + + it('should write lines for the extending class declaration using aliased types ', () => { + + let property = { + isPrimitive: () => { + return false; + }, + getFullyQualifiedTypeName: () => { + return 'org.test.basic.file'; + } + }; + + let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); + + mockClassDeclaration.isClassDeclaration.returns(true); + mockClassDeclaration.getProperties.returns([property]); + mockClassDeclaration.getNamespace.returns('org.test.collection'); + mockClassDeclaration.getName.returns('bigFile'); + mockClassDeclaration.getSuperType.returns('org.basic.file'); + mockClassDeclaration.isScalarDeclaration.returns(false); + mockClassDeclaration.getDirectSubclasses.returns([]); + mockClassDeclaration.getOwnProperties.returns([]); + param.aliasedTypesMap = new Map([['org.basic.Ifile', 'If']]); + typescriptVisitor.visitClassDeclaration(mockClassDeclaration,param); + + param.fileWriter.writeLine.callCount.should.deep.equal(2); + param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'export interface IbigFile extends If {']); + }); }); describe('visitField', () => {