Comparing version 1.4.9 to 1.4.10
@@ -13,2 +13,3 @@ "use strict"; | ||
constructor(name) { | ||
this.annotations = []; | ||
this.klassType = "class"; | ||
@@ -31,4 +32,5 @@ this.modifiers = []; | ||
} | ||
setAnnotation(annotation) { | ||
this.annotation = annotation; | ||
addAnnotation(...annotation) { | ||
this.annotations.push(...annotation); | ||
this.annotations = lodash_1.default.uniq(this.annotations); | ||
return this; | ||
@@ -35,0 +37,0 @@ } |
@@ -7,3 +7,3 @@ "use strict"; | ||
print(klass, indent = 0, options) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f; | ||
if (typeof klass === "string") | ||
@@ -23,6 +23,8 @@ return klass; | ||
// Annotation | ||
if ((_a = klass.annotation) === null || _a === void 0 ? void 0 : _a.length) { | ||
this.indent(indent, result); | ||
result.push(klass.annotation); | ||
result.push("\n"); | ||
for (const annotation of klass.annotations) { | ||
if (annotation.length) { | ||
this.indent(indent, result); | ||
result.push(annotation); | ||
result.push("\n"); | ||
} | ||
} | ||
@@ -35,3 +37,3 @@ // Class declaration | ||
result.push(`${klass.klassType}`); | ||
if ((_b = klass.name) === null || _b === void 0 ? void 0 : _b.length) | ||
if ((_a = klass.name) === null || _a === void 0 ? void 0 : _a.length) | ||
result.push(` ${klass.name}`); | ||
@@ -51,3 +53,3 @@ // Primary Constructor | ||
result.push(` : ${klass.extends.name}`); | ||
result.push(`(${(_e = (_d = (_c = klass.extends) === null || _c === void 0 ? void 0 : _c.args) === null || _d === void 0 ? void 0 : _d.map((value) => value.name).join(", ")) !== null && _e !== void 0 ? _e : ""})`); | ||
result.push(`(${(_d = (_c = (_b = klass.extends) === null || _b === void 0 ? void 0 : _b.args) === null || _c === void 0 ? void 0 : _c.map((value) => value.name).join(", ")) !== null && _d !== void 0 ? _d : ""})`); | ||
} | ||
@@ -70,3 +72,3 @@ if (klass.implements.length) { | ||
indent++; | ||
if ((_f = klass.enumValues) === null || _f === void 0 ? void 0 : _f.length) { | ||
if ((_e = klass.enumValues) === null || _e === void 0 ? void 0 : _e.length) { | ||
this.push(result, klass.enumValues.map((value) => { | ||
@@ -82,3 +84,3 @@ var _a; | ||
} | ||
if ((_g = klass.members) === null || _g === void 0 ? void 0 : _g.length) { | ||
if ((_f = klass.members) === null || _f === void 0 ? void 0 : _f.length) { | ||
this.push(result, klass.members.map((value) => this.printParameter(value, "val", options)), indent, "\n"); | ||
@@ -138,10 +140,12 @@ result.push("\n"); | ||
} | ||
if ((_a = param.annotation) === null || _a === void 0 ? void 0 : _a.length) { | ||
result.push(`${param.annotation}`); | ||
if ((options === null || options === void 0 ? void 0 : options.annotationNewLines) || param.annotation.length > 32) { | ||
result.push("\n"); | ||
for (const annotation of (_a = param.annotations) !== null && _a !== void 0 ? _a : []) { | ||
if (annotation === null || annotation === void 0 ? void 0 : annotation.length) { | ||
result.push(`${annotation}`); | ||
if ((options === null || options === void 0 ? void 0 : options.annotationNewLines) || annotation.length > 32) { | ||
result.push("\n"); | ||
} | ||
else { | ||
result.push(" "); | ||
} | ||
} | ||
else { | ||
result.push(" "); | ||
} | ||
} | ||
@@ -148,0 +152,0 @@ if (param.abstract) { |
@@ -87,3 +87,3 @@ "use strict"; | ||
const result = new Klass(name) | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.addInnerClasses(...this.generateInnerKlasses(members)); | ||
@@ -118,2 +118,3 @@ if (members.length) { | ||
const name = node.name.getText(); | ||
const annotations = []; | ||
let type = (0, MemberHelpers_1.getMemberType)(this.martok, node, { | ||
@@ -128,3 +129,2 @@ followReferences: (_a = options === null || options === void 0 ? void 0 : options.followReferences) !== null && _a !== void 0 ? _a : false, | ||
} | ||
let annotation; | ||
const doc = (0, typescript_1.getJSDocTags)(node); | ||
@@ -136,4 +136,3 @@ const forceDateTime = type === "String" && | ||
type = "kotlinx.datetime.Instant"; | ||
annotation = | ||
"@Serializable(with = kotlinx.datetime.serializers.InstantIso8601Serializer::class)"; | ||
annotations.push("@Serializable(with = kotlinx.datetime.serializers.InstantIso8601Serializer::class)"); | ||
} | ||
@@ -149,3 +148,3 @@ const nullable = (options === null || options === void 0 ? void 0 : options.optional) || !!node.questionToken; | ||
type, | ||
annotation, | ||
annotations, | ||
mutability: "val", | ||
@@ -152,0 +151,0 @@ nullable, |
@@ -17,3 +17,3 @@ "use strict"; | ||
.addGeneratorTypes("ordinal-enum") | ||
.setAnnotation(`@Serializable(with = ${name}.Companion::class)`) | ||
.addAnnotation(`@Serializable(with = ${name}.Companion::class)`) | ||
.addModifier("enum") | ||
@@ -20,0 +20,0 @@ .addCtorArgs({ |
@@ -16,3 +16,3 @@ "use strict"; | ||
.addGeneratorTypes("string-enum") | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.addModifier("enum") | ||
@@ -19,0 +19,0 @@ .addCtorArgs({ |
@@ -48,3 +48,3 @@ "use strict"; | ||
.addGeneratorTypes("tagged") | ||
.setAnnotation(`@Serializable(with = ${name}.UnionSerializer::class)`) | ||
.addAnnotation(`@Serializable(with = ${name}.UnionSerializer::class)`) | ||
.addModifier("sealed") | ||
@@ -129,3 +129,3 @@ .addMembers(...members.map((value) => { | ||
.addModifier("enum") | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.setCtorArgs({ name: "serialName", type: "String", mutability: "val" }) | ||
@@ -132,0 +132,0 @@ .setEnumValues(...enums); |
@@ -21,6 +21,8 @@ "use strict"; | ||
function processKlass(klass) { | ||
var _a; | ||
for (const member of [...klass.members, ...klass.ctor]) { | ||
if (member.oldName && member.name !== member.oldName) { | ||
const name = member.oldName.replace(/"/g, ""); | ||
member.annotation = `@SerialName("${name}")`; | ||
member.annotations = (_a = member.annotations) !== null && _a !== void 0 ? _a : []; | ||
member.annotations.push(`@SerialName("${name}")`); | ||
} | ||
@@ -27,0 +29,0 @@ } |
@@ -25,3 +25,3 @@ "use strict"; | ||
const k = new Klass("Foob") | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.addCtorArgs({ | ||
@@ -42,3 +42,3 @@ name: "foo", | ||
}) | ||
.addInnerClasses(new Klass("Barb").setAnnotation("@Serializable").addCtorArgs({ | ||
.addInnerClasses(new Klass("Barb").addAnnotation("@Serializable").addCtorArgs({ | ||
name: "whatever", | ||
@@ -45,0 +45,0 @@ type: "Hi", |
{ | ||
"name": "martok", | ||
"version": "1.4.9", | ||
"version": "1.4.10", | ||
"description": "", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"special": "ts-node src/index.ts tests/comparisons/special/DateTime.d.ts -a -s -t -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"special": "ts-node src/index.ts tests/comparisons/special/DateTime.d.ts -s -t -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"lint": "eslint . --ext .ts" | ||
@@ -15,0 +15,0 @@ }, |
@@ -39,3 +39,3 @@ import _ from "lodash"; | ||
mutability?: Mutability; | ||
annotation?: string; | ||
annotations?: string[]; | ||
abstract?: boolean; | ||
@@ -71,3 +71,3 @@ comment?: Komment; | ||
public annotation: string | undefined; | ||
public annotations: string[] = []; | ||
public klassType: KlassType = "class"; | ||
@@ -102,4 +102,5 @@ public modifiers: KlassModifier[] = []; | ||
public setAnnotation(annotation: string | undefined): this { | ||
this.annotation = annotation; | ||
public addAnnotation(...annotation: string[]): this { | ||
this.annotations.push(...annotation); | ||
this.annotations = _.uniq(this.annotations); | ||
return this; | ||
@@ -106,0 +107,0 @@ } |
@@ -31,6 +31,8 @@ import { kotlin } from "./Klass"; | ||
// Annotation | ||
if (klass.annotation?.length) { | ||
this.indent(indent, result); | ||
result.push(klass.annotation); | ||
result.push("\n"); | ||
for (const annotation of klass.annotations) { | ||
if (annotation.length) { | ||
this.indent(indent, result); | ||
result.push(annotation); | ||
result.push("\n"); | ||
} | ||
} | ||
@@ -178,8 +180,10 @@ | ||
} | ||
if (param.annotation?.length) { | ||
result.push(`${param.annotation}`); | ||
if (options?.annotationNewLines || param.annotation.length > 32) { | ||
result.push("\n"); | ||
} else { | ||
result.push(" "); | ||
for (const annotation of param.annotations ?? []) { | ||
if (annotation?.length) { | ||
result.push(`${annotation}`); | ||
if (options?.annotationNewLines || annotation.length > 32) { | ||
result.push("\n"); | ||
} else { | ||
result.push(" "); | ||
} | ||
} | ||
@@ -186,0 +190,0 @@ } |
@@ -142,3 +142,3 @@ import { Martok } from "../Martok"; | ||
const result = new Klass(name) | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.addInnerClasses(...this.generateInnerKlasses(members)); | ||
@@ -190,2 +190,3 @@ if (members.length) { | ||
const name = node.name!.getText(); | ||
const annotations: string[] = []; | ||
let type = getMemberType(this.martok, node, { | ||
@@ -199,3 +200,2 @@ followReferences: options?.followReferences ?? false, | ||
} | ||
let annotation: string | undefined; | ||
const doc = getJSDocTags(node); | ||
@@ -210,4 +210,5 @@ const forceDateTime = | ||
type = "kotlinx.datetime.Instant"; | ||
annotation = | ||
"@Serializable(with = kotlinx.datetime.serializers.InstantIso8601Serializer::class)"; | ||
annotations.push( | ||
"@Serializable(with = kotlinx.datetime.serializers.InstantIso8601Serializer::class)" | ||
); | ||
} | ||
@@ -224,3 +225,3 @@ const nullable = options?.optional || !!node.questionToken; | ||
type, | ||
annotation, | ||
annotations, | ||
mutability: "val", | ||
@@ -227,0 +228,0 @@ nullable, |
@@ -17,3 +17,3 @@ import { Martok } from "../Martok"; | ||
.addGeneratorTypes("ordinal-enum") | ||
.setAnnotation(`@Serializable(with = ${name}.Companion::class)`) | ||
.addAnnotation(`@Serializable(with = ${name}.Companion::class)`) | ||
.addModifier("enum") | ||
@@ -20,0 +20,0 @@ .addCtorArgs({ |
@@ -16,3 +16,3 @@ import { Martok } from "../Martok"; | ||
.addGeneratorTypes("string-enum") | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.addModifier("enum") | ||
@@ -19,0 +19,0 @@ .addCtorArgs({ |
@@ -70,3 +70,3 @@ import { Martok } from "../Martok"; | ||
.addGeneratorTypes("tagged") | ||
.setAnnotation(`@Serializable(with = ${name}.UnionSerializer::class)`) | ||
.addAnnotation(`@Serializable(with = ${name}.UnionSerializer::class)`) | ||
.addModifier("sealed") | ||
@@ -155,3 +155,3 @@ .addMembers( | ||
.addModifier("enum") | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.setCtorArgs({ name: "serialName", type: "String", mutability: "val" }) | ||
@@ -158,0 +158,0 @@ .setEnumValues(...enums); |
@@ -23,3 +23,4 @@ import { kotlin } from "../../kotlin/Klass"; | ||
const name = member.oldName.replace(/"/g, ""); | ||
member.annotation = `@SerialName("${name}")`; | ||
member.annotations = member.annotations ?? []; | ||
member.annotations.push(`@SerialName("${name}")`); | ||
} | ||
@@ -26,0 +27,0 @@ } |
@@ -25,3 +25,3 @@ import { kotlin } from "../../kotlin/Klass"; | ||
const k = new Klass("Foob") | ||
.setAnnotation("@Serializable") | ||
.addAnnotation("@Serializable") | ||
.addCtorArgs({ | ||
@@ -43,3 +43,3 @@ name: "foo", | ||
.addInnerClasses( | ||
new Klass("Barb").setAnnotation("@Serializable").addCtorArgs({ | ||
new Klass("Barb").addAnnotation("@Serializable").addCtorArgs({ | ||
name: "whatever", | ||
@@ -46,0 +46,0 @@ type: "Hi", |
@@ -5,3 +5,3 @@ export type WithDates = { | ||
*/ | ||
useDecorators: string; | ||
use_decorators: string; | ||
@@ -8,0 +8,0 @@ utcDate1: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
284134
4932