diff --git a/demo/basic/config.json b/demo/basic/config.json index 405358b..ddeae97 100644 --- a/demo/basic/config.json +++ b/demo/basic/config.json @@ -33,7 +33,8 @@ "namedTypesTemplatePath": "../../example-templates/kotlin-named-types.mustache", "namedTypesOutputPath": "generated/kotlin/BridgeTypes.kt", "typeNameMap": { - "CodeGen_Int": "Int" + "CodeGen_Int": "Int", + "BaseSize": "JSBaseSize" } } } diff --git a/demo/basic/generated/kotlin/IHtmlApi.kt b/demo/basic/generated/kotlin/IHtmlApi.kt index 2141c39..72efcf1 100644 --- a/demo/basic/generated/kotlin/IHtmlApi.kt +++ b/demo/basic/generated/kotlin/IHtmlApi.kt @@ -29,7 +29,7 @@ interface IHtmlApiBridge { fun getHTML(title: String, callback: Callback) fun requestRenderingResult() fun getSize(callback: Callback) - fun getAliasSize(callback: Callback) + fun getAliasSize(callback: Callback) fun testDictionaryWithAnyKey(dict: Map) } @@ -65,8 +65,8 @@ open class IHtmlApiBridge(editor: WebEditor, gson: Gson) : JsBridge(editor, gson executeJsForResponse(OverriddenFullSize::class.java, "getSize", callback) } - override fun getAliasSize(callback: Callback) { - executeJsForResponse(BaseSize::class.java, "getAliasSize", callback) + override fun getAliasSize(callback: Callback) { + executeJsForResponse(JSBaseSize::class.java, "getAliasSize", callback) } override fun testDictionaryWithAnyKey(dict: Map) { @@ -131,7 +131,7 @@ class DefaultEnumTypeAdapter : JsonSerializer, JsonDeserializer) {} + constructor(private readonly typeNameMap: Record) {} convertValueType(valueType: ValueType): string { if (isBasicType(valueType)) { @@ -31,11 +31,11 @@ export class KotlinValueTransformer implements ValueTransformer { } if (isInterfaceType(valueType)) { - return valueType.name; + return this.convertTypeNameFromCustomMap(valueType.name); } if (isEnumType(valueType)) { - return valueType.name; + return this.convertTypeNameFromCustomMap(valueType.name); } if (isArraryType(valueType)) { @@ -63,7 +63,7 @@ export class KotlinValueTransformer implements ValueTransformer { } if (isPredefinedType(valueType)) { - return this.predefinedTypes[valueType.name] ?? valueType.name; + return this.typeNameMap[valueType.name] ?? valueType.name; } throw Error('Type not handled'); @@ -125,4 +125,8 @@ export class KotlinValueTransformer implements ValueTransformer { .replace(/^_/, '') .toUpperCase(); } + + convertTypeNameFromCustomMap(name: string): string { + return this.typeNameMap[name] ?? name; + } } diff --git a/src/renderer/value-transformer/SwiftValueTransformer.ts b/src/renderer/value-transformer/SwiftValueTransformer.ts index 81e94dd..05730b8 100644 --- a/src/renderer/value-transformer/SwiftValueTransformer.ts +++ b/src/renderer/value-transformer/SwiftValueTransformer.ts @@ -14,7 +14,7 @@ import { import { ValueTransformer } from './ValueTransformer'; export class SwiftValueTransformer implements ValueTransformer { - constructor(private readonly predefinedTypes: Record) {} + constructor(private readonly typeNameMap: Record) {} convertValueType(valueType: ValueType): string { if (isBasicType(valueType)) { @@ -31,11 +31,11 @@ export class SwiftValueTransformer implements ValueTransformer { } if (isInterfaceType(valueType)) { - return valueType.name; + return this.convertTypeNameFromCustomMap(valueType.name); } if (isEnumType(valueType)) { - return valueType.name; + return this.convertTypeNameFromCustomMap(valueType.name); } if (isArraryType(valueType)) { @@ -63,7 +63,7 @@ export class SwiftValueTransformer implements ValueTransformer { } if (isPredefinedType(valueType)) { - return this.predefinedTypes[valueType.name] ?? valueType.name; + return this.typeNameMap[valueType.name] ?? valueType.name; } throw Error('Type not handled'); @@ -140,4 +140,9 @@ export class SwiftValueTransformer implements ValueTransformer { return text.slice(0, index).toLowerCase() + text.slice(index); } + + convertTypeNameFromCustomMap(name: string): string { + return this.typeNameMap[name] ?? name; + } + } diff --git a/src/renderer/value-transformer/ValueTransformer.ts b/src/renderer/value-transformer/ValueTransformer.ts index 79f789f..6ced0b6 100644 --- a/src/renderer/value-transformer/ValueTransformer.ts +++ b/src/renderer/value-transformer/ValueTransformer.ts @@ -5,4 +5,5 @@ export interface ValueTransformer { convertNonOptionalValueType(valueType: ValueType): string; convertValue(value: Value, type: ValueType): string; convertEnumKey(text: string): string; + convertTypeNameFromCustomMap(name: string): string; } diff --git a/src/renderer/views/EnumTypeView.ts b/src/renderer/views/EnumTypeView.ts index ff55284..4b41cb3 100644 --- a/src/renderer/views/EnumTypeView.ts +++ b/src/renderer/views/EnumTypeView.ts @@ -6,7 +6,7 @@ export class EnumTypeView { constructor(private enumType: EnumType, private valueTransformer: ValueTransformer) {} get typeName(): string { - return this.enumType.name; + return this.valueTransformer.convertTypeNameFromCustomMap(this.enumType.name); } get valueType(): string { @@ -42,4 +42,8 @@ export class EnumTypeView { get documentationLines(): string[] { return getDocumentationLines(this.enumType.documentation); } + + get customTags(): Record { + return this.enumType.customTags; + } } diff --git a/src/renderer/views/InterfaceTypeView.ts b/src/renderer/views/InterfaceTypeView.ts index 0e7133d..3c92633 100644 --- a/src/renderer/views/InterfaceTypeView.ts +++ b/src/renderer/views/InterfaceTypeView.ts @@ -4,11 +4,14 @@ import { ValueTransformer } from '../value-transformer'; export class InterfaceTypeView { constructor( - readonly typeName: string, private readonly interfaceType: InterfaceType, private readonly valueTransformer: ValueTransformer ) {} + get typeName(): string { + return this.valueTransformer.convertValueType(this.interfaceType); + } + get members(): { name: string; type: string; documentationLines: string[]; last: boolean }[] { const members = this.interfaceType.members.filter((member) => member.staticValue === undefined); @@ -40,4 +43,8 @@ export class InterfaceTypeView { get documentationLines(): string[] { return getDocumentationLines(this.interfaceType.documentation); } + + get customTags(): Record { + return this.interfaceType.customTags; + } }