From 38993f6a5f323858233be62b64ab966f2f170418 Mon Sep 17 00:00:00 2001 From: Subhajit Ghosh Date: Sun, 31 Mar 2024 10:44:55 +0530 Subject: [PATCH 1/4] Added toString method to enumdeclaration in javavisior Signed-off-by: Subhajit Ghosh --- lib/codegen/fromcto/java/javavisitor.js | 5 ++++ test/codegen/__snapshots__/codegen.js.snap | 32 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index a3f296cf..98f99682 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -145,6 +145,11 @@ class JavaVisitor { property.accept(this, parameters); }); + parameters.fileWriter.writeLine(0, '@Override'); + parameters.fileWriter.writeLine(0, 'public String toString() {'); + parameters.fileWriter.writeLine(0, `return name();`); + parameters.fileWriter.writeLine(0, '}'); + parameters.fileWriter.writeLine(0, '}' ); this.endClassFile(enumDeclaration, parameters); diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index 91be777d..d070bc81 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -973,6 +973,10 @@ public enum State { WA, IL, CA, +@Override +public String toString() { +return name(); +} } ", } @@ -990,6 +994,10 @@ public enum TShirtSizeType { SMALL, MEDIUM, LARGE, +@Override +public String toString() { +return name(); +} } ", } @@ -1141,6 +1149,10 @@ public enum Department { HR, Engineering, Design, +@Override +public String toString() { +return name(); +} } ", } @@ -1196,6 +1208,10 @@ import com.fasterxml.jackson.annotation.*; public enum LaptopMake { Apple, Microsoft, +@Override +public String toString() { +return name(); +} } ", } @@ -7091,6 +7107,10 @@ public enum State { WA, IL, CA, +@Override +public String toString() { +return name(); +} } ", } @@ -7108,6 +7128,10 @@ public enum TShirtSizeType { SMALL, MEDIUM, LARGE, +@Override +public String toString() { +return name(); +} } ", } @@ -7259,6 +7283,10 @@ public enum Department { HR, Engineering, Design, +@Override +public String toString() { +return name(); +} } ", } @@ -7314,6 +7342,10 @@ import com.fasterxml.jackson.annotation.*; public enum LaptopMake { Apple, Microsoft, +@Override +public String toString() { +return name(); +} } ", } From 991afa087c03c71bfe6cdc16f72b0d19accf8124 Mon Sep 17 00:00:00 2001 From: Subhajit Ghosh Date: Sun, 31 Mar 2024 10:54:02 +0530 Subject: [PATCH 2/4] Added minor changes Signed-off-by: Subhajit Ghosh --- lib/codegen/fromcto/java/javavisitor.js | 8 +-- test/codegen/__snapshots__/codegen.js.snap | 64 +++++++++++----------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index 98f99682..6d4f279d 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -145,10 +145,10 @@ class JavaVisitor { property.accept(this, parameters); }); - parameters.fileWriter.writeLine(0, '@Override'); - parameters.fileWriter.writeLine(0, 'public String toString() {'); - parameters.fileWriter.writeLine(0, `return name();`); - parameters.fileWriter.writeLine(0, '}'); + parameters.fileWriter.writeLine(1, '@Override'); + parameters.fileWriter.writeLine(1, 'public String toString() {'); + parameters.fileWriter.writeLine(1, 'return name();'); + parameters.fileWriter.writeLine(1, '}'); parameters.fileWriter.writeLine(0, '}' ); diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index d070bc81..ab6e4e8d 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -973,10 +973,10 @@ public enum State { WA, IL, CA, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -994,10 +994,10 @@ public enum TShirtSizeType { SMALL, MEDIUM, LARGE, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -1149,10 +1149,10 @@ public enum Department { HR, Engineering, Design, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -1208,10 +1208,10 @@ import com.fasterxml.jackson.annotation.*; public enum LaptopMake { Apple, Microsoft, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -7107,10 +7107,10 @@ public enum State { WA, IL, CA, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -7128,10 +7128,10 @@ public enum TShirtSizeType { SMALL, MEDIUM, LARGE, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -7283,10 +7283,10 @@ public enum Department { HR, Engineering, Design, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } @@ -7342,10 +7342,10 @@ import com.fasterxml.jackson.annotation.*; public enum LaptopMake { Apple, Microsoft, -@Override -public String toString() { -return name(); -} + @Override + public String toString() { + return name(); + } } ", } From 4a8bc8aade1bf2638a5b9b1def90dad14355285a Mon Sep 17 00:00:00 2001 From: Subhajit Ghosh Date: Sun, 31 Mar 2024 10:58:18 +0530 Subject: [PATCH 3/4] Added some space to the return statement Signed-off-by: Subhajit Ghosh --- lib/codegen/fromcto/java/javavisitor.js | 2 +- test/codegen/__snapshots__/codegen.js.snap | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/codegen/fromcto/java/javavisitor.js b/lib/codegen/fromcto/java/javavisitor.js index 6d4f279d..a7fb0d31 100644 --- a/lib/codegen/fromcto/java/javavisitor.js +++ b/lib/codegen/fromcto/java/javavisitor.js @@ -147,7 +147,7 @@ class JavaVisitor { parameters.fileWriter.writeLine(1, '@Override'); parameters.fileWriter.writeLine(1, 'public String toString() {'); - parameters.fileWriter.writeLine(1, 'return name();'); + parameters.fileWriter.writeLine(2, 'return name();'); parameters.fileWriter.writeLine(1, '}'); parameters.fileWriter.writeLine(0, '}' ); diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index ab6e4e8d..abb8a388 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -975,7 +975,7 @@ public enum State { CA, @Override public String toString() { - return name(); + return name(); } } ", @@ -996,7 +996,7 @@ public enum TShirtSizeType { LARGE, @Override public String toString() { - return name(); + return name(); } } ", @@ -1151,7 +1151,7 @@ public enum Department { Design, @Override public String toString() { - return name(); + return name(); } } ", @@ -1210,7 +1210,7 @@ public enum LaptopMake { Microsoft, @Override public String toString() { - return name(); + return name(); } } ", @@ -7109,7 +7109,7 @@ public enum State { CA, @Override public String toString() { - return name(); + return name(); } } ", @@ -7130,7 +7130,7 @@ public enum TShirtSizeType { LARGE, @Override public String toString() { - return name(); + return name(); } } ", @@ -7285,7 +7285,7 @@ public enum Department { Design, @Override public String toString() { - return name(); + return name(); } } ", @@ -7344,7 +7344,7 @@ public enum LaptopMake { Microsoft, @Override public String toString() { - return name(); + return name(); } } ", From 7c14d706387e371d22c36ccdb17fda08b4a2f1e7 Mon Sep 17 00:00:00 2001 From: Subhajit Ghosh Date: Sun, 31 Mar 2024 11:26:43 +0530 Subject: [PATCH 4/4] Added test Signed-off-by: Subhajit Ghosh --- test/codegen/fromcto/java/javavisitor.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/codegen/fromcto/java/javavisitor.js b/test/codegen/fromcto/java/javavisitor.js index 7ed6f004..f0d4d010 100644 --- a/test/codegen/fromcto/java/javavisitor.js +++ b/test/codegen/fromcto/java/javavisitor.js @@ -243,11 +243,16 @@ describe('JavaVisitor', function () { javaVisit.visitEnumDeclaration(mockEnumDeclaration, param); mockStartClassFile.withArgs(mockEnumDeclaration, param).calledOnce.should.be.ok; - param.fileWriter.writeLine.callCount.should.deep.equal(4); + param.fileWriter.writeLine.callCount.should.deep.equal(8); + param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'import com.fasterxml.jackson.annotation.*;']); param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, '@JsonIgnoreProperties({"$class"})']); param.fileWriter.writeLine.getCall(2).args.should.deep.equal([0, 'public enum Bob {']); - param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, '}']); + param.fileWriter.writeLine.getCall(3).args.should.deep.equal([1, '@Override']); + param.fileWriter.writeLine.getCall(4).args.should.deep.equal([1, 'public String toString() {']); + param.fileWriter.writeLine.getCall(5).args.should.deep.equal([2, 'return name();']); + param.fileWriter.writeLine.getCall(6).args.should.deep.equal([1, '}']); + param.fileWriter.writeLine.getCall(7).args.should.deep.equal([0, '}']); mockEndClassFile.withArgs(mockEnumDeclaration, param).calledOnce.should.be.ok; }); });