зеркало из https://github.com/microsoft/ts-gyb.git
Enable renaming non-predefined types (#80)
* Enable renaming non-predefined types * fix lint Co-authored-by: Kelvin Mo <fumo@microsoft.com>
This commit is contained in:
Родитель
2c66e26bbb
Коммит
80fe719667
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ interface IHtmlApiBridge {
|
|||
fun getHTML(title: String, callback: Callback<String>)
|
||||
fun requestRenderingResult()
|
||||
fun getSize(callback: Callback<OverriddenFullSize>)
|
||||
fun getAliasSize(callback: Callback<BaseSize>)
|
||||
fun getAliasSize(callback: Callback<JSBaseSize>)
|
||||
fun testDictionaryWithAnyKey(dict: Map<String, String>)
|
||||
}
|
||||
|
||||
|
@ -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<BaseSize>) {
|
||||
executeJsForResponse(BaseSize::class.java, "getAliasSize", callback)
|
||||
override fun getAliasSize(callback: Callback<JSBaseSize>) {
|
||||
executeJsForResponse(JSBaseSize::class.java, "getAliasSize", callback)
|
||||
}
|
||||
|
||||
override fun testDictionaryWithAnyKey(dict: Map<String, String>) {
|
||||
|
@ -131,7 +131,7 @@ class DefaultEnumTypeAdapter : JsonSerializer<DefaultEnum>, JsonDeserializer<Def
|
|||
}
|
||||
}
|
||||
|
||||
data class BaseSize(
|
||||
data class JSBaseSize(
|
||||
@JvmField val width: Float,
|
||||
@JvmField val height: Float,
|
||||
)
|
||||
|
|
|
@ -157,7 +157,7 @@ export class CodeGenerator {
|
|||
private getNamedTypeView(namedType: NamedType, valueTransformer: ValueTransformer): NamedTypeView {
|
||||
let namedTypeView: NamedTypeView;
|
||||
if (isInterfaceType(namedType)) {
|
||||
namedTypeView = new InterfaceTypeView(namedType.name, namedType, valueTransformer);
|
||||
namedTypeView = new InterfaceTypeView(namedType, valueTransformer);
|
||||
namedTypeView.custom = true;
|
||||
} else {
|
||||
namedTypeView = new EnumTypeView(namedType, valueTransformer);
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
import { ValueTransformer } from './ValueTransformer';
|
||||
|
||||
export class KotlinValueTransformer implements ValueTransformer {
|
||||
constructor(private readonly predefinedTypes: Record<string, string>) {}
|
||||
constructor(private readonly typeNameMap: Record<string, string>) {}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
import { ValueTransformer } from './ValueTransformer';
|
||||
|
||||
export class SwiftValueTransformer implements ValueTransformer {
|
||||
constructor(private readonly predefinedTypes: Record<string, string>) {}
|
||||
constructor(private readonly typeNameMap: Record<string, string>) {}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<string, unknown> {
|
||||
return this.enumType.customTags;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<string, unknown> {
|
||||
return this.interfaceType.customTags;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче