Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit d449148

Browse files
Gregory Lureauglureau
authored andcommitted
Change the annotation retention to BINARY to fix multimodules issues.
1 parent 3e6c3aa commit d449148

File tree

7 files changed

+53
-24
lines changed

7 files changed

+53
-24
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ plugins {
2424

2525
allprojects {
2626
group = "deezer.kustomexport"
27-
version = "0.5.0"
27+
version = "0.6.0"
2828

2929
repositories {
3030
mavenLocal()

compiler/src/main/kotlin/deezer/kustomexport/compiler/js/mapping/TypeMapping.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import com.squareup.kotlinpoet.TypeName
2727
import com.squareup.kotlinpoet.TypeVariableName
2828
import com.squareup.kotlinpoet.ksp.KotlinPoetKspPreview
2929
import deezer.kustomexport.compiler.GenericsVisitor
30-
import deezer.kustomexport.compiler.Logger
3130
import deezer.kustomexport.compiler.js.FormatString
3231
import deezer.kustomexport.compiler.js.TypeParameterDescriptor
3332
import deezer.kustomexport.compiler.js.jsPackage
@@ -42,7 +41,7 @@ import deezer.kustomexport.compiler.js.toFormatString
4241
class OriginTypeName(
4342
private val originTypeName: TypeName,
4443
private val concreteTypeParameters: List<TypeParameterDescriptor>,
45-
val isKustomExportAnnotated: Boolean,
44+
val isKustomExportAnnotated: Boolean,
4645
private val typeArgs: List<OriginTypeName>,
4746
) {
4847
val concreteTypeName: TypeName by lazy { originTypeName.resolvedType(concreteTypeParameters) }

compiler/src/main/kotlin/deezer/kustomexport/compiler/js/pattern/ClassDeclarationParser.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ fun parseClass(
8888

8989
val superTypes = classDeclaration.superTypes
9090
.mapNotNull { superType ->
91+
val typeName = superType.toTypeNamePatch(typeParamResolver)
9192
// KSP 1.6.20-1.0.5 now returns kotlin.Any even if we're parsing an interface.
9293
// That doesn't make sense for us, so we're just ignoring them
9394
// https://github.com/google/ksp/issues/815#issuecomment-1105676539
94-
val typeName = superType.toTypeNamePatch(typeParamResolver)
9595
if (typeName == ANY) return@mapNotNull null
9696
// End of trick
9797

98-
9998
val isKustomExportAnnotated = superType.isKustomExportAnnotated()
10099
val superTypeName = typeName.cached(concreteTypeParameters, isKustomExportAnnotated)
101100

@@ -273,13 +272,6 @@ private fun KSFunctionDeclaration.toDescriptor(
273272
val typeResolved = p.type.resolve()
274273

275274
val typeArgs = typeResolved.arguments.map {
276-
// Just logging here
277-
it.type?.let { t ->
278-
t.resolve().declaration.annotations.forEach { a ->
279-
val ksDeclaration = a.annotationType.resolve().declaration
280-
}
281-
}
282-
283275
it.toTypeName(typeParamResolver)
284276
.cached(concreteTypeParameters, it.type?.isKustomExportAnnotated() ?: false)
285277
}

lib/src/commonMain/kotlin/deezer/kustomexport/KustomExport.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package deezer.kustomexport
1919

2020
import kotlin.reflect.KClass
2121

22-
@Retention(AnnotationRetention.SOURCE)
22+
@Retention(AnnotationRetention.BINARY)
2323
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION)
2424
public annotation class KustomExport(
2525
/**
@@ -36,13 +36,14 @@ public annotation class KustomExport(
3636
val usedByKustomExportGeneric: Boolean = false
3737
)
3838

39+
@Retention(AnnotationRetention.BINARY)
3940
@Target(AnnotationTarget.FILE)
4041
public annotation class KustomExportGenerics(
4142
public val exportGenerics: Array<KustomGenerics> = []
4243
)
4344

45+
@Retention(AnnotationRetention.BINARY)
4446
@Target() // No target, only there for data container
45-
@Retention(AnnotationRetention.RUNTIME) // TODO: to be reduced!
4647
public annotation class KustomGenerics(
4748
public val kClass: KClass<*>,
4849
public val typeParameters: Array<KClass<*>>,

samples/src/commonMain/kotlin/sample/_class/static/Statics.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ package sample._class.static
2525

2626
import deezer.kustomexport.KustomExport
2727
import deezer.kustomexport.KustomExportGenerics
28-
//import sample.generics.GenericsImpl
2928

3029
fun createString() = "string from factory method"
3130

@@ -34,10 +33,31 @@ object StaticFactory {
3433
fun create(stuff: Long) = "string from factory object stuff=$stuff"
3534
}
3635

37-
/* See generic
36+
37+
38+
/**
39+
* NOT SUPPORTED: Currently KustomExport cannot handle generics functions.
40+
*
41+
* When an annotation like `KustomGenerics(StaticGenericFactory::class, arrayOf(Long::class))` is found,
42+
* it resolves the class type parameters with the given parameter (here [Long]), but the class doesn't need it.
43+
* The generic functions can actually be used with multiple types so if we want to support it, we should handle
44+
* multiple custom types for each method, generating as many functions as needed, on the wrappers.
45+
* Also be able to split generics from the typed class and from the typed methods.
46+
*
47+
* ```kotlin
48+
* class Foo<T : Any> {
49+
* fun <T, V> bar(t: T, v: V) { // T from here is not the T from the class
50+
* }
51+
* }
52+
* Foo<Int>().bar("a", "b") // Here "T" is a Int at the class level, and a String at the method level.
53+
* ```
54+
* So it can be tedious to provide a good solution for that (waiting for more adopters, not sure if we need
55+
* this level of tooling right now...)
56+
*/
57+
/*
3858
object StaticGenericFactory {
39-
fun <T> create(): GenericsImpl<T> {
40-
return GenericsImpl<T>()
41-
}
59+
fun <T> create(): GenericsImpl<T> {
60+
return GenericsImpl<T>()
61+
}
4262
}
4363
*/

samples/src/commonMain/kotlin/sample/generics/Generics.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,25 @@ class GenericsConsumer {
8484
// (You should not use generics on TypeAlias.)
8585
//@KustomExport
8686
//typealias TypeAliasLong = TypeAliasInterface<Long>
87-
// Unfortunately, typealias are not properly handled by KotlinJs rn
87+
// Unfortunately, typealias are not properly handled by KotlinJs rn
88+
89+
90+
/**
91+
* NOT SUPPORTED: Currently KustomExport cannot handle generics functions.
92+
*
93+
* When an annotation like `KustomGenerics(GenericsStuff::class, arrayOf(Long::class))` is found,
94+
* it resolves the class type parameters with the given parameter (here [Long]), but the class doesn't need it.
95+
* The generic functions can actually be used with multiple types so if we want to support it, we should handle
96+
* multiple custom types for each method, generating as many functions as needed, on the wrappers.
97+
* Also be able to split generics from the typed class and from the typed methods.
98+
*
99+
* ```kotlin
100+
* class Foo<T : Any> {
101+
* fun <T, V> bar(t: T, v: V) { // T from here is not the T from the class
102+
* }
103+
* }
104+
* Foo<Int>().bar("a", "b") // Here "T" is a Int at the class level, and a String at the method level.
105+
* ```
106+
* So it can be tedious to provide a good solution for that (waiting for more adopters, not sure if we need
107+
* this level of tooling right now...)
108+
*/

samples/src/commonMain/kotlin/sample/generics/Generics.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Disabling Generics support for now:
2-
// - more complex when dealing with @JsExport and @KustomExport mixed
3-
// - support is still not great enough, must be reworked
4-
51
import { runTest } from "../shared_ts/RunTest"
62
import { assert, assertEquals, assertQuiet } from "../shared_ts/Assert"
73
import { Nullable, sample } from '@kustom/Samples'

0 commit comments

Comments
 (0)