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/10] 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 fefab2c1..fcdb6b99 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/10] 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 fcdb6b99..a33c4950 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/10] 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 a33c4950..37d6456d 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 1e9640e6..7ae4cf0d 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/10] 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 37d6456d..0590f538 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 a3f296cf..182506cc 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/10] 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 0590f538..293f06c6 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 182506cc..7822d08b 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 7ae4cf0d..01c475e5 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/10] 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 7ed6f004..3389fc51 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/10] 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 8766e930..c3112c40 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 ef6bcdff..6650b194 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 b80204d2..2aaf4c9e 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 3389fc51..557eab24 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/10] 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 293f06c6..6b8c9706 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 7822d08b..bffc386e 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/10] 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 6b8c9706..e7ac7a7b 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 bffc386e..7a6b838d 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 557eab24..375ab986 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 9537e59d1c0cb679ff979bd58d1b07f65c7542d8 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja Date: Tue, 3 Sep 2024 20:46:42 +0530 Subject: [PATCH 10/10] feat(alias-import): visitField() updated Signed-off-by: Jaskeerat Singh Saluja --- lib/codegen/fromcto/rust/rustvisitor.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/codegen/fromcto/rust/rustvisitor.js b/lib/codegen/fromcto/rust/rustvisitor.js index cad313ee..eabfca70 100644 --- a/lib/codegen/fromcto/rust/rustvisitor.js +++ b/lib/codegen/fromcto/rust/rustvisitor.js @@ -211,7 +211,16 @@ class RustVisitor { * @private */ visitField(field, parameters) { - let type = this.toRustType(field.type); + let type = field.type; + if (!ModelUtil.isPrimitiveType(field.type)) { + const modelFile = field.getModelFile(); + if (modelFile?.isImportedType(type)) { + type = modelFile.getImportedType(type); + } + console.log(type); + } + type = this.toRustType(type); + if (field.isArray?.()) { type = `Vec<${type}>`; }