Skip to content

Commit

Permalink
Fix cross-module generation and fix for value classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cupertank committed Apr 22, 2024
1 parent 42f876b commit 5405ce1
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import io.kinference.primitives.types.DataType
*/
@Repeatable
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.SOURCE)
annotation class BindPrimitives(
val type1: Array<DataType> = emptyArray(),
val type2: Array<DataType> = emptyArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataType> = emptyArray()
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package io.kinference.primitives.annotations

@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class MakePublic()
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataType> = arrayOf(DataType.ALL)
)
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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!!
Expand Down

0 comments on commit 5405ce1

Please sign in to comment.