Skip to content

Commit

Permalink
Use Seskar annotations for native setters/getters/invokes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrishchenko committed Dec 13, 2023
1 parent c5c0cab commit bca554e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 109 deletions.
3 changes: 1 addition & 2 deletions src/converter/plugins/convertCallSignatureDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const convertCallSignatureDeclaration = createSimplePlugin((node, context
const inheritanceModifier = inheritanceModifierService?.resolveSignatureInheritanceModifier(node, signature, context)

return `
@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
${ifPresent(inheritanceModifier, it => `${it} `)}operator fun ${ifPresent(typeParameters, it => `<${it}>`)} invoke(${parameters})${ifPresent(returnType, it => `: ${it}`)}
`
}
Expand Down
12 changes: 2 additions & 10 deletions src/converter/plugins/convertIndexedSignatureDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,15 @@ export const convertIndexedSignatureDeclaration = createSimplePlugin((node, cont
const type = renderNullable(node.type, true, context, render)

const getter = `
@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
${ifPresent(inheritanceModifier, it => `${it} `)}operator fun get(key: ${keyType}): ${type}
`

let setter = ""

if (!readonly) {
setter = `
@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
${ifPresent(inheritanceModifier, it => `${it} `)}operator fun set(key: ${keyType}, value: ${type})
`
}
Expand Down
12 changes: 2 additions & 10 deletions src/converter/plugins/convertMappedType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,15 @@ export const convertMappedType = createSimplePlugin((node, context, render) => {
}

const getter = `
@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
${ifPresent(inheritanceModifier, it => `${it} `)}operator fun <${typeParameter}> get(key: ${keyType}): ${type}
`

let setter = ""

if (!readonly) {
setter = `
@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
${ifPresent(inheritanceModifier, it => `${it} `)}operator fun <${typeParameter}> set(key: ${keyType}, value: ${type})
`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ package sandbox.base.declarationMerging

external class ExampleClass {

@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
operator fun invoke(param: String): Unit

var a: Double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ package sandbox.base.declarationMerging

external interface Example {

@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
operator fun invoke(param1: String): Unit

var a: Double
Expand Down
42 changes: 7 additions & 35 deletions test/functional/base/generated/indexSignature/simple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,12 @@ package sandbox.base.indexSignature
external interface RouteData {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun get(key: String): Any?



@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
operator fun set(key: String, value: Any?)


Expand All @@ -37,11 +29,7 @@ operator fun set(key: String, value: Any?)
external interface ReadonlyRouteData {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun get(key: String): Any?


Expand All @@ -52,20 +40,12 @@ operator fun get(key: String): Any?
external interface SomeData {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun get(key: js.core.Symbol): Double?



@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
operator fun set(key: js.core.Symbol, value: Double?)


Expand All @@ -77,20 +57,12 @@ external interface IntersectionSomeData {
var x: String


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun get(key: js.core.Symbol): Double?



@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
operator fun set(key: js.core.Symbol, value: Double?)


Expand Down
48 changes: 8 additions & 40 deletions test/functional/base/generated/mappedType/simple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ val two: Keys
external interface OptionsFlags {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun <Property : Keys> get(key: Property): Promise<Property>?



@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
operator fun <Property : Keys> set(key: Property, value: Promise<Property>?)


Expand All @@ -51,11 +43,7 @@ operator fun <Property : Keys> set(key: Property, value: Promise<Property>?)
external interface ReadonlyOptionsFlags {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun <Property : Keys> get(key: Property): Promise<Property>?


Expand All @@ -66,20 +54,12 @@ operator fun <Property : Keys> get(key: Property): Promise<Property>?
external interface OptionsFlagsWithTypeLiteral {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun <Property : Keys> get(key: Property): Promise<Property>?



@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
operator fun <Property : Keys> set(key: Property, value: Promise<Property>?)


Expand All @@ -97,20 +77,12 @@ var key: T
external interface NamedOptionsFlags {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun <Property : Keys> get(key: KeyWrapper<Property>): Promise<Property>?



@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeSetter
@seskar.js.JsNative
operator fun <Property : Keys> set(key: KeyWrapper<Property>, value: Promise<Property>?)


Expand All @@ -121,11 +93,7 @@ operator fun <Property : Keys> set(key: KeyWrapper<Property>, value: Promise<Pro
external interface OptionalOptionsFlags {


@Suppress(
"DEPRECATION",
"NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER",
)
@nativeGetter
@seskar.js.JsNative
operator fun <Property : Keys> get(key: KeyWrapper<Property>): Promise<Property>?


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ fun method(options: MyInterfaceMethodOptions): String

external interface ShouldRevalidateFunction {

@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
operator fun invoke(args: ShouldRevalidateFunctionArgs): Boolean

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ fun getDerivedStateFromProps(): MyInterfaceGetDerivedStateFromPropsResult

external interface MapRoutePropertiesFunction {

@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
operator fun invoke(route: MapRoutePropertiesFunctionRoute): MapRoutePropertiesFunctionResult

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package `package`.namespace

external interface TestInterfaceTestFn {

@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
operator fun invoke(param: String): String


@Suppress("DEPRECATION")
@nativeInvoke
@seskar.js.JsNative
operator fun invoke(param: Double): String

}

0 comments on commit bca554e

Please sign in to comment.