From 5405ce1af718684680e769477bcda786533f36d4 Mon Sep 17 00:00:00 2001 From: Ilia Vologin Date: Mon, 22 Apr 2024 16:56:00 +0200 Subject: [PATCH] Fix cross-module generation and fix for value classes --- .../io/kinference/primitives/annotations/BindPrimitives.kt | 1 - .../kinference/primitives/annotations/FilterPrimitives.kt | 1 - .../primitives/annotations/GenerateNameFromPrimitives.kt | 1 - .../kinference/primitives/annotations/GeneratePrimitives.kt | 1 - .../io/kinference/primitives/annotations/MakePublic.kt | 1 - .../kinference/primitives/annotations/SpecifyPrimitives.kt | 1 - .../kotlin/io/kinference/primitives/generator/Utils.kt | 6 ++++-- 7 files changed, 4 insertions(+), 8 deletions(-) diff --git a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/BindPrimitives.kt b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/BindPrimitives.kt index b92a321..0ba2484 100644 --- a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/BindPrimitives.kt +++ b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/BindPrimitives.kt @@ -18,7 +18,6 @@ import io.kinference.primitives.types.DataType */ @Repeatable @Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) annotation class BindPrimitives( val type1: Array = emptyArray(), val type2: Array = emptyArray(), diff --git a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/FilterPrimitives.kt b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/FilterPrimitives.kt index 0ef51bf..96b9b7f 100644 --- a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/FilterPrimitives.kt +++ b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/FilterPrimitives.kt @@ -12,7 +12,6 @@ import io.kinference.primitives.types.DataType * that PrimitiveType is Number */ @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS) -@Retention(AnnotationRetention.SOURCE) annotation class FilterPrimitives( val exclude: Array = emptyArray() ) diff --git a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GenerateNameFromPrimitives.kt b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GenerateNameFromPrimitives.kt index f52e042..74af59e 100644 --- a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GenerateNameFromPrimitives.kt +++ b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GenerateNameFromPrimitives.kt @@ -4,5 +4,4 @@ import io.kinference.primitives.types.DataType /** Specify that in this class or function `Primitive` substring in name should be replaced with currently generated [DataType] */ @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) annotation class GenerateNameFromPrimitives diff --git a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GeneratePrimitives.kt b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GeneratePrimitives.kt index b40706e..894c5d9 100644 --- a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GeneratePrimitives.kt +++ b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/GeneratePrimitives.kt @@ -4,5 +4,4 @@ import io.kinference.primitives.types.* /** Specify that any usage of [PrimitiveNumberType] or [PrimitiveArray] is subject for replacement in this file */ @Target(AnnotationTarget.FILE) -@Retention(AnnotationRetention.SOURCE) annotation class GeneratePrimitives(vararg val types: DataType) diff --git a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/MakePublic.kt b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/MakePublic.kt index ce679b5..a2aff01 100644 --- a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/MakePublic.kt +++ b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/MakePublic.kt @@ -1,5 +1,4 @@ package io.kinference.primitives.annotations @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS) -@Retention(AnnotationRetention.SOURCE) annotation class MakePublic() diff --git a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/SpecifyPrimitives.kt b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/SpecifyPrimitives.kt index cc02de3..9aa08e7 100644 --- a/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/SpecifyPrimitives.kt +++ b/primitives-annotations/src/commonMain/kotlin/io/kinference/primitives/annotations/SpecifyPrimitives.kt @@ -9,7 +9,6 @@ import io.kinference.primitives.types.DataType * that PrimitiveType is Double type number */ @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS) -@Retention(AnnotationRetention.SOURCE) annotation class SpecifyPrimitives( val include: Array = arrayOf(DataType.ALL) ) diff --git a/primitives-plugin/kotlin-plugin/src/jvmMain/kotlin/io/kinference/primitives/generator/Utils.kt b/primitives-plugin/kotlin-plugin/src/jvmMain/kotlin/io/kinference/primitives/generator/Utils.kt index 3cf51a3..e0a97a5 100644 --- a/primitives-plugin/kotlin-plugin/src/jvmMain/kotlin/io/kinference/primitives/generator/Utils.kt +++ b/primitives-plugin/kotlin-plugin/src/jvmMain/kotlin/io/kinference/primitives/generator/Utils.kt @@ -7,10 +7,12 @@ import io.kinference.primitives.types.DataType import io.kinference.primitives.utils.psi.* import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.isValueClass import kotlin.reflect.KProperty @@ -48,9 +50,9 @@ internal fun KtAnnotationEntry.isPluginAnnotation(context: BindingContext): Bool } internal fun DeclarationDescriptor.isNamedFunction() = findPsi() is KtNamedFunction -internal fun DeclarationDescriptor.isKtClassOrObject() = findPsi() is KtClassOrObject +internal fun DeclarationDescriptor.isKtClassOrObject() = findPsi() is KtClassOrObject || isValueClass() internal fun DeclarationDescriptor.isCompanion() = findPsi() is KtObjectDeclaration && containingDeclaration?.findPsi() is KtClass -internal fun DeclarationDescriptor.isConstructor() = findPsi() is KtConstructor<*> && containingDeclaration?.findPsi() is KtClass +internal fun DeclarationDescriptor.isConstructor() = this is ClassConstructorDescriptor || findPsi() is KtConstructor<*> && containingDeclaration?.findPsi() is KtClass internal fun KtNamedDeclaration.specialize(primitive: Primitive<*, *>, collector: MessageCollector): String { val name = name!!