com.lightningkite.khrysalis.replacements.GetReplacement.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-plugin-common Show documentation
Show all versions of kotlin-compiler-plugin-common Show documentation
Common translational tools between Typescript and Swift.
The newest version!
package com.lightningkite.khrysalis.replacements
import com.fasterxml.jackson.annotation.JsonIgnore
import com.lightningkite.khrysalis.util.fqNameWithTypeArgs
import com.lightningkite.khrysalis.util.fqNameWithoutTypeArgs
import com.lightningkite.khrysalis.util.satisfies
import com.lightningkite.khrysalis.util.simpleFqName
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.psiUtil.getTextWithLocation
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.supertypes
data class GetReplacement(
val id: String,
val receiver: String? = null,
val actualReceiver: String? = null,
override val debug: Boolean = false,
val reflectiveName: Template? = null,
val resultIsNullable: Boolean? = null,
val template: Template
) : ReplacementRule {
@get:JsonIgnore()
override val priority: Int
get() = (if (receiver != null) 2 else 0) + (if (actualReceiver != null) 4 else 0)
fun passes(decl: PropertyDescriptor, receiverType: KotlinType?): Boolean {
if (debug) {
println("Checking applicability for $id:")
if (actualReceiver != null) {
if (receiverType == null || !receiverType.satisfies(actualReceiver)) {
println("Not applicable: actualReceiver needs ${actualReceiver}, got ${receiverType?.fqNameWithTypeArgs}")
}
}
if (receiver != null && decl.extensionReceiverParameter?.type?.satisfies(receiver) == false) println("Not applicable: receiver requires $receiver, got ${decl.extensionReceiverParameter?.type?.fqNameWithoutTypeArgs}")
}
if (actualReceiver != null) {
if (receiverType == null || !receiverType.satisfies(actualReceiver)) return false
}
if (receiver != null && decl.extensionReceiverParameter?.type?.satisfies(receiver) == false) return false
return true
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy